refactor ui flags
This commit is contained in:
@@ -63,7 +63,7 @@ fn s8_t ui_tprint_loc(ui_code_loc_t loc) {
|
||||
return s8_printf(tcx.temp, "%s(%d)", loc.file, loc.line);
|
||||
}
|
||||
|
||||
fn ui_box_t *ui_build_box_from_id(ui_code_loc_t loc, ui_box_flag_t flags, ui_id_t id) {
|
||||
fn ui_box_t *ui_build_box_from_id(ui_code_loc_t loc, ui_box_flags_t flags, ui_id_t id) {
|
||||
ui_box_t *box = ui_find_box(id);
|
||||
if (box) {
|
||||
expect (box->last_touched_event_id != ui->event->id) {
|
||||
@@ -83,18 +83,17 @@ fn ui_box_t *ui_build_box_from_id(ui_code_loc_t loc, ui_box_flag_t flags, ui_id_
|
||||
return box;
|
||||
}
|
||||
|
||||
fn ui_id_t ui_gen_id(ui_id_strategy_t strat, ui_code_loc_t loc, s8_t string) {
|
||||
assert(strat != 0);
|
||||
fn ui_id_t ui_gen_id(ui_id_flags_t flags, ui_code_loc_t loc, s8_t string) {
|
||||
u64 result = 42523423493;
|
||||
if (is_flag_set(strat, ui_id_strategy_use_string)) {
|
||||
if (flags.use_string) {
|
||||
u64 string_hash = hash_data(string);
|
||||
result = hash_mix(string_hash, result);
|
||||
}
|
||||
if (is_flag_set(strat, ui_id_strategy_use_hierarchy)) {
|
||||
if (flags.use_hierarchy) {
|
||||
ui_id_t top_id = ui_find_top_id();
|
||||
result = hash_mix(top_id.value, result);
|
||||
}
|
||||
if (is_flag_set(strat, ui_id_strategy_use_code_loc)) {
|
||||
if (flags.use_code_loc) {
|
||||
u64 file_hash = hash_data(s8_from_char(loc.file));
|
||||
u64 line_hash = hash_data(s8_struct(loc.line));
|
||||
u64 cont_hash = hash_data(s8_struct(loc.counter));
|
||||
@@ -106,8 +105,8 @@ fn ui_id_t ui_gen_id(ui_id_strategy_t strat, ui_code_loc_t loc, s8_t string) {
|
||||
return id;
|
||||
}
|
||||
|
||||
fn ui_box_t *ui_build_box_from_string(ui_code_loc_t loc, ui_box_flag_t flags, s8_t string) {
|
||||
ui_id_t id = ui_gen_id(ui->id_strategy, loc, ui_get_hash_string(string));
|
||||
fn ui_box_t *ui_build_box_from_string(ui_code_loc_t loc, ui_box_flags_t flags, s8_t string) {
|
||||
ui_id_t id = ui_gen_id(ui->id_flags, loc, ui_get_hash_string(string));
|
||||
ui_box_t *box = ui_build_box_from_id(loc, flags, id);
|
||||
box->string = ui_get_display_string(string);
|
||||
return box;
|
||||
@@ -148,7 +147,7 @@ fn void ui_init(ma_arena_t *arena) {
|
||||
ui = ma_push_type(arena, ui_t);
|
||||
ui->box_arena = arena;
|
||||
ui->root = ma_push_type(arena, ui_box_t);
|
||||
ui->id_strategy = flag2(ui_id_strategy_use_string, ui_id_strategy_use_code_loc);
|
||||
ui->id_flags = (ui_id_flags_t){.use_string = true, .use_code_loc = true};
|
||||
|
||||
ui->box_array = ma_push_type(arena, ui_box_t);
|
||||
SLLS_PUSH(ui->free_first, ui->box_array);
|
||||
@@ -200,21 +199,21 @@ fn ui_box_t *ui_pop_parent(void) {
|
||||
}
|
||||
|
||||
fn ui_box_t *ui_spacer(ui_code_loc_t loc, ui_size_t x, ui_size_t y) {
|
||||
ui_box_t *box = ui_build_box_from_id(loc, flag2(ui_box_flag_draw_rect, ui_box_flag_draw_border), ui_null_id);
|
||||
ui_box_t *box = ui_build_box_from_id(loc, (ui_box_flags_t){.draw_rect = true, .draw_border = true}, ui_null_id);
|
||||
ui_set_semantic_size(box, x, y);
|
||||
return box;
|
||||
}
|
||||
|
||||
fn ui_signal_t ui_scroller_button(ui_code_loc_t loc, ui_size_t x, ui_size_t y) {
|
||||
ui_id_t id = ui_gen_id(flag2(ui_id_strategy_use_code_loc, ui_id_strategy_use_string), loc, s8_lit("spacer"));
|
||||
ui_box_t *box = ui_build_box_from_id(loc, flag2(ui_box_flag_draw_rect, ui_box_flag_draw_border), id);
|
||||
ui_id_t id = ui_gen_id(ui->id_flags, loc, s8_lit("spacer"));
|
||||
ui_box_t *box = ui_build_box_from_id(loc, (ui_box_flags_t){.draw_rect = true, .draw_border = true}, id);
|
||||
ui_set_semantic_size(box, x, y);
|
||||
ui_signal_t signal = ui_signal_from_box(box);
|
||||
return signal;
|
||||
}
|
||||
|
||||
fn ui_box_t *ui_push_container(ui_code_loc_t loc, ui_size_t x, ui_size_t y) {
|
||||
ui_box_t *box = ui_build_box_from_id(loc, flag2(ui_box_flag_draw_rect, ui_box_flag_draw_border), ui_null_id);
|
||||
ui_box_t *box = ui_build_box_from_id(loc, (ui_box_flags_t){.draw_rect = true}, ui_null_id);
|
||||
ui_push_parent(box);
|
||||
ui_set_semantic_size(box, x, y);
|
||||
box->grow_axis = ui_axis2_y;
|
||||
@@ -235,7 +234,7 @@ fn void ui_set_indented_string(ui_box_t *box, s8_t string) { box->string = s8_pr
|
||||
|
||||
fn ui_signal_t ui_push_exp(ui_code_loc_t loc, char *str, ...) {
|
||||
S8_FMT(tcx.temp, str, string);
|
||||
ui_box_t *box = ui_build_box_from_string(loc, flag1(ui_box_flag_draw_text), string);
|
||||
ui_box_t *box = ui_build_box_from_string(loc, (ui_box_flags_t){.draw_text = true}, string);
|
||||
ui_set_semantic_size(box, ui_percent(1), ui_text());
|
||||
|
||||
if (box->created_new) box->expanded = true;
|
||||
@@ -262,7 +261,7 @@ fn void ui_pop_exp(void) {
|
||||
|
||||
fn ui_box_t *ui_label(ui_code_loc_t loc, char *fmt, ...) {
|
||||
S8_FMT(tcx.temp, fmt, string);
|
||||
ui_box_t *box = ui_build_box_from_id(loc, flag1(ui_box_flag_draw_text), ui_null_id);
|
||||
ui_box_t *box = ui_build_box_from_id(loc, (ui_box_flags_t){.draw_text = true}, ui_null_id);
|
||||
ui_set_indented_string(box, string);
|
||||
ui_set_semantic_size(box, ui_text(), ui_text());
|
||||
return box;
|
||||
@@ -343,7 +342,7 @@ fn void ui_layout(void) {
|
||||
f32 *iter_pos = &parent->iter_pos[axis];
|
||||
|
||||
*pos = parent_pos + *iter_pos;
|
||||
if (is_flag_set(parent->flags, ui_box_flag_scroll)) {
|
||||
if (parent->flags.scroll) {
|
||||
*pos -= parent->view_offset.e[axis];
|
||||
}
|
||||
|
||||
@@ -381,13 +380,13 @@ fn void ui_draw(void) {
|
||||
}
|
||||
|
||||
rn_set_clip(clip_rect);
|
||||
if (is_flag_set(box->flags, ui_box_flag_draw_rect)) {
|
||||
if (box->flags.draw_rect) {
|
||||
rn_draw_rect(box->rect, rect_color);
|
||||
}
|
||||
if (is_flag_set(box->flags, ui_box_flag_draw_border)) {
|
||||
if (box->flags.draw_border) {
|
||||
rn_draw_rect_border(box->rect, accent2_color_global);
|
||||
}
|
||||
if (is_flag_set(box->flags, ui_box_flag_draw_text)) {
|
||||
if (box->flags.draw_text) {
|
||||
rn_draw_string(font, box->rect.min, text_color, box->string);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user