wasm f32_pow, f64_pow, lots of changes to math, ui animations start

This commit is contained in:
Krzosa Karol
2025-01-22 17:59:30 +01:00
parent b20a507834
commit de35c4a705
19 changed files with 775 additions and 544 deletions

View File

@@ -127,7 +127,9 @@ fn ui_box_t *ui_build_box_from_id(ui_code_loc_t loc, ui_box_flags_t flags, ui_id
box->flags = flags;
box->text_align = ui->text_align_stack->value;
box->border_thickness = ui->border_thickness_stack->value;
if (ui->background_color_stack) box->background_color = ui->background_color_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;
ui_push_box(ui->top, box);
return box;
}
@@ -262,6 +264,9 @@ fn void ui_begin_build(ui_code_loc_t loc, app_event_t *ev, r2f32_t window_rect)
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);
zero_struct(&ui->root);
ui->root.full_rect = ui->root.rect = window_rect;
@@ -274,9 +279,15 @@ fn void ui_begin_build(ui_code_loc_t loc, app_event_t *ev, r2f32_t window_rect)
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_assert_stacks_are_null();
for (ui_box_t *box = ui->hash_first, *next = NULL; box; box = next) {
next = box->hash_next;
@@ -298,23 +309,36 @@ 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);
v4f32_t rect_color = primary_color_global;
if (!v4f32_is_null(box->background_color)) rect_color = box->background_color;
v4f32_t text_color = black_color_global;
v4f32_t background_color = box->background_color;
v4f32_t text_color = box->text_color;
v4f32_t border_color = box->border_color;
if (ui_is_hot_box(box)) {
rect_color = secondary_color_global;
text_color = accent2_color_global;
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)));
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);
}
if (ui_is_active_box(box)) {
rect_color = accent1_color_global;
text_color = white_color_global;
// 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, rect_color);
rn_draw_rect(rect, background_color);
}
if (box->flags.draw_border) {
rn_draw_rect_border(rect, accent2_color_global, box->border_thickness);
rn_draw_rect_border(rect, border_color, box->border_thickness);
}
if (box->flags.draw_text) {
v2f32_t string_size = rn_measure_string(rn_state.main_font, box->string);
@@ -341,6 +365,7 @@ fn void ui__draw_box(app_frame_t *frame, ui_box_t *box) {
ui->clip_rect = prev_clip_rect;
rn_set_clip(ui->clip_rect);
}
}
fn void ui_draw(void) {
@@ -354,6 +379,20 @@ fn void ui_begin_frame(app_frame_t *frame) {
}
fn void ui_end_frame(void) {
for (ui_box_t *box = ui->hash_first, *next = NULL; box; box = next) {
next = box->hash_next;
if (ui_is_hot_box(box)) {
box->hot_t += (f32)ui->frame->delta;
} else {
box->hot_t = 0;
}
if (ui_is_active_box(box)) {
box->active_t += (f32)ui->frame->delta;
} else {
box->active_t = 0;
}
}
for (app_event_t *ev = ui->frame->first_event; ev; ev = ev->next) {
if (ev_left_up(ev)) {
ui->active = ui_null_id;
@@ -561,15 +600,15 @@ fn void ui_demo_init(ma_arena_t *arena) {
gb i32 ui_g_panel = 1;
gb app_event_t ui_test_event;
fn void ui_demo_update(app_frame_t *frame) {
fn void ui_demo_update(app_frame_t *frame, mt_tweak_t *tweak_table, i32 tweak_count) {
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_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)));
ui_set_rect(top_box, r2f32_cut_top(&ui->top->rect, ui_em(1.5f)));
ui_set_padding(v2f32(50, 0))
ui_set_padding(v2f32(ui_em(3), 0))
ui_set_text_align(ui_text_align_center)
ui_set_lop(ui_lop_cut_left)
ui_set_top(top_box) {
@@ -577,7 +616,7 @@ fn void ui_demo_update(app_frame_t *frame) {
ui_radio_button(&ui_g_panel, 2, "2");
}
ui->top->rect = r2f32_shrinks(ui->top->rect, 100);
ui->top->rect = r2f32_shrinks(ui->top->rect, ui_em(1));
if (ui_g_panel == 1) {
@@ -586,10 +625,12 @@ fn void ui_demo_update(app_frame_t *frame) {
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));
item_box->rect = r2f32_shrinks(item_box->rect, ui_em(1));
ui_set_text_align(ui_text_align_left)
ui_set_top(item_box) {
for (i32 i = 0; i < lengthof(tweak_table); i += 1) {
for (i32 i = 0; i < tweak_count; i += 1) {
mt_tweak_t *tweak = tweak_table + i;
if (s8_starts_with(tweak->name, s8_lit("_"), false)) {
continue;