// A naive implementation of an immediate mode gui. #ifndef ED_UI_INCLUDED #define ED_UI_INCLUDED #include #include #include #include "string.h" typedef enum { UI_AXIS_HORIZONTAL, UI_AXIS_VERTICAL, } ui_axis; typedef enum { UI_SEMANTIC_SIZE_FIT_TEXT, UI_SEMANTIC_SIZE_CHILDREN_SUM, UI_SEMANTIC_SIZE_FILL, UI_SEMANTIC_SIZE_EXACT, UI_SEMANTIC_SIZE_PERCENT_OF_PARENT, } ui_semantic_size_t; typedef struct { ui_semantic_size_t type; union { uint32_t integer; }; } ui_semantic_size; typedef struct { ui_axis axis; ui_semantic_size semantic_size[2]; uint32_t computed_size[2]; uint32_t computed_pos[2]; } ui_size; // UI Element data persisted across frames typedef struct { string label; ui_size size; size_t last_instantiated_index; } ui_element_cache_data; typedef enum { UI_FLAG_CLICKABLE = 0b000000001, UI_FLAG_HOVERABLE = 0b000000010, UI_FLAG_SCROLLABLE = 0b000000100, UI_FLAG_DRAW_TEXT = 0b000001000, UI_FLAG_DRAW_BORDER = 0b000010000, UI_FLAG_DRAW_BACKGROUND = 0b000100000, UI_FLAG_ROUNDED_BORDER = 0b001000000, UI_FLAG_FLOATING = 0b010000000, UI_FLAG_CUSTOM_DRAW_FUNC = 0b100000000, } ui_flags; // Ephemeral frame only UI Element data typedef struct { size_t index; string key; string label; ui_size size; ui_flags flags; // optional types size_t first; size_t last; size_t next; size_t prev; size_t parent; } ui_element_frame_data; typedef struct { ed_ht *cached_elements; } ui_context; #endif #ifdef ED_UI_IMPLEMENTATION #endif