new ui conception rect_cut+ryan memes

This commit is contained in:
Krzosa Karol
2025-01-17 10:59:35 +01:00
parent 3151a84ffe
commit 0ad84c9fc7
5 changed files with 378 additions and 32 deletions

View File

@@ -4,15 +4,12 @@ struct ui_code_loc_t {
int line;
int counter;
};
#define UILOC (ui_code_loc_t){.file = __FILE__, .line = __LINE__, .counter = __COUNTER__}
typedef struct ui_id_t ui_id_t;
struct ui_id_t {
u64 value;
};
typedef struct ui_box_flags_t ui_box_flags_t;
struct ui_box_flags_t {
b8 draw_rect: 1;
@@ -20,6 +17,14 @@ struct ui_box_flags_t {
b8 draw_text: 1;
};
typedef enum {
ui_op_cut_top,
ui_op_cut_bottom,
ui_op_cut_left,
ui_op_cut_right,
ui_op_idle,
} ui_op_t;
typedef struct ui_box_t ui_box_t;
struct ui_box_t {
ui_box_t *next;
@@ -27,21 +32,24 @@ struct ui_box_t {
ui_box_t *first;
ui_box_t *last;
ui_box_t *parent;
i32 node_count;
i32 node_count;
ui_code_loc_t loc;
s8_t string;
r2f32_t full_rect;
r2f32_t rect;
ui_code_loc_t loc;
s8_t string;
r2f32_t full_rect;
r2f32_t rect;
ui_op_t layout_op;
ui_box_flags_t flags;
b8 created_new;
b8 created_new;
ui_id_t id;
ui_id_t id;
ui_box_t *hash_next;
ui_box_t *hash_prev;
u64 last_touched_event_id;
};
u64 last_touched_event_id;
r2f32_t final_rect;
b32 expanded;
};
typedef struct ui_signal_t ui_signal_t;
struct ui_signal_t {
@@ -71,6 +79,7 @@ ui_t *ui;
gb_read_only ui_id_t ui_null_id;
gb_read_only ui_box_t ui_null_box;
gb_read_only ui_box_flags_t ui_null_flags;
fn b32 ui_is_null_id(ui_id_t id) { return id.value == 0; }
fn b32 ui_is_null_box(ui_box_t *box) { return box->id.value == 0; }
@@ -80,3 +89,12 @@ fn b32 ui_is_active_box(ui_box_t *box) { return !ui_is_null_box(box) && box->id.
#define ev_left(ev) ((ev)->mouse_button == app_mouse_button_left)
#define ev_left_up(ev) ((ev)->kind == app_event_kind_mouse_up && ev_left(ev))
#define ev_left_down(ev) ((ev)->kind == app_event_kind_mouse_down && ev_left(ev))
fn void ui_push_top(ui_box_t *new_top) { assert(new_top->parent == ui->top); ui->top = new_top; }
fn void ui_pop_top(void) { ui->top = ui->top->parent; }
fn void ui_set_rect(ui_box_t *box, r2f32_t rect) { box->rect = box->full_rect = rect; }
#define UILOC (ui_code_loc_t){.file = __FILE__, .line = __LINE__, .counter = __COUNTER__}
#define ui_em(x) ((x) * rn_state.main_font.size)
#define ui_max 200000000.f
#define ui_box_flags(...) (ui_box_flag_t){__VA_ARGS__}