pico8-0hh1/ui.lua

46 lines
1.1 KiB
Lua

function make_button(options)
local state = 0 -- 0 = normal, 1 = hovered, 2 = pressed
return {
x = options.x,
y = options.y,
w = options.w,
h = options.h or 6,
data = options.data,
text = options.text,
on_click = options.on_click,
on_hover = options.on_hover,
on_draw = options.on_draw,
ogColor = options.color or 5,
color = options.color or 5,
draw=function(self, selected)
standard_font()
-- rect2(self.x, self.y, self.w, self.h, 8)
if self.on_draw then self.on_draw(self) end
print(self.text, self.x+1, self.y+1, self.color)
end,
update=function(self)
self.color = self.ogColor
if mouse_x >= self.x and mouse_x <= self.x + self.w and
mouse_y >= self.y and mouse_y <= self.y + self.h then
if stat(34)&1 == 0 and state == 2 and self.on_click then
self.on_click(self)
end
if stat(34)&1 == 1 then
state = 2
else
if self.on_hover then self.on_hover(self) end
state = 1
end
else
state = 0
end
end
}
end
function print_shadow(text, x, y, color)
print(text, x+1, y+1, 0)
print(text, x, y, color)
end