uuhh, text? and i guess 'optimized', although its like 4 bytes less for a function

This commit is contained in:
Jayden Khan 2026-05-21 18:59:46 -07:00
parent 5fff4af053
commit 56014fd8f6
2 changed files with 24 additions and 15 deletions

View File

@ -13,9 +13,13 @@ ui.theme = {
}
ui.events = {}
ui._wasDown = false
ui._focused = nil
function ui.emit(event)
ui.events[event] = true
ui.events[event] = true -- should change to a custom ID soon to prevent conflicts.
end
function ui.on(event)
@ -23,6 +27,7 @@ function ui.on(event)
end
function ui.flush()
ui._wasDown = love.mouse.isDown(1)
ui.events = {}
end
@ -38,26 +43,28 @@ function ui.button(x, y, w, h, text)
local mousex, mousey = love.mouse.getPosition()
local hovered = mousex > x and mousex < x + w and mousey > y and mousey < y + h -- calculaters if its touching the box
if hovered then
-- makes dimed panel then text ontop
love.graphics.setColor(ui.theme.hover)
love.graphics.rectangle("fill", x, y , w, h)
love.graphics.rectangle("fill", x, y, w, h)
love.graphics.setColor(ui.theme.border)
love.graphics.setLineWidth(ui.theme.borderwidth)
love.graphics.rectangle("line", x, y ,w, h)
love.graphics.setColor(ui.theme.text)
love.graphics.printf(text, x, y + h/2-7, w, "center")
love.graphics.rectangle("line", x, y, w, h)
ui.text(x, y, w, h, text)
else
-- makes a panel and then just adds text to it
ui.panel(x, y, w, h)
love.graphics.setColor(ui.theme.text)
love.graphics.printf(text, x, y + h/2-7, w, "center")
ui.text(x, y, w, h, text) -- just normal text
end
if hovered and love.mouse.isDown(1) then
ui.emit(text) -- uses button label as event name for now, change later to avoid same ID stuff
if hovered and love.mouse.isDown(1) and not ui._wasDown then
ui.emit(text)
end
return hovered -- returns hovered
end
function ui.text(x, y, w, h, text) -- expand on this, havent fully read the text documentation so i dont know if i should have more
ui.panel(x,y,w,h)
love.graphics.setColor(ui.theme.text)
love.graphics.printf(text, x, y + h/2-7, w, "center")
end
return ui

View File

@ -5,13 +5,15 @@ function love.load()
end
function love.update(dt)
ui.flush()
end
function love.draw()
ui.panel(50,50,50,50)
local test = ui.button(100,200,100,100,"hello world")
ui.button(100,200,100,100,"hello world")
if ui.on("hello world") then -- detect if the button is pressed.
ui.panel(250,250,250,250)
end
ui.flush() -- KEEP AT END
end