diff --git a/src/main.c b/src/main.c index 4508a7d..4c98781 100644 --- a/src/main.c +++ b/src/main.c @@ -21,6 +21,11 @@ #define ARENA_IMPLEMENTATION #include +#include "string.h" + +#define ED_UI_IMPLEMENTATION +#include "ui.h" + static Arena default_arena = {0}; static Arena temporary_arena = {0}; static Arena *context_arena = &default_arena; @@ -91,13 +96,7 @@ static struct { bool should_exit; } state; -#define _String(text) ((String) { .data = text, .len = sizeof(text) }) -typedef struct { - char *data; - size_t len; -} String; - -void queue_text(String text, float position[2]) { +void queue_text(string text, float position[2]) { float x = 0; for (size_t i=0; i < text.len; ++i) { if (text.data[i] >= 32 && text.data[i] <= 32+95) { diff --git a/src/string.h b/src/string.h new file mode 100644 index 0000000..6571cbd --- /dev/null +++ b/src/string.h @@ -0,0 +1,13 @@ +#ifndef ED_STRING_INCLUDED +#define ED_STRING_INCLUDED + +#include + +#define _String(text) ((string) { .data = text, .len = sizeof(text) }) +typedef struct { + char *data; + size_t len; +} string; + +#endif + diff --git a/src/ui.h b/src/ui.h new file mode 100644 index 0000000..fd01b17 --- /dev/null +++ b/src/ui.h @@ -0,0 +1,77 @@ +// 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; + +#endif + +#ifdef ED_UI_IMPLEMENTATION +#endif