add ui element helper macros

main
Patrick Cleavelin 2024-03-17 21:35:10 -05:00
parent e806637b10
commit b436268ffa
1 changed files with 25 additions and 14 deletions
src

View File

@ -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 <stddef.h>
#include <stdint.h>
#include <stdbool.h>
@ -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