add ui module

This commit is contained in:
asrael 2025-10-04 11:55:04 -05:00
parent 1744e689b5
commit 6008ebf5ed
12 changed files with 703 additions and 215 deletions

View file

@ -329,5 +329,37 @@ end
pxl8.gfx = gfx
pxl8.input = input
pxl8.ui = _pxl8_ui
function pxl8.bounds(x, y, w, h)
return ffi.new("pxl8_bounds", {x = x, y = y, w = w, h = h})
end
function pxl8.ui_window_begin(title, x, y, w, h, options)
local rect = ffi.new("pxl8_bounds", {x = x, y = y, w = w, h = h})
return C.pxl8_ui_window_begin(_pxl8_ui, title, rect, options or 0)
end
function pxl8.ui_window_end()
C.pxl8_ui_window_end(_pxl8_ui)
end
function pxl8.ui_button(label)
return C.pxl8_ui_button(_pxl8_ui, label)
end
function pxl8.ui_label(text)
C.pxl8_ui_label(_pxl8_ui, text)
end
function pxl8.ui_layout_row(item_count, widths, height)
local widths_array = widths
if type(widths) == "table" then
widths_array = ffi.new("int[?]", #widths, widths)
elseif type(widths) == "number" then
widths_array = ffi.new("int[1]", widths)
end
C.pxl8_ui_layout_row(_pxl8_ui, item_count, widths_array, height)
end
return pxl8