ui colors

This commit is contained in:
Krzosa Karol
2025-01-22 22:18:18 +01:00
parent de35c4a705
commit 057d6b6f50
13 changed files with 169 additions and 105 deletions

View File

@@ -125,11 +125,11 @@ 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->text_align_stack->value;
box->border_thickness = ui->border_thickness_stack->value;
box->background_color = ui->background_color_stack->value;
box->text_color = ui->text_color_stack->value;
box->border_color = ui->border_color_stack->value;
box->text_align = ui_top_text_align();
box->border_thickness = ui_top_border_thickness();
box->background_color = ui_top_background_color();
box->text_color = ui_top_text_color();
box->border_color = ui_top_border_color();
ui_push_box(ui->top, box);
return box;
}
@@ -139,6 +139,7 @@ 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);
// @todo: this is un0intuitive
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);
@@ -166,8 +167,6 @@ fn ui_box_t *ui__box0f(ui_code_loc_t loc, ui_box_flags_t flags, char *str, ...)
fn ui_signal_t ui_signal_from_box(ui_box_t *box) {
ui_signal_t result = {box};
app_event_t *ev = ui->event;
// b32 move = ev->kind == app_event_kind_mouse_move;
b32 inside = r2f32_contains(box->final_rect, ev->mouse_pos);
if (ui_is_active_box(box)) {
@@ -206,7 +205,7 @@ fn ui_signal_t ui__radio_button(ui_code_loc_t loc, i32 *value, i32 value_clicked
ui_box_t *box = ui_build_box_from_string(loc, (ui_box_flags_t){ .draw_border = true, .draw_rect = true, .draw_text = true }, string);
ui_signal_t signal = ui_signal_from_box(box);
if (signal.clicked) *value = value_clicked;
if (*value == value_clicked) box->background_color = accent1_color_global;
if (*value == value_clicked) box->background_color = ui_top_radio_color();
return signal;
}
@@ -260,33 +259,18 @@ 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);
ui_push_background_color(primary_color_global);
ui_push_text_color(black_color_global);
ui_push_border_color(accent2_color_global);
ui_push_init_values();
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->lop_stack);
SLLS_POP(ui->id_stack);
SLLS_POP(ui->border_thickness_stack);
SLLS_POP(ui->text_align_stack);
SLLS_POP(ui->background_color_stack);
SLLS_POP(ui->text_color_stack);
SLLS_POP(ui->border_color_stack);
ui_pop_init_values();
ui_assert_stacks_are_null();
for (ui_box_t *box = ui->hash_first, *next = NULL; box; box = next) {
@@ -300,11 +284,6 @@ fn void ui_end_build(void) {
}
}
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 void ui__draw_box(app_frame_t *frame, ui_box_t *box) {
r2f32_t rect = box->full_rect;
box->final_rect = r2f32_intersect(box->full_rect, ui->clip_rect);
@@ -314,25 +293,21 @@ fn void ui__draw_box(app_frame_t *frame, ui_box_t *box) {
v4f32_t border_color = box->border_color;
if (ui_is_hot_box(box)) {
if (ui_is_active_box(box)) {
f32 active_t = f32_clamp01(f32_ease_out_n(box->active_t, 50.f));
// background_color = v4f32_lerp(background_color, v4f32(1,1,1,1), 1.0);
text_color = v4f32_lerp(text_color, v4f32(1,1,1,1), active_t);
} else if (ui_is_hot_box(box)) {
f32 hot_t = f32_ease_out_n(box->hot_t, 25.f);
v4f32_t hsla_rect = v4f32_rgba_to_hsla(background_color);
hsla_rect.s = f32_lerp(hsla_rect.s, 1.0f, f32_ease_out_elastic(f32_clamp01(box->hot_t)));
hsla_rect.s = f32_lerp(hsla_rect.s, 1.0f, hot_t);
background_color = v4f32_hsla_to_rgba(hsla_rect);
// v4f32_t hsla_text = v4f32_rgba_to_hsla(text_color);
// hsla_text.l = f32_lerp(hsla_text.l, 1.0f, box->hot_t);
// text_color = v4f32_hsla_to_rgba(hsla_text);
v4f32_t hsla_text = v4f32_rgba_to_hsla(text_color);
hsla_text = v4f32_lerp(hsla_text, v4f32(0.2f, 0.3f, 0.3f, 1.0f), hot_t);
text_color = v4f32_hsla_to_rgba(hsla_text);
}
if (ui_is_active_box(box)) {
// v4f32_t hsla_rect = v4f32_rgba_to_hsla(background_color);
// hsla_rect.s = f32_lerp(hsla_rect.s, 1.0f, box->active_t);
// background_color = v4f32_hsla_to_rgba(hsla_rect);
// v4f32_t hsla_text = v4f32_rgba_to_hsla(text_color);
// hsla_text.l = f32_lerp(hsla_text.l, 1.0f, box->active_t);
// text_color = v4f32_hsla_to_rgba(hsla_text);
}
if (box->flags.draw_rect) {
rn_draw_rect(rect, background_color);
@@ -684,14 +659,16 @@ fn void ui_demo_update(app_frame_t *frame, mt_tweak_t *tweak_table, i32 tweak_co
ui_offset_box(it, v2f32(0, scroller_value));
}
}
} else if (ui_g_panel == 2) {
}
ui_end_build();
}
rn_begin(frame);
rn_begin(frame, white_color);
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_draw_stringf(rn_state.main_font, v2f32(0, frame->window_size.y - rn_state.main_font->size), v4f32(0,0,0,1), "boxes: %d", ui->allocated_boxes);
rn_end();
ui_end_frame();