pico8-0hh1/ui.lua

46 lines
1.1 KiB
Lua
Raw Normal View History

2022-06-02 20:18:02 +02:00
function make_button(options)
2022-06-01 21:26:57 +02:00
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,
2022-06-02 20:18:02 +02:00
on_click = options.on_click,
on_hover = options.on_hover,
on_draw = options.on_draw,
2022-06-01 21:26:57 +02:00
ogColor = options.color or 5,
color = options.color or 5,
draw=function(self, selected)
2022-06-02 20:18:02 +02:00
standard_font()
2022-06-01 21:26:57 +02:00
-- rect2(self.x, self.y, self.w, self.h, 8)
2022-06-02 20:18:02 +02:00
if self.on_draw then self.on_draw(self) end
2022-06-01 21:26:57 +02:00
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
2022-06-02 20:18:02 +02:00
if stat(34)&1 == 0 and state == 2 and self.on_click then
self.on_click(self)
2022-06-01 21:26:57 +02:00
end
if stat(34)&1 == 1 then
state = 2
else
2022-06-02 20:18:02 +02:00
if self.on_hover then self.on_hover(self) end
2022-06-01 21:26:57 +02:00
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)
2022-06-01 21:26:57 +02:00
end