From 96a891db0af9c16aa95946016f1a3baf158f6478 Mon Sep 17 00:00:00 2001 From: Emil Kosz Date: Sat, 19 Jul 2025 09:42:54 +0200 Subject: [PATCH] Macro changes --- game/src/ui/widget_core.c | 16 ++++++---------- game/src/ui/widget_core.h | 12 +++++------- game/src/ui/widget_layout.c | 16 ++++++---------- game/src/ui/widget_render.c | 4 ++-- game/src/ui/widget_style.h | 4 ++-- 5 files changed, 21 insertions(+), 31 deletions(-) diff --git a/game/src/ui/widget_core.c b/game/src/ui/widget_core.c index fe6da52..0e93c76 100644 --- a/game/src/ui/widget_core.c +++ b/game/src/ui/widget_core.c @@ -324,9 +324,8 @@ Widget_tick (Widget *widget) widget->on_event[EVENT_TICK] (widget, NULL, widget->event_data[EVENT_TICK]); } - for (unsigned int i = 0; i < widget->children->len; ++i) + WFOREACH (widget, child) { - Widget *child = g_array_index (widget->children, Widget *, i); Widget_tick (child); } } @@ -346,8 +345,7 @@ Widget_render (Widget *widget, mat4 projection, int window_height) } /* If we're dirty, so are our children. */ - Widget *child; - WIDGET_FOREACH_CHILD (widget, i, child) + WFOREACH (widget, child) { child->layout_dirty = TRUE; } @@ -365,9 +363,8 @@ Widget_render (Widget *widget, mat4 projection, int window_height) { widget->do_render (widget, projection, window_height); } - - Widget *child; - WIDGET_FOREACH_CHILD (widget, i, child) + + WFOREACH (widget, child) { Widget_render (child, projection, window_height); } @@ -426,9 +423,8 @@ Widget_dump (Widget *widget, int depth) } } - for (unsigned int i = 0; i < widget->children->len; ++i) + WFOREACH (widget, child) { - Widget *child = g_array_index (widget->children, Widget *, i); - Widget_dump (child, depth + 1); + Widget_dump (child, depth + 1); } } diff --git a/game/src/ui/widget_core.h b/game/src/ui/widget_core.h index 3a751b5..14b4972 100644 --- a/game/src/ui/widget_core.h +++ b/game/src/ui/widget_core.h @@ -15,11 +15,9 @@ #include "../gl/mesh.h" #include "../gl/program.h" -#define WIDGET_FOREACH_CHILD(widget, i, child) \ - for (unsigned int i = 0; i < widget->children->len \ - && ((child = g_array_index (widget->children, Widget *, i)), 1); ++i) - -#define WIDGET_STYLE(widget, id) ((widget)->style = WSTYLE (id)) +#define WFOREACH(widget, child) \ + for (unsigned int _i = 0; _i < (widget)->children->len; ++_i) \ + for (Widget *child = g_array_index ((widget)->children, Widget *, _i); child; child = NULL) typedef enum WidgetKind { @@ -40,8 +38,8 @@ typedef enum WidgetKind typedef enum WidgetIcon { - ICON_NONE = -1, - ICON_CHECKBOX_UNCHECKED = 0, + ICON_NONE, + ICON_CHECKBOX_UNCHECKED, ICON_CHECKBOX_CHECKED, ICON_MINUS, ICON_PLUS, diff --git a/game/src/ui/widget_layout.c b/game/src/ui/widget_layout.c index 6da59ec..fb361ef 100644 --- a/game/src/ui/widget_layout.c +++ b/game/src/ui/widget_layout.c @@ -13,8 +13,7 @@ Widget_layout_container (Widget *self) float total_weights = 0.0; int total_fixed = 0; - Widget *child; - WIDGET_FOREACH_CHILD (self, i, child) + WFOREACH (self, child) { child->size[cross_axis] = container_cross; @@ -40,7 +39,7 @@ Widget_layout_container (Widget *self) int unit = total_weights > 0.0 ? (usable_main - total_fixed) / total_weights : 0; int offset = self->layout_padding; - WIDGET_FOREACH_CHILD (self, i, child) + WFOREACH (self, child) { int size; @@ -79,9 +78,8 @@ void Widget_layout_scrollable (Widget *self) { ivec2 content_size = { 0 }; - Widget *child; - - WIDGET_FOREACH_CHILD (self, i, child) + + WFOREACH (self, child) { child->position[0] = self->position[0] - self->scrollable.scroll_position[0]; child->position[1] = self->position[1] - self->scrollable.scroll_position[1]; @@ -239,8 +237,7 @@ Widget_layout_flowbox (Widget *self) int logical_main = self->position[main_axis]; int logical_cross = self->position[cross_axis]; - Widget *child; - WIDGET_FOREACH_CHILD (self, i, child) + WFOREACH (self, child) { /* It works like a percentage here; identically like in the ScrollableWidget. */ @@ -290,8 +287,7 @@ Widget_layout_window (Widget *self) { int top_height = self->window.titlebar_height + self->layout_padding * 2; - Widget *child; - WIDGET_FOREACH_CHILD (self, i, child) + WFOREACH (self, child) { child->position[0] = self->position[0] + self->layout_padding; child->position[1] = self->position[1] + top_height; diff --git a/game/src/ui/widget_render.c b/game/src/ui/widget_render.c index 97d37ae..7caecdf 100644 --- a/game/src/ui/widget_render.c +++ b/game/src/ui/widget_render.c @@ -82,8 +82,8 @@ Widget_render_base (Widget *self, mat4 projection, int window_height) program_set_int (RESPRG ("uiwidget"), "has_background_image", style->background_image != 0); texture_use (style->background_image, 0); /* If it doesn't have a texture, it'll be 0 anyway. */ - program_set_int (RESPRG ("uiwidget"), "has_icon", self->icon != -1); - program_set_float (RESPRG ("uiwidget"), "icon_index", self->icon); + program_set_int (RESPRG ("uiwidget"), "has_icon", self->icon != ICON_NONE); + program_set_float (RESPRG ("uiwidget"), "icon_index", self->icon - 1); texture_use (RESTEX ("icons"), 1); program_set_int (RESPRG ("uiwidget"), "has_resize_handle", self->kind == WIDGET_WINDOW); diff --git a/game/src/ui/widget_style.h b/game/src/ui/widget_style.h index 509ec37..0a71424 100644 --- a/game/src/ui/widget_style.h +++ b/game/src/ui/widget_style.h @@ -110,8 +110,8 @@ static const WidgetStyle widget_styles[NSTYLES] = { .background_color_hovered = { 0.3, 0.3, 0.3, 1.0 }, .background_color_clicked = { 0.3, 0.3, 0.3, 1.0 }, - /* .border_color = { 0.5, 0.5, 0.5, 1.0 }, */ - /* .border_width = 2, */ + .border_color = { 0.4, 0.4, 0.4, 1.0 }, + .border_width = 2, }, };