hot reload working
This commit is contained in:
78
src/ui/ui.c
78
src/ui/ui.c
@@ -36,7 +36,7 @@ fn ui_caret_t ui_carets(i32 x) {
|
||||
}
|
||||
|
||||
fn s8_t ui_tprint_loc(ui_code_loc_t loc) {
|
||||
return s8_printf(tcx.temp, "%s(%d)", loc.file, loc.line);
|
||||
return s8_printf(tcx->temp, "%s(%d)", loc.file, loc.line);
|
||||
}
|
||||
|
||||
fn s8_t ui_get_display_string(s8_t string) {
|
||||
@@ -59,6 +59,11 @@ fn ui_id_t ui_id_from_string(s8_t string) {
|
||||
return result;
|
||||
}
|
||||
|
||||
fn r2f32_t window_rect_from_frame(app_frame_t *frame) {
|
||||
r2f32_t window_rect = r2f32(0, 0, frame->window_size.x, frame->window_size.y);
|
||||
return window_rect;
|
||||
}
|
||||
|
||||
fn u64 ui_hash_code_loc(ui_code_loc_t loc) {
|
||||
u64 result = 4242843;
|
||||
u64 file_hash = hash_data(s8_from_char(loc.file));
|
||||
@@ -97,7 +102,7 @@ fn ui_id_t ui_id(s8_t string) {
|
||||
}
|
||||
|
||||
fn ui_id_t ui_idf(char *str, ...) {
|
||||
S8_FMT(tcx.temp, str, string);
|
||||
S8_FMT(tcx->temp, str, string);
|
||||
return ui_id(string);
|
||||
}
|
||||
|
||||
@@ -189,7 +194,7 @@ fn ui_box_t *ui_build_box_from_string(ui_code_loc_t loc, ui_box_flags_t flags, s
|
||||
ui_id_t id = ui_id(string);
|
||||
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);
|
||||
v2f32_t string_size = rn_measure_string(rn->main_font, box->string);
|
||||
ui_axis2_t axis = ui_axis_from_lop(ui_top_lop());
|
||||
if (ui->required_size_stack && (axis == ui_axis2_x || axis == ui_axis2_y)) {
|
||||
string_size.e[axis] = ui_top_required_size();
|
||||
@@ -207,7 +212,7 @@ fn ui_box_t *ui_build_box_from_string(ui_code_loc_t loc, ui_box_flags_t flags, s
|
||||
|
||||
#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);
|
||||
S8_FMT(tcx->temp, str, string);
|
||||
flags.dont_compute_rect = true;
|
||||
ui_box_t *box = ui_build_box_from_string(loc, flags, string);
|
||||
return box;
|
||||
@@ -216,7 +221,7 @@ fn ui_box_t *ui__boxf(ui_code_loc_t loc, ui_box_flags_t flags, char *str, ...) {
|
||||
#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);
|
||||
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;
|
||||
@@ -270,7 +275,7 @@ fn ui_signal_t ui_signal_from_box(ui_box_t *box) {
|
||||
}
|
||||
|
||||
fn v2f32_t ui_aligned_text_pos(f32 offset, ui_text_align_t text_align, r2f32_t rect, s8_t string) {
|
||||
v2f32_t string_size = rn_measure_string(rn_state.main_font, string);
|
||||
v2f32_t string_size = rn_measure_string(rn->main_font, string);
|
||||
v2f32_t rect_size = r2f32_get_size(rect);
|
||||
v2f32_t rect_string_diff = v2f32_sub(rect_size, string_size);
|
||||
v2f32_t center_pos = v2f32_divs(rect_string_diff, 2);
|
||||
@@ -309,16 +314,18 @@ fn ui_draw_compute_t ui_draw_compute(ui_box_t *box) {
|
||||
f32 active_t = f32_ease_out_n(box->active_t, 50.f);
|
||||
active_t = f32_clamp01(active_t);
|
||||
co.background_color = v4f32_lerp(co.background_color, box->bg_active_color, 1.0);
|
||||
co.text_color = v4f32_lerp(co.text_color, box->text_active_color, active_t);
|
||||
// co.text_color = v4f32_lerp(co.text_color, box->text_active_color, active_t);
|
||||
box->flags.draw_rect = true;
|
||||
} else if (ui_is_hot_box(box)) {
|
||||
f32 hot_t = f32_ease_out_n(box->hot_t, 3.f);
|
||||
f32 hot_t = f32_ease_out_n(box->hot_t, 50.f);
|
||||
hot_t = f32_clamp01(hot_t);
|
||||
co.background_color = v4f32_lerp(co.background_color, box->bg_hot_color, hot_t);
|
||||
co.text_color = v4f32_lerp(co.background_color, box->text_hot_color, hot_t);
|
||||
} else if (ui_is_focused_box(box)) {
|
||||
co.background_color = ui_color_table[ui_color_focused_rect_color];
|
||||
// co.text_color = v4f32_lerp(co.background_color, box->text_hot_color, hot_t);
|
||||
box->flags.draw_rect = true;
|
||||
} else if (ui_is_focused_box(box)) {
|
||||
co.background_color = ui_color_table[ui_color_focused_rect];
|
||||
// co.text_color = v4f32_hsla_to_rgba((v4f32_t){0.1f, 0.6f, 0.7f, 1.0f});
|
||||
box->flags.draw_rect = true;
|
||||
}
|
||||
|
||||
return co;
|
||||
@@ -332,15 +339,15 @@ fn void ui_text_input_draw(ui_box_t *box) {
|
||||
ui_text_input_t *ti = box->text_input;
|
||||
s8_t string = s8(ti->str, ti->len);
|
||||
v2f32_t pos = ui_aligned_text_pos(box->string_pos_offset, box->text_align, co.rect, string);
|
||||
rn_draw_string(rn_state.main_font, pos, co.text_color, string);
|
||||
rn_draw_string(rn->main_font, pos, co.text_color, string);
|
||||
|
||||
ti->caret = ui_caret_clamp(ti->caret, 0, (i32)ti->len);
|
||||
{
|
||||
s8_t string_min = s8(ti->str, ti->caret.range.min);
|
||||
s8_t string_max = s8(ti->str, ti->caret.range.max);
|
||||
|
||||
v2f32_t size_min = rn_measure_string(rn_state.main_font, string_min);
|
||||
v2f32_t size_max = rn_measure_string(rn_state.main_font, string_max);
|
||||
v2f32_t size_min = rn_measure_string(rn->main_font, string_min);
|
||||
v2f32_t size_max = rn_measure_string(rn->main_font, string_max);
|
||||
r2f32_t selection_rect = r2f32(co.rect.min.x + size_min.x, co.rect.min.y, co.rect.min.x + size_max.x, co.rect.min.y + ui_em(1));
|
||||
rn_draw_rect(selection_rect, v4f32(1,1,1,0.5f));
|
||||
|
||||
@@ -363,7 +370,7 @@ fn void ui_default_draw_box(ui_box_t *box) {
|
||||
}
|
||||
if (box->flags.draw_text) {
|
||||
v2f32_t text_pos = ui_aligned_text_pos(box->string_pos_offset, box->text_align, co.rect, box->string);
|
||||
rn_draw_string(rn_state.main_font, text_pos, co.text_color, box->string);
|
||||
rn_draw_string(rn->main_font, text_pos, co.text_color, box->string);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -452,7 +459,7 @@ fn ui_signal_t ui_text_input(ui_code_loc_t loc, ui_text_input_t *ti) {
|
||||
}
|
||||
}
|
||||
}
|
||||
v2f32_t size = rn_measure_string(rn_state.main_font, s8_lit("_"));
|
||||
v2f32_t size = rn_measure_string(rn->main_font, s8_lit("_"));
|
||||
v2f32_t pos = v2f32_sub(ev->mouse_pos, box->final_rect.min);
|
||||
i32 p = (i32)f32_round(pos.x / size.x);
|
||||
if (ev->kind == app_event_kind_mouse_down && ev->mouse_button == app_mouse_button_left) {
|
||||
@@ -468,7 +475,7 @@ fn ui_signal_t ui_text_input(ui_code_loc_t loc, ui_text_input_t *ti) {
|
||||
|
||||
#define ui_button(...) ui__button(UILOC, __VA_ARGS__)
|
||||
fn ui_signal_t ui__button(ui_code_loc_t loc, char *str, ...) {
|
||||
S8_FMT(tcx.temp, str, string);
|
||||
S8_FMT(tcx->temp, str, string);
|
||||
ui_box_t *box = ui_build_box_from_string(loc, (ui_box_flags_t){ .draw_border = true, .draw_rect = true, .draw_text = true, .keyboard_nav = true }, string);
|
||||
ui_signal_t signal = ui_signal_from_box(box);
|
||||
return signal;
|
||||
@@ -476,7 +483,7 @@ fn ui_signal_t ui__button(ui_code_loc_t loc, char *str, ...) {
|
||||
|
||||
#define ui_radio_button(...) ui__radio_button(UILOC, __VA_ARGS__)
|
||||
fn ui_signal_t ui__radio_button(ui_code_loc_t loc, i32 *value, i32 value_clicked, char *str, ...) {
|
||||
S8_FMT(tcx.temp, str, string);
|
||||
S8_FMT(tcx->temp, str, string);
|
||||
ui_box_t *box = ui_build_box_from_string(loc, (ui_box_flags_t){ .draw_border = true, .draw_rect = true, .draw_text = true, .keyboard_nav = true }, string);
|
||||
ui_signal_t signal = ui_signal_from_box(box);
|
||||
if (signal.clicked) *value = value_clicked;
|
||||
@@ -487,7 +494,7 @@ fn ui_signal_t ui__radio_button(ui_code_loc_t loc, i32 *value, i32 value_clicked
|
||||
|
||||
#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);
|
||||
S8_FMT(tcx->temp, str, string);
|
||||
ui_box_t *box = ui_build_box_from_string(loc, (ui_box_flags_t){ .draw_text = true, .keyboard_nav = true }, string);
|
||||
ui_signal_t signal = ui_signal_from_box(box);
|
||||
return signal;
|
||||
@@ -495,7 +502,7 @@ fn ui_signal_t ui__label_button(ui_code_loc_t loc, char *str, ...) {
|
||||
|
||||
#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);
|
||||
S8_FMT(tcx->temp, str, string);
|
||||
ui_box_t *box = ui_build_box_from_string(loc, (ui_box_flags_t){ .draw_text = true }, string);
|
||||
return box;
|
||||
}
|
||||
@@ -503,14 +510,14 @@ fn ui_box_t *ui__label(ui_code_loc_t loc, char *str, ...) {
|
||||
#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);
|
||||
S8_FMT(tcx->temp, str, string);
|
||||
ui_box_t *box = ui_build_box_from_string(loc, (ui_box_flags_t){ .draw_text = true, .keyboard_nav = true }, string);
|
||||
if (box->created_new) box->expanded = true;
|
||||
ui_signal_t signal = ui_signal_from_box(box);
|
||||
if (signal.clicked) box->expanded = !box->expanded;
|
||||
signal.clicked = box->expanded;
|
||||
if ( box->expanded) box->string = s8_printf(tcx.temp, "* %S", box->string);
|
||||
if (!box->expanded) box->string = s8_printf(tcx.temp, "> %S", box->string);
|
||||
if ( box->expanded) box->string = s8_printf(tcx->temp, "* %S", box->string);
|
||||
if (!box->expanded) box->string = s8_printf(tcx->temp, "> %S", box->string);
|
||||
if (box->expanded) {
|
||||
ui_push_string_pos_offset(ui_top_string_pos_offset() + ui_em(0.5f));
|
||||
ui_push_id(box->id);
|
||||
@@ -663,7 +670,8 @@ fn void ui_draw(void) {
|
||||
ui__draw_box(ui->frame, &ui->root);
|
||||
}
|
||||
|
||||
fn void ui_begin_frame(app_frame_t *frame) {
|
||||
fn void ui_begin_frame(ui_t *ui_context, app_frame_t *frame) {
|
||||
ui = ui_context;
|
||||
ui->frame = frame;
|
||||
}
|
||||
|
||||
@@ -886,24 +894,24 @@ fn void ui_serial_subtype(void *p, type_t *type, s8_t name) {
|
||||
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);
|
||||
tcx->data[1] = ma_push_type(arena, ui_t);
|
||||
ui = tcx->data[1];
|
||||
ui->box_arena = ma_push_arena(arena, mib(1));
|
||||
ui_init_colors();
|
||||
}
|
||||
|
||||
gb i32 ui_g_panel = 1;
|
||||
gb app_event_t ui_test_event;
|
||||
fn void ui_demo_update(app_frame_t *frame, mt_tweak_t *tweak_table, i32 tweak_count) {
|
||||
ui_begin_frame(frame);
|
||||
ui_begin_frame(tcx->data[1], frame);
|
||||
rn_begin_frame(tcx->data[0], frame);
|
||||
for (app_event_t *ev = frame->first_event; ev; ev = ev->next) {
|
||||
ui_begin_build(UILOC, ev, window_rect_from_frame(frame));
|
||||
|
||||
ui_box_t *top_box = ui_box0((ui_box_flags_t){.draw_rect = true, .clip_rect = true});
|
||||
ui_set_rect(top_box, r2f32_cut_top(&ui->top->rect, ui_em(1.5f)), ui_lop_cut_top);
|
||||
|
||||
ui_set_padding(ui_em(3))
|
||||
ui_set_text_align(ui_text_align_center)
|
||||
ui_set_lop(ui_lop_cut_left)
|
||||
@@ -950,20 +958,20 @@ fn void ui_demo_update(app_frame_t *frame, mt_tweak_t *tweak_table, i32 tweak_co
|
||||
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);
|
||||
v2f32_t string_size = rn_measure_string(rn->main_font, signal.box->string);
|
||||
f32 delta = (signal.drag.x / string_size.x) * size;
|
||||
*n = CLAMP(*n + delta, tweak->min, tweak->max);
|
||||
}
|
||||
} else_is_invalid;
|
||||
}
|
||||
ui_label("allocated boxes: %d", ui->allocated_boxes);
|
||||
ui_serial_type(&ui_test_event, type(app_event_t));
|
||||
// ui_serial_type(&ui_test_event, type(app_event_t));
|
||||
}
|
||||
|
||||
locl f32 scroller_value;
|
||||
defer_block(ui_push_top(scroller_box), ui_pop_top()) {
|
||||
f32 item_count = (f32)item_box->node_count;
|
||||
f32 all_items_size = item_count * rn_state.main_font->size;
|
||||
f32 all_items_size = item_count * rn->main_font->size;
|
||||
f32 item_box_size = r2f32_get_size(ui->top->full_rect).y;
|
||||
f32 scroller_box_size = r2f32_get_size(scroller_box->full_rect).y;
|
||||
f32 scroller_size = CLAMP(item_box_size / (all_items_size + frame->window_size.y), 0, 1.0f);
|
||||
@@ -974,7 +982,9 @@ fn void ui_demo_update(app_frame_t *frame, mt_tweak_t *tweak_table, i32 tweak_co
|
||||
|
||||
r2f32_cut_top(&ui->top->rect, scroller_percent * scroller_box_size);
|
||||
ui_box_t *box = ui_build_box_from_id(UILOC, (ui_box_flags_t){.draw_rect = true}, ui_idf("slider"));
|
||||
box->background_color = v4f32(1,0,1,1);
|
||||
box->background_color = ui_color_table[ui_color_scroller];
|
||||
box->bg_hot_color = ui_color_table[ui_color_scroller_hot];
|
||||
box->bg_active_color = ui_color_table[ui_color_scroller_active];
|
||||
ui_set_rect(box, r2f32_cut_top(&ui->top->rect, scroller_size * scroller_box_size), ui_lop_cut_top);
|
||||
ui_signal_t signal = ui_signal_from_box(box);
|
||||
if (signal.dragging) {
|
||||
@@ -997,7 +1007,7 @@ fn void ui_demo_update(app_frame_t *frame, mt_tweak_t *tweak_table, i32 tweak_co
|
||||
ui_end_build();
|
||||
}
|
||||
|
||||
rn_begin(frame, white_color);
|
||||
rn_begin(white_color);
|
||||
ui_draw();
|
||||
rn_end();
|
||||
|
||||
|
||||
@@ -2,16 +2,19 @@
|
||||
|
||||
type_t type__ui_color_t = { type_kind_enum, s8_const_lit("ui_color_t"), sizeof(ui_color_t),
|
||||
.members = (type_member_t[]){
|
||||
{.name = s8_const_lit("ui_color_rect_color"), .value = ui_color_rect_color},
|
||||
{.name = s8_const_lit("ui_color_rect_hot_color"), .value = ui_color_rect_hot_color},
|
||||
{.name = s8_const_lit("ui_color_rect_active_color"), .value = ui_color_rect_active_color},
|
||||
{.name = s8_const_lit("ui_color_border_color"), .value = ui_color_border_color},
|
||||
{.name = s8_const_lit("ui_color_text_color"), .value = ui_color_text_color},
|
||||
{.name = s8_const_lit("ui_color_text_hot_color"), .value = ui_color_text_hot_color},
|
||||
{.name = s8_const_lit("ui_color_text_active_color"), .value = ui_color_text_active_color},
|
||||
{.name = s8_const_lit("ui_color_focused_rect_color"), .value = ui_color_focused_rect_color},
|
||||
{.name = s8_const_lit("ui_color_rect"), .value = ui_color_rect},
|
||||
{.name = s8_const_lit("ui_color_rect_hot"), .value = ui_color_rect_hot},
|
||||
{.name = s8_const_lit("ui_color_rect_active"), .value = ui_color_rect_active},
|
||||
{.name = s8_const_lit("ui_color_border"), .value = ui_color_border},
|
||||
{.name = s8_const_lit("ui_color_text"), .value = ui_color_text},
|
||||
{.name = s8_const_lit("ui_color_text_hot"), .value = ui_color_text_hot},
|
||||
{.name = s8_const_lit("ui_color_text_active"), .value = ui_color_text_active},
|
||||
{.name = s8_const_lit("ui_color_focused_rect"), .value = ui_color_focused_rect},
|
||||
{.name = s8_const_lit("ui_color_scroller"), .value = ui_color_scroller},
|
||||
{.name = s8_const_lit("ui_color_scroller_hot"), .value = ui_color_scroller_hot},
|
||||
{.name = s8_const_lit("ui_color_scroller_active"), .value = ui_color_scroller_active},
|
||||
},
|
||||
.count = 8,
|
||||
.count = 11,
|
||||
};
|
||||
gb v4f32_t ui_color_table[] = {
|
||||
{0},
|
||||
@@ -22,71 +25,77 @@ gb v4f32_t ui_color_table[] = {
|
||||
{0},
|
||||
{0},
|
||||
{0},
|
||||
{0},
|
||||
{0},
|
||||
{0},
|
||||
};
|
||||
|
||||
fn void ui_init_colors(void) {
|
||||
ui_color_table[ui_color_rect_color] = v4f32_hsla_to_rgba((v4f32_t){0.0f, 0.2f, 0.95f, 1.0f});
|
||||
ui_color_table[ui_color_rect_hot_color] = v4f32_hsla_to_rgba((v4f32_t){0.0f, 0.5f, 0.95f, 1.0f});
|
||||
ui_color_table[ui_color_rect_active_color] = v4f32_hsla_to_rgba((v4f32_t){0.1f, 0.5f, 0.95f, 1.0f});
|
||||
ui_color_table[ui_color_border_color] = v4f32_hsla_to_rgba((v4f32_t){0.0f, 0.2f, 0.70f, 1.0f});
|
||||
ui_color_table[ui_color_text_color] = v4f32_hsla_to_rgba((v4f32_t){0.0f, 0.2f, 0.70f, 1.0f});
|
||||
ui_color_table[ui_color_text_hot_color] = v4f32_hsla_to_rgba((v4f32_t){0.1f, 0.4f, 0.70f, 1.0f});
|
||||
ui_color_table[ui_color_text_active_color] = v4f32_hsla_to_rgba((v4f32_t){0.1f, 0.5f, 0.70f, 1.0f});
|
||||
ui_color_table[ui_color_focused_rect_color] = v4f32_hsla_to_rgba((v4f32_t){0.1f, 0.6f, 0.95f, 1.0f});
|
||||
ui_color_table[ui_color_rect] = v4f32_hsla_to_rgba((v4f32_t){0.0f, 0.2f, 0.95f, 1.0f});
|
||||
ui_color_table[ui_color_rect_hot] = v4f32_hsla_to_rgba((v4f32_t){0.0f, 0.5f, 0.95f, 1.0f});
|
||||
ui_color_table[ui_color_rect_active] = v4f32_hsla_to_rgba((v4f32_t){0.1f, 0.5f, 0.95f, 1.0f});
|
||||
ui_color_table[ui_color_border] = v4f32_hsla_to_rgba((v4f32_t){0.0f, 0.2f, 0.70f, 1.0f});
|
||||
ui_color_table[ui_color_text] = v4f32_hsla_to_rgba((v4f32_t){0.0f, 0.2f, 0.70f, 1.0f});
|
||||
ui_color_table[ui_color_text_hot] = v4f32_hsla_to_rgba((v4f32_t){0.1f, 0.4f, 0.70f, 1.0f});
|
||||
ui_color_table[ui_color_text_active] = v4f32_hsla_to_rgba((v4f32_t){0.1f, 0.5f, 0.70f, 1.0f});
|
||||
ui_color_table[ui_color_focused_rect] = v4f32_hsla_to_rgba((v4f32_t){0.1f, 0.6f, 0.95f, 1.0f});
|
||||
ui_color_table[ui_color_scroller] = ui_color_table[ui_color_text];
|
||||
ui_color_table[ui_color_scroller_hot] = v4f32_hsla_to_rgba((v4f32_t){0.1f, 0.2f, 0.7f, 1.0f});
|
||||
ui_color_table[ui_color_scroller_active] = v4f32_hsla_to_rgba((v4f32_t){0.1f, 0.2f, 0.5f, 1.0f});
|
||||
}
|
||||
fn void ui_push_id(ui_id_t v) { ui_id_node_t *n = ma_push_type(tcx.temp, ui_id_node_t); n->value = v; SLLS_PUSH(ui->id_stack, n); }
|
||||
fn void ui_push_id(ui_id_t v) { ui_id_node_t *n = ma_push_type(tcx->temp, ui_id_node_t); n->value = v; SLLS_PUSH(ui->id_stack, n); }
|
||||
fn void ui_pop_id(void) { SLLS_POP(ui->id_stack); }
|
||||
fn ui_id_t ui_top_id(void) { return ui->id_stack->value; }
|
||||
#define ui_set_id(x) defer_block(ui_push_id(x), ui_pop_id())
|
||||
fn void ui_push_lop(ui_lop_t v) { ui_lop_node_t *n = ma_push_type(tcx.temp, ui_lop_node_t); n->value = v; SLLS_PUSH(ui->lop_stack, n); }
|
||||
fn void ui_push_lop(ui_lop_t v) { ui_lop_node_t *n = ma_push_type(tcx->temp, ui_lop_node_t); n->value = v; SLLS_PUSH(ui->lop_stack, n); }
|
||||
fn void ui_pop_lop(void) { SLLS_POP(ui->lop_stack); }
|
||||
fn ui_lop_t ui_top_lop(void) { return ui->lop_stack->value; }
|
||||
#define ui_set_lop(x) defer_block(ui_push_lop(x), ui_pop_lop())
|
||||
fn void ui_push_border_thickness(f32 v) { ui_f32_node_t *n = ma_push_type(tcx.temp, ui_f32_node_t); n->value = v; SLLS_PUSH(ui->border_thickness_stack, n); }
|
||||
fn void ui_push_border_thickness(f32 v) { ui_f32_node_t *n = ma_push_type(tcx->temp, ui_f32_node_t); n->value = v; SLLS_PUSH(ui->border_thickness_stack, n); }
|
||||
fn void ui_pop_border_thickness(void) { SLLS_POP(ui->border_thickness_stack); }
|
||||
fn f32 ui_top_border_thickness(void) { return ui->border_thickness_stack->value; }
|
||||
#define ui_set_border_thickness(x) defer_block(ui_push_border_thickness(x), ui_pop_border_thickness())
|
||||
fn void ui_push_text_align(ui_text_align_t v) { ui_text_align_node_t *n = ma_push_type(tcx.temp, ui_text_align_node_t); n->value = v; SLLS_PUSH(ui->text_align_stack, n); }
|
||||
fn void ui_push_text_align(ui_text_align_t v) { ui_text_align_node_t *n = ma_push_type(tcx->temp, ui_text_align_node_t); n->value = v; SLLS_PUSH(ui->text_align_stack, n); }
|
||||
fn void ui_pop_text_align(void) { SLLS_POP(ui->text_align_stack); }
|
||||
fn ui_text_align_t ui_top_text_align(void) { return ui->text_align_stack->value; }
|
||||
#define ui_set_text_align(x) defer_block(ui_push_text_align(x), ui_pop_text_align())
|
||||
fn void ui_push_required_size(f32 v) { ui_f32_node_t *n = ma_push_type(tcx.temp, ui_f32_node_t); n->value = v; SLLS_PUSH(ui->required_size_stack, n); }
|
||||
fn void ui_push_required_size(f32 v) { ui_f32_node_t *n = ma_push_type(tcx->temp, ui_f32_node_t); n->value = v; SLLS_PUSH(ui->required_size_stack, n); }
|
||||
fn void ui_pop_required_size(void) { SLLS_POP(ui->required_size_stack); }
|
||||
fn f32 ui_top_required_size(void) { return ui->required_size_stack->value; }
|
||||
#define ui_set_required_size(x) defer_block(ui_push_required_size(x), ui_pop_required_size())
|
||||
fn void ui_push_padding(f32 v) { ui_f32_node_t *n = ma_push_type(tcx.temp, ui_f32_node_t); n->value = v; SLLS_PUSH(ui->padding_stack, n); }
|
||||
fn void ui_push_padding(f32 v) { ui_f32_node_t *n = ma_push_type(tcx->temp, ui_f32_node_t); n->value = v; SLLS_PUSH(ui->padding_stack, n); }
|
||||
fn void ui_pop_padding(void) { SLLS_POP(ui->padding_stack); }
|
||||
fn f32 ui_top_padding(void) { return ui->padding_stack->value; }
|
||||
#define ui_set_padding(x) defer_block(ui_push_padding(x), ui_pop_padding())
|
||||
fn void ui_push_string_pos_offset(f32 v) { ui_f32_node_t *n = ma_push_type(tcx.temp, ui_f32_node_t); n->value = v; SLLS_PUSH(ui->string_pos_offset_stack, n); }
|
||||
fn void ui_push_string_pos_offset(f32 v) { ui_f32_node_t *n = ma_push_type(tcx->temp, ui_f32_node_t); n->value = v; SLLS_PUSH(ui->string_pos_offset_stack, n); }
|
||||
fn void ui_pop_string_pos_offset(void) { SLLS_POP(ui->string_pos_offset_stack); }
|
||||
fn f32 ui_top_string_pos_offset(void) { return ui->string_pos_offset_stack->value; }
|
||||
#define ui_set_string_pos_offset(x) defer_block(ui_push_string_pos_offset(x), ui_pop_string_pos_offset())
|
||||
fn void ui_push_background_color(v4f32_t v) { ui_v4f32_node_t *n = ma_push_type(tcx.temp, ui_v4f32_node_t); n->value = v; SLLS_PUSH(ui->background_color_stack, n); }
|
||||
fn void ui_push_background_color(v4f32_t v) { ui_v4f32_node_t *n = ma_push_type(tcx->temp, ui_v4f32_node_t); n->value = v; SLLS_PUSH(ui->background_color_stack, n); }
|
||||
fn void ui_pop_background_color(void) { SLLS_POP(ui->background_color_stack); }
|
||||
fn v4f32_t ui_top_background_color(void) { return ui->background_color_stack->value; }
|
||||
#define ui_set_background_color(x) defer_block(ui_push_background_color(x), ui_pop_background_color())
|
||||
fn void ui_push_bg_hot_color(v4f32_t v) { ui_v4f32_node_t *n = ma_push_type(tcx.temp, ui_v4f32_node_t); n->value = v; SLLS_PUSH(ui->bg_hot_color_stack, n); }
|
||||
fn void ui_push_bg_hot_color(v4f32_t v) { ui_v4f32_node_t *n = ma_push_type(tcx->temp, ui_v4f32_node_t); n->value = v; SLLS_PUSH(ui->bg_hot_color_stack, n); }
|
||||
fn void ui_pop_bg_hot_color(void) { SLLS_POP(ui->bg_hot_color_stack); }
|
||||
fn v4f32_t ui_top_bg_hot_color(void) { return ui->bg_hot_color_stack->value; }
|
||||
#define ui_set_bg_hot_color(x) defer_block(ui_push_bg_hot_color(x), ui_pop_bg_hot_color())
|
||||
fn void ui_push_bg_active_color(v4f32_t v) { ui_v4f32_node_t *n = ma_push_type(tcx.temp, ui_v4f32_node_t); n->value = v; SLLS_PUSH(ui->bg_active_color_stack, n); }
|
||||
fn void ui_push_bg_active_color(v4f32_t v) { ui_v4f32_node_t *n = ma_push_type(tcx->temp, ui_v4f32_node_t); n->value = v; SLLS_PUSH(ui->bg_active_color_stack, n); }
|
||||
fn void ui_pop_bg_active_color(void) { SLLS_POP(ui->bg_active_color_stack); }
|
||||
fn v4f32_t ui_top_bg_active_color(void) { return ui->bg_active_color_stack->value; }
|
||||
#define ui_set_bg_active_color(x) defer_block(ui_push_bg_active_color(x), ui_pop_bg_active_color())
|
||||
fn void ui_push_border_color(v4f32_t v) { ui_v4f32_node_t *n = ma_push_type(tcx.temp, ui_v4f32_node_t); n->value = v; SLLS_PUSH(ui->border_color_stack, n); }
|
||||
fn void ui_push_border_color(v4f32_t v) { ui_v4f32_node_t *n = ma_push_type(tcx->temp, ui_v4f32_node_t); n->value = v; SLLS_PUSH(ui->border_color_stack, n); }
|
||||
fn void ui_pop_border_color(void) { SLLS_POP(ui->border_color_stack); }
|
||||
fn v4f32_t ui_top_border_color(void) { return ui->border_color_stack->value; }
|
||||
#define ui_set_border_color(x) defer_block(ui_push_border_color(x), ui_pop_border_color())
|
||||
fn void ui_push_text_color(v4f32_t v) { ui_v4f32_node_t *n = ma_push_type(tcx.temp, ui_v4f32_node_t); n->value = v; SLLS_PUSH(ui->text_color_stack, n); }
|
||||
fn void ui_push_text_color(v4f32_t v) { ui_v4f32_node_t *n = ma_push_type(tcx->temp, ui_v4f32_node_t); n->value = v; SLLS_PUSH(ui->text_color_stack, n); }
|
||||
fn void ui_pop_text_color(void) { SLLS_POP(ui->text_color_stack); }
|
||||
fn v4f32_t ui_top_text_color(void) { return ui->text_color_stack->value; }
|
||||
#define ui_set_text_color(x) defer_block(ui_push_text_color(x), ui_pop_text_color())
|
||||
fn void ui_push_text_hot_color(v4f32_t v) { ui_v4f32_node_t *n = ma_push_type(tcx.temp, ui_v4f32_node_t); n->value = v; SLLS_PUSH(ui->text_hot_color_stack, n); }
|
||||
fn void ui_push_text_hot_color(v4f32_t v) { ui_v4f32_node_t *n = ma_push_type(tcx->temp, ui_v4f32_node_t); n->value = v; SLLS_PUSH(ui->text_hot_color_stack, n); }
|
||||
fn void ui_pop_text_hot_color(void) { SLLS_POP(ui->text_hot_color_stack); }
|
||||
fn v4f32_t ui_top_text_hot_color(void) { return ui->text_hot_color_stack->value; }
|
||||
#define ui_set_text_hot_color(x) defer_block(ui_push_text_hot_color(x), ui_pop_text_hot_color())
|
||||
fn void ui_push_text_active_color(v4f32_t v) { ui_v4f32_node_t *n = ma_push_type(tcx.temp, ui_v4f32_node_t); n->value = v; SLLS_PUSH(ui->text_active_color_stack, n); }
|
||||
fn void ui_push_text_active_color(v4f32_t v) { ui_v4f32_node_t *n = ma_push_type(tcx->temp, ui_v4f32_node_t); n->value = v; SLLS_PUSH(ui->text_active_color_stack, n); }
|
||||
fn void ui_pop_text_active_color(void) { SLLS_POP(ui->text_active_color_stack); }
|
||||
fn v4f32_t ui_top_text_active_color(void) { return ui->text_active_color_stack->value; }
|
||||
#define ui_set_text_active_color(x) defer_block(ui_push_text_active_color(x), ui_pop_text_active_color())
|
||||
@@ -113,13 +122,13 @@ ui_push_lop(ui_lop_cut_top);
|
||||
ui_push_border_thickness(1.0f);
|
||||
ui_push_text_align(ui_text_align_left);
|
||||
ui_push_string_pos_offset(0);
|
||||
ui_push_background_color(ui_color_table[ui_color_rect_color]);
|
||||
ui_push_bg_hot_color(ui_color_table[ui_color_rect_hot_color]);
|
||||
ui_push_bg_active_color(ui_color_table[ui_color_rect_active_color]);
|
||||
ui_push_border_color(ui_color_table[ui_color_border_color]);
|
||||
ui_push_text_color(ui_color_table[ui_color_text_color]);
|
||||
ui_push_text_hot_color(ui_color_table[ui_color_text_hot_color]);
|
||||
ui_push_text_active_color(ui_color_table[ui_color_text_active_color]);
|
||||
ui_push_background_color(ui_color_table[ui_color_rect]);
|
||||
ui_push_bg_hot_color(ui_color_table[ui_color_rect_hot]);
|
||||
ui_push_bg_active_color(ui_color_table[ui_color_rect_active]);
|
||||
ui_push_border_color(ui_color_table[ui_color_border]);
|
||||
ui_push_text_color(ui_color_table[ui_color_text]);
|
||||
ui_push_text_hot_color(ui_color_table[ui_color_text_hot]);
|
||||
ui_push_text_active_color(ui_color_table[ui_color_text_active]);
|
||||
}
|
||||
fn void ui_pop_init_values(void) {
|
||||
ui_pop_id();
|
||||
|
||||
@@ -1,13 +1,16 @@
|
||||
// automatically generated using: C:\dev\wasm\src/ui/ui.meta.c
|
||||
typedef enum {
|
||||
ui_color_rect_color,
|
||||
ui_color_rect_hot_color,
|
||||
ui_color_rect_active_color,
|
||||
ui_color_border_color,
|
||||
ui_color_text_color,
|
||||
ui_color_text_hot_color,
|
||||
ui_color_text_active_color,
|
||||
ui_color_focused_rect_color,
|
||||
ui_color_rect,
|
||||
ui_color_rect_hot,
|
||||
ui_color_rect_active,
|
||||
ui_color_border,
|
||||
ui_color_text,
|
||||
ui_color_text_hot,
|
||||
ui_color_text_active,
|
||||
ui_color_focused_rect,
|
||||
ui_color_scroller,
|
||||
ui_color_scroller_hot,
|
||||
ui_color_scroller_active,
|
||||
ui_color_count,
|
||||
} ui_color_t;
|
||||
|
||||
|
||||
@@ -156,7 +156,7 @@ fn b32 ui_is_focused_box(ui_box_t *box) { return !ui_is_null_box(box) && box->id
|
||||
fn void ui_set_rect(ui_box_t *box, r2f32_t rect, ui_lop_t lop) { box->rect = box->full_rect = rect; box->lop = lop; }
|
||||
|
||||
#define UILOC (ui_code_loc_t){.file = __FILE__, .line = __LINE__, .counter = __COUNTER__}
|
||||
#define ui_em(x) ((x) * rn_state.main_font->size)
|
||||
#define ui_em(x) ((x) * rn->main_font->size)
|
||||
#define ui_max 200000000.f
|
||||
#define ui_box_flags(...) (ui_box_flag_t){__VA_ARGS__}
|
||||
|
||||
|
||||
@@ -1,15 +1,17 @@
|
||||
fn void mt_ui_colors(ma_arena_t *arena, sb8_t *c, sb8_t *h) {
|
||||
ast_t *table = mtt_parse(arena, __FILE__, S8_CODE(
|
||||
{ name color }
|
||||
{ rect_color `v4f32_hsla_to_rgba((v4f32_t){0.0f, 0.2f, 0.95f, 1.0f})` }
|
||||
{ rect_hot_color `v4f32_hsla_to_rgba((v4f32_t){0.0f, 0.5f, 0.95f, 1.0f})` }
|
||||
{ rect_active_color `v4f32_hsla_to_rgba((v4f32_t){0.1f, 0.5f, 0.95f, 1.0f})` }
|
||||
{ border_color `v4f32_hsla_to_rgba((v4f32_t){0.0f, 0.2f, 0.70f, 1.0f})` }
|
||||
{ text_color `v4f32_hsla_to_rgba((v4f32_t){0.0f, 0.2f, 0.70f, 1.0f})` }
|
||||
{ text_hot_color `v4f32_hsla_to_rgba((v4f32_t){0.1f, 0.4f, 0.70f, 1.0f})` }
|
||||
{ text_active_color `v4f32_hsla_to_rgba((v4f32_t){0.1f, 0.5f, 0.70f, 1.0f})` }
|
||||
{ focused_rect_color `v4f32_hsla_to_rgba((v4f32_t){0.1f, 0.6f, 0.95f, 1.0f})` }
|
||||
{ scroller_color `v4f32_hsla_to_rgba((v4f32_t){0.1f, 0.6f, 0.95f, 1.0f})` }
|
||||
{ name color }
|
||||
{ rect `v4f32_hsla_to_rgba((v4f32_t){0.0f, 0.2f, 0.95f, 1.0f})` }
|
||||
{ rect_hot `v4f32_hsla_to_rgba((v4f32_t){0.0f, 0.5f, 0.95f, 1.0f})` }
|
||||
{ rect_active `v4f32_hsla_to_rgba((v4f32_t){0.1f, 0.5f, 0.95f, 1.0f})` }
|
||||
{ border `v4f32_hsla_to_rgba((v4f32_t){0.0f, 0.2f, 0.70f, 1.0f})` }
|
||||
{ text `v4f32_hsla_to_rgba((v4f32_t){0.0f, 0.2f, 0.70f, 1.0f})` }
|
||||
{ text_hot `v4f32_hsla_to_rgba((v4f32_t){0.1f, 0.4f, 0.70f, 1.0f})` }
|
||||
{ text_active `v4f32_hsla_to_rgba((v4f32_t){0.1f, 0.5f, 0.70f, 1.0f})` }
|
||||
{ focused_rect `v4f32_hsla_to_rgba((v4f32_t){0.1f, 0.6f, 0.95f, 1.0f})` }
|
||||
{ scroller `ui_color_table[ui_color_text]` }
|
||||
{ scroller_hot `v4f32_hsla_to_rgba((v4f32_t){0.1f, 0.2f, 0.7f, 1.0f})` }
|
||||
{ scroller_active `v4f32_hsla_to_rgba((v4f32_t){0.1f, 0.2f, 0.5f, 1.0f})` }
|
||||
));
|
||||
|
||||
mtt_serial_enum(c, h, table, s8_lit("ui_color"));
|
||||
@@ -38,13 +40,13 @@ fn void mt_ui_stacks(ma_arena_t *arena, sb8_t *c, sb8_t *h) {
|
||||
{ f32 required_size 0 x }
|
||||
{ f32 padding 0 x }
|
||||
{ f32 string_pos_offset 0 0 }
|
||||
{ v4f32_t background_color 0 `ui_color_table[ui_color_rect_color]` }
|
||||
{ v4f32_t bg_hot_color 0 `ui_color_table[ui_color_rect_hot_color]` }
|
||||
{ v4f32_t bg_active_color 0 `ui_color_table[ui_color_rect_active_color]` }
|
||||
{ v4f32_t border_color 0 `ui_color_table[ui_color_border_color]` }
|
||||
{ v4f32_t text_color 0 `ui_color_table[ui_color_text_color]` }
|
||||
{ v4f32_t text_hot_color 0 `ui_color_table[ui_color_text_hot_color]` }
|
||||
{ v4f32_t text_active_color 0 `ui_color_table[ui_color_text_active_color]` }
|
||||
{ v4f32_t background_color 0 `ui_color_table[ui_color_rect]` }
|
||||
{ v4f32_t bg_hot_color 0 `ui_color_table[ui_color_rect_hot]` }
|
||||
{ v4f32_t bg_active_color 0 `ui_color_table[ui_color_rect_active]` }
|
||||
{ v4f32_t border_color 0 `ui_color_table[ui_color_border]` }
|
||||
{ v4f32_t text_color 0 `ui_color_table[ui_color_text]` }
|
||||
{ v4f32_t text_hot_color 0 `ui_color_table[ui_color_text_hot]` }
|
||||
{ v4f32_t text_active_color 0 `ui_color_table[ui_color_text_active]` }
|
||||
));
|
||||
|
||||
///////////////////////////////
|
||||
@@ -98,7 +100,7 @@ fn void mt_ui_stacks(ma_arena_t *arena, sb8_t *c, sb8_t *h) {
|
||||
///////////////////////////////
|
||||
// generate stack functions
|
||||
for (ast_t *it = table->first; it; it = it->next) {
|
||||
mt_sbprintf(c, it, "fn void ui_push_@name(@type v) { @node *n = ma_push_type(tcx.temp, @node); n->value = v; SLLS_PUSH(ui->@stack, n); }\n"
|
||||
mt_sbprintf(c, it, "fn void ui_push_@name(@type v) { @node *n = ma_push_type(tcx->temp, @node); n->value = v; SLLS_PUSH(ui->@stack, n); }\n"
|
||||
"fn void ui_pop_@name(void) { SLLS_POP(ui->@stack); }\n"
|
||||
"fn @type ui_top_@name(void) { return ui->@stack->value; }\n"
|
||||
"#define ui_set_@name(x) defer_block(ui_push_@name(x), ui_pop_@name())\n");
|
||||
|
||||
Reference in New Issue
Block a user