From b436268ffa908898e7ba77dc86df8541d94b11dc Mon Sep 17 00:00:00 2001 From: Patrick Cleavelin Date: Sun, 17 Mar 2024 21:35:10 -0500 Subject: [PATCH] add ui element helper macros --- src/ui.h | 39 +++++++++++++++++++++++++-------------- 1 file changed, 25 insertions(+), 14 deletions(-) diff --git a/src/ui.h b/src/ui.h index bef6861..4b2879b 100644 --- a/src/ui.h +++ b/src/ui.h @@ -5,6 +5,20 @@ #define MAX_UI_ELEMENTS 2048 +#define _elm(index) (&cx->frame_elements.data[index]) + +#define _first(index) (_elm(index)->first) +#define _last(index) (_elm(index)->last) +#define _next(index) (_elm(index)->next) +#define _prev(index) (_elm(index)->prev) +#define _parent(index) (_elm(index)->parent) + +#define _first_ref(index) (_elm(_first(index))) +#define _last_ref(index) (_elm(_last(index))) +#define _next_ref(index) (_elm(_next(index))) +#define _prev_ref(index) (_elm(_prev(index))) +#define _parent_ref(index) (_elm(_parent(index))) + #include #include #include @@ -99,16 +113,6 @@ ui_context init_ui_context() { }; } -static ui_element_frame_data *_ui_element_last(ui_context *cx, size_t parent_index) { - size_t last_index = cx->frame_elements.data[parent_index].last; - - if (last_index) { - return &cx->frame_elements.data[last_index]; - } - - return NULL; -} - size_t ui_element(ui_context *cx, string label) { ui_element_frame_data frame_data = (ui_element_frame_data) { .index = cx->frame_elements.size, @@ -140,12 +144,19 @@ size_t ui_element(ui_context *cx, string label) { pushArray(ui_element_frame_data, &cx->frame_elements, frame_data); if (frame_data.prev) { - cx->frame_elements.data[frame_data.prev].next = frame_data.index; + _prev_ref(frame_data.index)->next = frame_data.index; } - if (cx->frame_elements.data[cx->current_parent].first == 0) { - cx->frame_elements.data[cx->current_parent].first = frame_data.index; + if (_elm(cx->current_parent)->first == 0) { + _elm(cx->current_parent)->first = frame_data.index; } - cx->frame_elements.data[cx->current_parent].last = frame_data.index; + _elm(cx->current_parent)->last = frame_data.index; +} + +void ui_compute_layout(ui_context *cx, uint32_t canvas_size[2], size_t element_index) { + ui_axis axis = UI_AXIS_HORIZONTAL; + + // FIXME: change me to use -1 for no reference to element + // TODO: actually compute layout } #endif