diff --git a/include/ui.h b/include/ui.h index 26883d0..7acbd55 100644 --- a/include/ui.h +++ b/include/ui.h @@ -31,6 +31,12 @@ struct ui_elem { ui_elem_type_t type; }; +typedef struct ui_elem_colours ui_elem_colours_t; +struct ui_elem_colours { + colour_t fill; + colour_t border; +}; + struct ui_ctx { u64 count; i64 hovered; @@ -49,7 +55,9 @@ void init_ui_ctx(ui_ctx_t *ctx); void reset_ui_ctx(ui_ctx_t *ctx); void handle_ui_events(const window_t *wnd, ui_ctx_t *ctx, const SDL_Event *event); -bool button(const window_t *wnd, ui_ctx_t *ctx, rect_t rect); -rect_t node(const window_t *wnd, ui_ctx_t *ctx, rect_t rect); +bool button(const window_t *wnd, ui_ctx_t *ctx, rect_t rect, + ui_elem_colours_t colours); +rect_t node(const window_t *wnd, ui_ctx_t *ctx, rect_t rect, + ui_elem_colours_t colours); #endif // !UI_H diff --git a/src/ui.c b/src/ui.c index 4061c17..0953838 100644 --- a/src/ui.c +++ b/src/ui.c @@ -3,25 +3,6 @@ #include "aliases/aliases.h" #include "window.h" -typedef struct ui_elem_colours ui_elem_colours_t; -struct ui_elem_colours { - colour_t fill; - colour_t border; -}; - -INTERNAL ui_elem_colours_t colours[COUNT_UI_ELEM] = { - [UI_ELEM_NODE] = - (ui_elem_colours_t){ - .fill = (colour_t){.abgr = 0xff2c84b7}, - .border = (colour_t){.abgr = 0xff315c89}, - }, - [UI_ELEM_BUTTON] = - (ui_elem_colours_t){ - .fill = (colour_t){.abgr = 0xff89a83c}, - .border = (colour_t){.abgr = 0xff768432}, - }, -}; - bool aabb(const ui_elem_t *elem, i32 x, i32 y) { return x > elem->rect.topleft.x && x <= elem->rect.topleft.x + elem->rect.w && y > elem->rect.topleft.y && y <= elem->rect.topleft.y + elem->rect.h; @@ -71,7 +52,8 @@ void handle_ui_events(const window_t *wnd, ui_ctx_t *ctx, } } -bool button(const window_t *wnd, ui_ctx_t *ctx, rect_t rect) { +bool button(const window_t *wnd, ui_ctx_t *ctx, rect_t rect, + ui_elem_colours_t colours) { if (ctx->count + 1 >= MAX_UI_ELEMENTS) { return false; } @@ -82,8 +64,8 @@ bool button(const window_t *wnd, ui_ctx_t *ctx, rect_t rect) { .type = UI_ELEM_BUTTON, }; - fill_rect(wnd, rect, colours[UI_ELEM_BUTTON].fill); - draw_rect(wnd, rect, colours[UI_ELEM_BUTTON].border); + fill_rect(wnd, rect, colours.fill); + draw_rect(wnd, rect, colours.border); if (wnd != ctx->wnd || (ctx->active >= 0 && ctx->active != elem.id)) { return false; @@ -107,7 +89,8 @@ bool button(const window_t *wnd, ui_ctx_t *ctx, rect_t rect) { return false; } -rect_t node(const window_t *wnd, ui_ctx_t *ctx, rect_t rect) { +rect_t node(const window_t *wnd, ui_ctx_t *ctx, rect_t rect, + ui_elem_colours_t colours) { if (ctx->count + 1 >= MAX_UI_ELEMENTS) { return (rect_t){0}; } @@ -118,8 +101,8 @@ rect_t node(const window_t *wnd, ui_ctx_t *ctx, rect_t rect) { .type = UI_ELEM_NODE, }; - fill_rect(wnd, rect, colours[UI_ELEM_NODE].fill); - draw_rect(wnd, rect, colours[UI_ELEM_NODE].border); + fill_rect(wnd, rect, colours.fill); + draw_rect(wnd, rect, colours.border); if (wnd != ctx->wnd || (ctx->active >= 0 && ctx->active != elem.id)) { return rect;