feat(gui): add toolbar widget

feat(gui): add grid_select, toggle, panel, status_bar, image widgets
fix(bsp): fill in exterior cells
This commit is contained in:
asrael 2026-02-27 06:50:49 -06:00
parent 5a565844dd
commit 8d491612ab
63 changed files with 3150 additions and 1686 deletions

View file

@ -173,6 +173,22 @@ bool pxl8_gui_slider_int(pxl8_gui_state* state, pxl8_gfx* gfx, u32 id, i32 x, i3
return changed;
}
i32 pxl8_gui_toolbar(pxl8_gui_state* state, pxl8_gfx* gfx, u32 base_id,
i32 x, i32 y, i32 btn_w, i32 btn_h,
const char** labels, i32 count, i32 selected) {
i32 result = -1;
for (i32 i = 0; i < count; i++) {
i32 bx = x + i * (btn_w + 2);
bool clicked = pxl8_gui_button(state, gfx, base_id + (u32)i, bx, y, btn_w, btn_h, labels[i]);
if (clicked) result = i;
if (i == selected) {
u8 sel_color = pxl8_gui_color(gfx, PXL8_UI_FG0);
pxl8_2d_rect(gfx, bx, y + btn_h - 2, btn_w, 2, sel_color);
}
}
return result;
}
void pxl8_gui_window(pxl8_gfx* gfx, i32 x, i32 y, i32 w, i32 h, const char* title) {
if (!gfx || !title) return;
@ -206,3 +222,63 @@ void pxl8_gui_get_cursor_pos(const pxl8_gui_state* state, i32* x, i32* y) {
if (x) *x = state->cursor_x;
if (y) *y = state->cursor_y;
}
i32 pxl8_gui_grid_select(pxl8_gui_state* state, pxl8_gfx* gfx, u32 base_id,
i32 x, i32 y, i32 cell_w, i32 cell_h,
i32 cols, i32 rows, const u8* colors, i32 selected) {
i32 result = -1;
for (i32 r = 0; r < rows; r++) {
for (i32 c = 0; c < cols; c++) {
i32 cx = x + c * (cell_w + 1);
i32 cy = y + r * (cell_h + 1);
i32 idx = r * cols + c;
u32 id = base_id + (u32)idx;
bool over = is_cursor_over(state, cx, cy, cell_w, cell_h);
if (over) state->hot_id = id;
if (over && state->cursor_down && state->active_id == 0)
state->active_id = id;
bool clicked = (state->active_id == id) && state->cursor_clicked && over;
if (clicked) { result = idx; state->active_id = 0; }
pxl8_2d_rect_fill(gfx, cx, cy, cell_w, cell_h, colors[idx]);
if (idx == selected) {
u8 sel = pxl8_gui_color(gfx, PXL8_UI_FG0);
pxl8_2d_rect(gfx, cx - 1, cy - 1, cell_w + 2, cell_h + 2, sel);
} else if (over) {
u8 hov = pxl8_gui_color(gfx, PXL8_UI_BG3);
pxl8_2d_rect(gfx, cx, cy, cell_w, cell_h, hov);
}
}
}
return result;
}
void pxl8_gui_image(pxl8_gfx* gfx, u32 texture_id, i32 sx, i32 sy, i32 sw, i32 sh,
i32 dx, i32 dy, i32 dw, i32 dh) {
pxl8_2d_sprite(gfx, texture_id, dx, dy, dw, dh, false, false);
(void)sx; (void)sy; (void)sw; (void)sh;
}
void pxl8_gui_panel(pxl8_gfx* gfx, i32 x, i32 y, i32 w, i32 h) {
u8 bg = pxl8_gui_color(gfx, PXL8_UI_BG1);
u8 border = pxl8_gui_color(gfx, PXL8_UI_BG3);
pxl8_2d_rect_fill(gfx, x, y, w, h, bg);
pxl8_2d_rect(gfx, x, y, w, h, border);
}
void pxl8_gui_status_bar(pxl8_gfx* gfx, i32 y, i32 screen_w, i32 h, const char* text) {
u8 bg = pxl8_gui_color(gfx, PXL8_UI_BG1);
u8 fg = pxl8_gui_color(gfx, PXL8_UI_FG0);
pxl8_2d_rect_fill(gfx, 0, y, screen_w, h, bg);
pxl8_2d_text(gfx, text, 4, y + (h / 2) - 5, fg);
}
bool pxl8_gui_toggle(pxl8_gui_state* state, pxl8_gfx* gfx, u32 id,
i32 x, i32 y, i32 w, i32 h, const char* label, bool active) {
bool clicked = pxl8_gui_button(state, gfx, id, x, y, w, h, label);
if (active) {
u8 sel = pxl8_gui_color(gfx, PXL8_UI_FG0);
pxl8_2d_rect(gfx, x, y, w, 2, sel);
pxl8_2d_rect(gfx, x, y + h - 2, w, 2, sel);
}
return clicked ? !active : active;
}