using cache in build_file, ui metaprogram and generating stacks
This commit is contained in:
168
src/ui/ui.c
168
src/ui/ui.c
@@ -41,8 +41,8 @@ fn ui_id_t ui_id_from_code_loc(ui_code_loc_t loc) {
|
||||
|
||||
fn u64 ui_hash_from_stack(void) {
|
||||
u64 result = 34294923;
|
||||
for (i32 i = 0; i < ui->id_stack.len; i += 1) {
|
||||
result = hash_mix(result, ui->id_stack.data[i].value);
|
||||
for (ui_id_node_t *it = ui->id_stack; it; it = it->next) {
|
||||
result = hash_mix(result, it->value.value);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
@@ -60,11 +60,10 @@ fn ui_id_t ui_idf(char *str, ...) {
|
||||
return ui_id(string);
|
||||
}
|
||||
|
||||
fn void ui_push_id(ui_id_t id) { STACK_PUSH(ui->id_stack, id); }
|
||||
fn void ui_pop_id(void) { STACK_POP(ui->id_stack); }
|
||||
fn void ui_push_id_string(s8_t string) { ui_push_id(ui_id(string)); }
|
||||
fn void ui_push_top(ui_box_t *new_top) { assert(new_top->parent == ui->top); ui->top = new_top; ui_push_id(new_top->id); }
|
||||
fn void ui_pop_top(void) { ui->top = ui->top->parent; ui_pop_id(); }
|
||||
#define ui_set_top(x) defer_block(ui_push_top(x), ui_pop_top())
|
||||
|
||||
fn ui_box_t *ui_alloc_box(void) {
|
||||
ui_box_t *box = NULL;
|
||||
@@ -93,18 +92,23 @@ fn void ui_push_box(ui_box_t *parent, ui_box_t *box) {
|
||||
parent->node_count += 1;
|
||||
}
|
||||
|
||||
fn r2f32_t ui_next_rect(ui_op_t op, r2f32_t *rect, v2f32_t required_size) {
|
||||
fn r2f32_t ui_next_rect(ui_lop_t op, r2f32_t *rect, v2f32_t required_size) {
|
||||
switch (op) {
|
||||
case ui_op_cut_top: return r2f32_cut_top_no_squash(rect, required_size.y); break;
|
||||
case ui_op_cut_bottom: return r2f32_cut_bottom_no_squash(rect, required_size.y); break;
|
||||
case ui_op_cut_left: return r2f32_cut_left_no_squash(rect, required_size.x); break;
|
||||
case ui_op_cut_right: return r2f32_cut_right_no_squash(rect, required_size.x); break;
|
||||
case ui_op_idle: break;
|
||||
case ui_lop_cut_top: return r2f32_cut_top_no_squash(rect, required_size.y); break;
|
||||
case ui_lop_cut_bottom: return r2f32_cut_bottom_no_squash(rect, required_size.y); break;
|
||||
case ui_lop_cut_left: return r2f32_cut_left_no_squash(rect, required_size.x); break;
|
||||
case ui_lop_cut_right: return r2f32_cut_right_no_squash(rect, required_size.x); break;
|
||||
case ui_lop_idle: break;
|
||||
default_is_invalid;
|
||||
}
|
||||
return (r2f32_t){0};
|
||||
}
|
||||
|
||||
fn void ui_offset_box(ui_box_t *box, v2f32_t offset) {
|
||||
box->full_rect = r2f32_sub_v2f32(box->full_rect, offset);
|
||||
box->rect = r2f32_sub_v2f32(box->rect, offset);
|
||||
}
|
||||
|
||||
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) {
|
||||
@@ -121,7 +125,8 @@ fn ui_box_t *ui_build_box_from_id(ui_code_loc_t loc, ui_box_flags_t flags, ui_id
|
||||
box->last_touched_event_id = ui->event->id;
|
||||
box->id = id;
|
||||
box->flags = flags;
|
||||
box->text_align = ui->pref_text_align;
|
||||
box->text_align = ui->text_align_stack->value;
|
||||
box->border_thickness = ui->border_thickness_stack->value;
|
||||
ui_push_box(ui->top, box);
|
||||
return box;
|
||||
}
|
||||
@@ -131,19 +136,30 @@ fn ui_box_t *ui_build_box_from_string(ui_code_loc_t loc, ui_box_flags_t flags, s
|
||||
ui_box_t *box = ui_build_box_from_id(loc, flags, id);
|
||||
box->string = ui_get_display_string(string);
|
||||
v2f32_t string_size = rn_measure_string(rn_state.main_font, box->string);
|
||||
string_size.x += ui_em(1);
|
||||
r2f32_t rect = ui_next_rect(ui->top->op, &ui->top->rect, string_size);
|
||||
if (ui->required_width_stack) string_size.x = ui->required_width_stack->value;
|
||||
if (ui->required_height_stack) string_size.y = ui->required_height_stack->value;
|
||||
if (ui->padding_stack) string_size = v2f32_add(string_size, ui->padding_stack->value);
|
||||
r2f32_t rect = ui_next_rect(ui->lop_stack->value, &ui->top->rect, string_size);
|
||||
ui_set_rect(box, rect);
|
||||
return box;
|
||||
}
|
||||
|
||||
#define ui_boxf(flags, ...) ui__boxf(UILOC, flags, __VA_ARGS__)
|
||||
#define ui_boxf(...) ui__boxf(UILOC, __VA_ARGS__)
|
||||
fn ui_box_t *ui__boxf(ui_code_loc_t loc, ui_box_flags_t flags, char *str, ...) {
|
||||
S8_FMT(tcx.temp, str, string);
|
||||
ui_box_t *box = ui_build_box_from_string(loc, flags, string);
|
||||
return box;
|
||||
}
|
||||
|
||||
#define ui_box0(...) ui_build_box_from_id(UILOC, __VA_ARGS__, ui_null_id)
|
||||
#define ui_box0f(...) ui__box0f(UILOC, __VA_ARGS__)
|
||||
fn ui_box_t *ui__box0f(ui_code_loc_t loc, ui_box_flags_t flags, char *str, ...) {
|
||||
S8_FMT(tcx.temp, str, string);
|
||||
ui_box_t *box = ui_build_box_from_id(loc, flags, ui_null_id);
|
||||
box->string = string;
|
||||
return box;
|
||||
}
|
||||
|
||||
fn ui_signal_t ui_signal_from_box(ui_box_t *box) {
|
||||
ui_signal_t result = {box};
|
||||
app_event_t *ev = ui->event;
|
||||
@@ -181,6 +197,14 @@ fn ui_signal_t ui__button(ui_code_loc_t loc, char *str, ...) {
|
||||
return signal;
|
||||
}
|
||||
|
||||
#define ui_label_button(...) ui__label_button(UILOC, __VA_ARGS__)
|
||||
fn ui_signal_t ui__label_button(ui_code_loc_t loc, char *str, ...) {
|
||||
S8_FMT(tcx.temp, str, string);
|
||||
ui_box_t *box = ui_build_box_from_string(loc, (ui_box_flags_t){ .draw_text = true }, string);
|
||||
ui_signal_t signal = ui_signal_from_box(box);
|
||||
return signal;
|
||||
}
|
||||
|
||||
#define ui_label(...) ui__label(UILOC, __VA_ARGS__)
|
||||
fn ui_box_t *ui__label(ui_code_loc_t loc, char *str, ...) {
|
||||
S8_FMT(tcx.temp, str, string);
|
||||
@@ -188,6 +212,7 @@ fn ui_box_t *ui__label(ui_code_loc_t loc, char *str, ...) {
|
||||
return box;
|
||||
}
|
||||
|
||||
#define ui_expander(...) defer_if (ui_begin_expander(__VA_ARGS__).clicked, ui_end_expander())
|
||||
#define ui_begin_expander(...) ui__begin_expander(UILOC, __VA_ARGS__)
|
||||
fn ui_signal_t ui__begin_expander(ui_code_loc_t loc, char *str, ...) {
|
||||
S8_FMT(tcx.temp, str, string);
|
||||
@@ -222,15 +247,26 @@ fn void ui_begin_build(ui_code_loc_t loc, app_event_t *ev, r2f32_t window_rect)
|
||||
}
|
||||
}
|
||||
|
||||
ui_push_lop(ui_lop_cut_top);
|
||||
ui_push_id(ui_idf("root"));
|
||||
ui_push_border_thickness(1.0f);
|
||||
ui_push_text_align(ui_text_align_left);
|
||||
|
||||
zero_struct(&ui->root);
|
||||
ui->root.full_rect = ui->root.rect = window_rect;
|
||||
ui->top = &ui->root;
|
||||
ui->root.loc = loc;
|
||||
|
||||
|
||||
}
|
||||
|
||||
fn void ui_end_build(void) {
|
||||
assert(ui->top == &ui->root);
|
||||
|
||||
SLLS_POP(ui->id_stack);
|
||||
SLLS_POP(ui->border_thickness_stack);
|
||||
SLLS_POP(ui->text_align_stack);
|
||||
|
||||
for (ui_box_t *box = ui->hash_first, *next = NULL; box; box = next) {
|
||||
next = box->hash_next;
|
||||
b32 touched_box_during_update = ui->event->id <= box->last_touched_event_id;
|
||||
@@ -266,7 +302,7 @@ fn void ui__draw_box(app_frame_t *frame, ui_box_t *box) {
|
||||
rn_draw_rect(rect, rect_color);
|
||||
}
|
||||
if (box->flags.draw_border) {
|
||||
rn_draw_rect_border(rect, accent2_color_global);
|
||||
rn_draw_rect_border(rect, accent2_color_global, box->border_thickness);
|
||||
}
|
||||
if (box->flags.draw_text) {
|
||||
v2f32_t string_size = rn_measure_string(rn_state.main_font, box->string);
|
||||
@@ -295,15 +331,22 @@ fn void ui__draw_box(app_frame_t *frame, ui_box_t *box) {
|
||||
}
|
||||
}
|
||||
|
||||
fn void ui_draw(app_frame_t *frame) {
|
||||
ui->clip_rect = window_rect_from_frame(frame);
|
||||
fn void ui_draw(void) {
|
||||
ui->clip_rect = window_rect_from_frame(ui->frame);
|
||||
rn_set_clip(ui->clip_rect);
|
||||
ui__draw_box(frame, &ui->root);
|
||||
ui__draw_box(ui->frame, &ui->root);
|
||||
}
|
||||
|
||||
fn void ui_demo_init(ma_arena_t *arena) {
|
||||
ui = ma_push_type(arena, ui_t);
|
||||
ui->box_arena = ma_push_arena(arena, mib(1));
|
||||
fn void ui_begin_frame(app_frame_t *frame) {
|
||||
ui->frame = frame;
|
||||
}
|
||||
|
||||
fn void ui_end_frame(void) {
|
||||
for (app_event_t *ev = ui->frame->first_event; ev; ev = ev->next) {
|
||||
if (ev_left_up(ev)) {
|
||||
ui->active = ui_null_id;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn void ui_serial_subtype(void *p, type_t *type, s8_t name) {
|
||||
@@ -312,7 +355,7 @@ fn void ui_serial_subtype(void *p, type_t *type, s8_t name) {
|
||||
switch(type->kind) {
|
||||
case type_kind_i8: {
|
||||
i8 *n = (i8 *)p;
|
||||
if (ui_button("%S: %d##slider%S", name, *n, name).dragging) {
|
||||
if (ui_label_button("%S: %d##slider%S", name, *n, name).dragging) {
|
||||
f32 delta = ui->event->mouse_delta.x;
|
||||
n[0] += (i8)delta;
|
||||
}
|
||||
@@ -320,7 +363,7 @@ fn void ui_serial_subtype(void *p, type_t *type, s8_t name) {
|
||||
} break;
|
||||
case type_kind_i16: {
|
||||
i16 *n = (i16 *)p;
|
||||
if (ui_button("%S: %d##slider%S", name, *n, name).dragging) {
|
||||
if (ui_label_button("%S: %d##slider%S", name, *n, name).dragging) {
|
||||
f32 delta = ui->event->mouse_delta.x;
|
||||
n[0] += (i16)delta;
|
||||
}
|
||||
@@ -328,7 +371,7 @@ fn void ui_serial_subtype(void *p, type_t *type, s8_t name) {
|
||||
} break;
|
||||
case type_kind_i32: {
|
||||
i32 *n = (i32 *)p;
|
||||
if (ui_button("%S: %d##slider%S", name, *n, name).dragging) {
|
||||
if (ui_label_button("%S: %d##slider%S", name, *n, name).dragging) {
|
||||
f32 delta = ui->event->mouse_delta.x;
|
||||
n[0] += (i32)delta;
|
||||
}
|
||||
@@ -336,7 +379,7 @@ fn void ui_serial_subtype(void *p, type_t *type, s8_t name) {
|
||||
} break;
|
||||
case type_kind_i64: {
|
||||
i64 *n = (i64 *)p;
|
||||
if (ui_button("%S: %lld##slider%S", name, (long long)*n, name).dragging) {
|
||||
if (ui_label_button("%S: %lld##slider%S", name, (long long)*n, name).dragging) {
|
||||
f32 delta = ui->event->mouse_delta.x;
|
||||
n[0] += (i64)delta;
|
||||
}
|
||||
@@ -344,7 +387,7 @@ fn void ui_serial_subtype(void *p, type_t *type, s8_t name) {
|
||||
} break;
|
||||
case type_kind_u8: {
|
||||
u8 *n = (u8 *)p;
|
||||
if (ui_button("%S: %u##slider%S", name, *n, name).dragging) {
|
||||
if (ui_label_button("%S: %u##slider%S", name, *n, name).dragging) {
|
||||
f32 delta = ui->event->mouse_delta.x;
|
||||
n[0] += (u8)delta;
|
||||
}
|
||||
@@ -352,7 +395,7 @@ fn void ui_serial_subtype(void *p, type_t *type, s8_t name) {
|
||||
} break;
|
||||
case type_kind_u16: {
|
||||
u16 *n = (u16 *)p;
|
||||
if (ui_button("%S: %u##slider%S", name, *n, name).dragging) {
|
||||
if (ui_label_button("%S: %u##slider%S", name, *n, name).dragging) {
|
||||
f32 delta = ui->event->mouse_delta.x;
|
||||
n[0] += (u16)delta;
|
||||
}
|
||||
@@ -360,7 +403,7 @@ fn void ui_serial_subtype(void *p, type_t *type, s8_t name) {
|
||||
} break;
|
||||
case type_kind_u32: {
|
||||
u32 *n = (u32 *)p;
|
||||
if (ui_button("%S: %u##slider%S", name, *n, name).dragging) {
|
||||
if (ui_label_button("%S: %u##slider%S", name, *n, name).dragging) {
|
||||
f32 delta = ui->event->mouse_delta.x;
|
||||
n[0] += (u32)delta;
|
||||
}
|
||||
@@ -368,7 +411,7 @@ fn void ui_serial_subtype(void *p, type_t *type, s8_t name) {
|
||||
} break;
|
||||
case type_kind_u64: {
|
||||
u64 *n = (u64 *)p;
|
||||
if (ui_button("%S: %llu##slider%S", name, (unsigned long long)*n, name).dragging) {
|
||||
if (ui_label_button("%S: %llu##slider%S", name, (unsigned long long)*n, name).dragging) {
|
||||
f32 delta = ui->event->mouse_delta.x;
|
||||
n[0] += (u64)delta;
|
||||
}
|
||||
@@ -376,35 +419,35 @@ fn void ui_serial_subtype(void *p, type_t *type, s8_t name) {
|
||||
} break;
|
||||
case type_kind_b8: {
|
||||
b8 *n = (b8 *)p;
|
||||
if (ui_button("%S: %s", name, *n ? "true" : "false").clicked) {
|
||||
if (ui_label_button("%S: %s", name, *n ? "true" : "false").clicked) {
|
||||
*n = !*n;
|
||||
}
|
||||
return;
|
||||
} break;
|
||||
case type_kind_b16: {
|
||||
b16 *n = (b16 *)p;
|
||||
if (ui_button("%S: %s", name, *n ? "true" : "false").clicked) {
|
||||
if (ui_label_button("%S: %s", name, *n ? "true" : "false").clicked) {
|
||||
*n = !*n;
|
||||
}
|
||||
return;
|
||||
} break;
|
||||
case type_kind_b32: {
|
||||
b32 *n = (b32 *)p;
|
||||
if (ui_button("%S: %s", name, *n ? "true" : "false").clicked) {
|
||||
if (ui_label_button("%S: %s", name, *n ? "true" : "false").clicked) {
|
||||
*n = !*n;
|
||||
}
|
||||
return;
|
||||
} break;
|
||||
case type_kind_b64: {
|
||||
b64 *n = (b64 *)p;
|
||||
if (ui_button("%S: %s", name, *n ? "true" : "false").clicked) {
|
||||
if (ui_label_button("%S: %s", name, *n ? "true" : "false").clicked) {
|
||||
*n = !*n;
|
||||
}
|
||||
return;
|
||||
} break;
|
||||
case type_kind_f32: {
|
||||
f32 *n = (f32 *)p;
|
||||
if (ui_button("%S: %f##slider%S", name, *n, name).dragging) {
|
||||
if (ui_label_button("%S: %f##slider%S", name, *n, name).dragging) {
|
||||
f32 delta = ui->event->mouse_delta.x;
|
||||
n[0] += delta;
|
||||
}
|
||||
@@ -412,7 +455,7 @@ fn void ui_serial_subtype(void *p, type_t *type, s8_t name) {
|
||||
} break;
|
||||
case type_kind_f64: {
|
||||
f64 *n = (f64 *)p;
|
||||
if (ui_button("%S: %f##slider%S", name, *n, name).dragging) {
|
||||
if (ui_label_button("%S: %f##slider%S", name, *n, name).dragging) {
|
||||
f32 delta = ui->event->mouse_delta.x;
|
||||
n[0] += delta;
|
||||
}
|
||||
@@ -420,7 +463,7 @@ fn void ui_serial_subtype(void *p, type_t *type, s8_t name) {
|
||||
} break;
|
||||
case type_kind_isize: {
|
||||
isize *n = (isize *)p;
|
||||
if (ui_button("%S: %lld##slider%S", name, *n, name).dragging) {
|
||||
if (ui_label_button("%S: %lld##slider%S", name, *n, name).dragging) {
|
||||
f32 delta = ui->event->mouse_delta.x;
|
||||
n[0] += (isize)delta;
|
||||
}
|
||||
@@ -428,7 +471,7 @@ fn void ui_serial_subtype(void *p, type_t *type, s8_t name) {
|
||||
} break;
|
||||
case type_kind_usize: {
|
||||
usize *n = (usize *)p;
|
||||
if (ui_button("%S: %llu##slider%S", name, *n, name).dragging) {
|
||||
if (ui_label_button("%S: %llu##slider%S", name, *n, name).dragging) {
|
||||
f32 delta = ui->event->mouse_delta.x;
|
||||
n[0] += (usize)delta;
|
||||
}
|
||||
@@ -436,7 +479,7 @@ fn void ui_serial_subtype(void *p, type_t *type, s8_t name) {
|
||||
} break;
|
||||
case type_kind_int: {
|
||||
int *n = (int *)p;
|
||||
if (ui_button("%S: %d##slider%S", name, *n, name).dragging) {
|
||||
if (ui_label_button("%S: %d##slider%S", name, *n, name).dragging) {
|
||||
f32 delta = ui->event->mouse_delta.x;
|
||||
n[0] += (int)delta;
|
||||
}
|
||||
@@ -444,7 +487,7 @@ fn void ui_serial_subtype(void *p, type_t *type, s8_t name) {
|
||||
} break;
|
||||
case type_kind_char: {
|
||||
char *n = (char *)p;
|
||||
if (ui_button("%S: %c##slider%S", name, *n, name).dragging) {
|
||||
if (ui_label_button("%S: %c##slider%S", name, *n, name).dragging) {
|
||||
f32 delta = ui->event->mouse_delta.x;
|
||||
n[0] += (char)delta;
|
||||
}
|
||||
@@ -460,7 +503,7 @@ fn void ui_serial_subtype(void *p, type_t *type, s8_t name) {
|
||||
if (type->kind == type_kind_enum) {
|
||||
i64 value = ti_enum_read_value(p, type);
|
||||
s8_t string_value = ti_enum_value_to_name(value, type);
|
||||
if (ui_button("%S: %S = %S", name, type->name, string_value).clicked) {
|
||||
if (ui_label_button("%S: %S = %S", name, type->name, string_value).clicked) {
|
||||
i64 new_value = ti_enum_next_value(p, value, type);
|
||||
ti_enum_write_value(p, new_value, type);
|
||||
}
|
||||
@@ -468,7 +511,7 @@ fn void ui_serial_subtype(void *p, type_t *type, s8_t name) {
|
||||
}
|
||||
|
||||
if (type->kind == type_kind_array) {
|
||||
defer_if (ui_begin_expander("%S:", name).clicked, ui_end_expander()) {
|
||||
ui_expander("%S:", name) {
|
||||
for (i32 i = 0; i < type->count; i += 1) {
|
||||
ma_temp_t scratch = ma_begin_scratch();
|
||||
s8_t index_name = s8_printf(scratch.arena, "[%d]", i);
|
||||
@@ -481,7 +524,7 @@ fn void ui_serial_subtype(void *p, type_t *type, s8_t name) {
|
||||
}
|
||||
|
||||
if (type->kind == type_kind_struct) {
|
||||
defer_if (ui_begin_expander("%S:", name).clicked, ui_end_expander()) {
|
||||
ui_expander("%S:", name) {
|
||||
for (i32 i = 0; i < type->count; i += 1) {
|
||||
type_member_t *tm = type->members + i;
|
||||
void *tmp = ti_extract_member(p, tm);
|
||||
@@ -498,33 +541,41 @@ fn void ui_serial_type(void *p, type_t *type) {
|
||||
ui_serial_subtype(p, type, type->name);
|
||||
}
|
||||
|
||||
|
||||
fn void ui_demo_init(ma_arena_t *arena) {
|
||||
ui = ma_push_type(arena, ui_t);
|
||||
ui->box_arena = ma_push_arena(arena, mib(1));
|
||||
}
|
||||
|
||||
gb app_event_t ui_test_event;
|
||||
fn void ui_demo_update(app_frame_t *frame) {
|
||||
ui_begin_frame(frame);
|
||||
for (app_event_t *ev = frame->first_event; ev; ev = ev->next) {
|
||||
ui_begin_build(UILOC, ev, window_rect_from_frame(frame));
|
||||
|
||||
ui->top->op = ui_op_idle;
|
||||
ui->top->rect = r2f32_shrinks(ui->top->rect, 200);
|
||||
|
||||
ui_box_t *scroller_box = ui_boxf((ui_box_flags_t){.draw_rect = true, .clip_rect = true}, "scroller");
|
||||
ui_box_t *scroller_box = ui_box0((ui_box_flags_t){.draw_rect = true, .clip_rect = true});
|
||||
ui_set_rect(scroller_box, r2f32_cut_right(&ui->top->rect, ui_em(0.5f)));
|
||||
|
||||
ui_box_t *item_box = ui_boxf((ui_box_flags_t){.draw_rect = true, .clip_rect = true}, "item_box");
|
||||
ui_box_t *item_box = ui_box0((ui_box_flags_t){.draw_rect = true, .clip_rect = true});
|
||||
ui_set_rect(item_box, r2f32_cut_left(&ui->top->rect, ui_max));
|
||||
|
||||
static f32 scroller_value;
|
||||
defer_block(ui_push_top(item_box), ui_pop_top()) {
|
||||
ui_set_text_align(ui_text_align_center)
|
||||
ui_set_top(item_box) {
|
||||
for (i32 i = 0; i < lengthof(tweak_table); i += 1) {
|
||||
mt_tweak_t *tweak = tweak_table + i;
|
||||
if (s8_starts_with(tweak->name, s8_lit("_"), false)) continue;
|
||||
|
||||
if (tweak->type->kind == type_kind_b32) {
|
||||
b32 *n = (b32 *)tweak->ptr;
|
||||
if (ui_button("%S: %s##slider%S", tweak->name, *n ? "true" : "false", tweak->name).clicked) {
|
||||
if (ui_label_button("%S: %s##slider%S", tweak->name, *n ? "true" : "false", tweak->name).clicked) {
|
||||
*n = !*n;
|
||||
}
|
||||
} else if (tweak->type->kind == type_kind_f32) {
|
||||
f32 *n = (f32 *)tweak->ptr;
|
||||
ui_signal_t signal = ui_button("%S: %f##slider%S", tweak->name, *n, tweak->name);
|
||||
ui_signal_t signal = ui_label_button("%S: %f##slider%S", tweak->name, *n, tweak->name);
|
||||
if (signal.dragging) {
|
||||
f32 size = tweak->max - tweak->min;
|
||||
v2f32_t string_size = rn_measure_string(rn_state.main_font, signal.box->string);
|
||||
@@ -534,17 +585,17 @@ fn void ui_demo_update(app_frame_t *frame) {
|
||||
} else_is_invalid;
|
||||
}
|
||||
ui_serial_type(&ui_test_event, type(app_event_t));
|
||||
defer_if (ui_begin_expander("app_event_t").clicked, ui_end_expander()) {
|
||||
ui_expander("app_event_t") {
|
||||
for (int i = 0; i < 2; i += 1) {
|
||||
ui_label("kind: app_event_kind_t##a%d", i);
|
||||
ui_label("ctrl: b8##ds%d", i);
|
||||
ui_label("shift: b8##f%d", i);
|
||||
defer_if (ui_begin_expander("pos: v3f32_t##gg%d", i).clicked, ui_end_expander()) {
|
||||
ui_expander("pos: v3f32_t##gg%d", i) {
|
||||
ui_label("x: f64 = value##hgt%d", i);
|
||||
ui_label("y: f64 = value##r%d", i);
|
||||
ui_label("z: f64 = value##yr%d", i);
|
||||
}
|
||||
defer_if (ui_begin_expander("mouse_pos: v2f32_t##i2%d", i).clicked, ui_end_expander()) {
|
||||
ui_expander("mouse_pos: v2f32_t##i2%d", i) {
|
||||
ui_label("x: f64 = value##i3%d", i);
|
||||
ui_label("y: f64 = value##i4%d", i);
|
||||
}
|
||||
@@ -578,10 +629,7 @@ fn void ui_demo_update(app_frame_t *frame) {
|
||||
}
|
||||
|
||||
for (ui_box_t *it = item_box->first; it; it = it->next) {
|
||||
it->full_rect.min.y -= scroller_value;
|
||||
it->full_rect.max.y -= scroller_value;
|
||||
it->rect.min.y -= scroller_value;
|
||||
it->rect.max.y -= scroller_value;
|
||||
ui_offset_box(it, v2f32(0, scroller_value));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -589,15 +637,9 @@ fn void ui_demo_update(app_frame_t *frame) {
|
||||
}
|
||||
|
||||
rn_begin();
|
||||
ui_draw(frame);
|
||||
ui_draw();
|
||||
rn_draw_stringf(rn_state.main_font, v2f32(0, frame->window_size.y - rn_state.main_font->size), black_color_global, "boxes: %d", ui->allocated_boxes);
|
||||
rn_end(frame->window_size, white_color_global);
|
||||
|
||||
|
||||
// End frame
|
||||
for (app_event_t *ev = frame->first_event; ev; ev = ev->next) {
|
||||
if (ev_left_up(ev)) {
|
||||
ui->active = ui_null_id;
|
||||
}
|
||||
}
|
||||
ui_end_frame();
|
||||
}
|
||||
Reference in New Issue
Block a user