animate clip rect, fix main app

This commit is contained in:
Krzosa Karol
2025-02-03 09:33:09 +01:00
parent 9f33ea0914
commit e7a2a775b2
9 changed files with 67 additions and 78 deletions

View File

@@ -387,17 +387,21 @@ struct ui_draw_compute_t {
v4f32_t text_color;
};
fn r2f32_t ui_get_appear_rect(ui_box_t *box) {
r2f32_t result = box->rect;
f32 appear_t = f32_ease_out_n(f32_clamp01(box->appear_t * 2), 10);
if (!ui_id_is_null(box->id)) {
v2f32_t size = v2f32_muls(r2f32_get_size(result), 0.15f);
r2f32_t smaller_rect = r2f32_shrink(result, size);
result = r2f32_lerp(smaller_rect, result, appear_t);
}
return result;
}
fn ui_draw_compute_t ui_draw_compute(ui_box_t *box) {
ui_draw_compute_t co = {0};
co.rect = box->rect;
f32 appear_t = f32_ease_out_n(f32_clamp01(box->appear_t * 2), 10);
if (!ui_id_is_null(box->id)) {
v2f32_t size = v2f32_muls(r2f32_get_size(co.rect), 0.15f);
r2f32_t smaller_rect = r2f32_shrink(co.rect, size);
co.rect = r2f32_lerp(smaller_rect, co.rect, appear_t);
}
co.rect = ui_get_appear_rect(box);
co.background_color = box->background_color;
co.text_color = box->text_color;
co.border_color = box->border_color;
@@ -964,6 +968,7 @@ struct ui_scroller_params_t {
b8 enabled;
f32 *value;
f32 max_size;
ui_code_loc_t loc;
} hori;
struct {
b8 enabled;
@@ -973,6 +978,7 @@ struct ui_scroller_params_t {
i32 item_count;
// @option2: non efficient
f32 max_size;
ui_code_loc_t loc;
} verti;
};
@@ -990,11 +996,11 @@ struct ui_scroller_t {
ui_scroller_params_t p;
};
fn ui_scroller_t ui_begin_scroller(ui_scroller_params_t p) {
fn ui_scroller_t ui_begin_scroller(ui_code_loc_t loc, ui_scroller_params_t p) {
ui_scroller_t r = {.p = p};
if (p.verti.enabled) {
r.verti.box = ui_box(.rect = r2f32_cut_right(&p.parent->rect, ui_dm(0.5f)), .flags = {.draw_rect = true});
r.verti.box = ui_box(.loc = loc, .rect = r2f32_cut_right(&p.parent->rect, ui_dm(0.5f)), .flags = {.draw_rect = true});
r2f32_cut_bottom(&r.verti.box->rect, ui_dm(0.5f));
r.verti.item_box_pixels = r2f32_get_size(p.parent->rect).y;
@@ -1011,7 +1017,8 @@ fn ui_scroller_t ui_begin_scroller(ui_scroller_params_t p) {
}
if (p.hori.enabled) {
r.hori.box = ui_box(.rect = r2f32_cut_bottom(&p.parent->rect, ui_dm(0.5f)), .flags = {.draw_rect = true});
loc.counter += 10000;
r.hori.box = ui_box(.loc = loc, .rect = r2f32_cut_bottom(&p.parent->rect, ui_dm(0.5f)), .flags = {.draw_rect = true});
}
return r;
@@ -1157,7 +1164,8 @@ fn void ui__draw_box(app_frame_t *frame, ui_box_t *box) {
r2f32_t prev_clip_rect = ui->clip_rect;
if (box->flags.clip_rect) {
ui->clip_rect = r2f32_intersect(ui->clip_rect, box->rect);
r2f32_t rect = ui_get_appear_rect(box);
ui->clip_rect = r2f32_intersect(ui->clip_rect, rect);
rn_set_clip(ui->clip_rect);
}
for (ui_box_t *it = box->first; it; it = it->next) {
@@ -1184,7 +1192,11 @@ 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;
box->appear_t += (f32)ui->frame->delta;
// if (box->flags.animate_appear) {
box->appear_t += (f32)ui->frame->delta;
// } else {
// box->appear_t = 1;
// }
if (ui_is_hot_box(box)) {
box->hot_t += (f32)ui->frame->delta;
} else {
@@ -1249,7 +1261,7 @@ fn void ui_demo_update(app_frame_t *frame, mt_tweak_t *tweak_table, i32 tweak_co
ui_box_t *item_box = ui_box(r2f32_cut_left(ui_top_rectp(), ui_max), {.draw_rect = true, .clip_rect = true});
static f32 verti_scroller_value;
ui_scroller_t scroller = ui_begin_scroller((ui_scroller_params_t){
ui_scroller_t scroller = ui_begin_scroller(UILOC, (ui_scroller_params_t){
.parent = item_box,
.verti = {
.enabled = true,
@@ -1437,7 +1449,7 @@ fn void ui_demo_update(app_frame_t *frame, mt_tweak_t *tweak_table, i32 tweak_co
locl f32 right_scroller_value;
locl f32 bottom_scroller_value;
ui_scroller_t scroller = ui_begin_scroller((ui_scroller_params_t){
ui_scroller_t scroller = ui_begin_scroller(UILOC, (ui_scroller_params_t){
.parent = item_box,
.verti = {
.enabled = true,
@@ -1521,32 +1533,6 @@ fn void ui_demo_update(app_frame_t *frame, mt_tweak_t *tweak_table, i32 tweak_co
s8_lit("show data tab"),
s8_lit("show log tab"),
s8_lit("show menus tab"),
s8_lit("x"),
s8_lit("x1"),
s8_lit("x2"),
s8_lit("x3"),
s8_lit("x4"),
s8_lit("x5"),
s8_lit("x6"),
s8_lit("x7"),
s8_lit("x8"),
s8_lit("x9"),
s8_lit("x0"),
s8_lit("x22"),
s8_lit("x33"),
s8_lit("x44"),
s8_lit("x55"),
s8_lit("x66"),
s8_lit("x77"),
s8_lit("x88"),
s8_lit("x99"),
s8_lit("x123"),
s8_lit("x12"),
s8_lit("x32"),
s8_lit("x42"),
s8_lit("x52"),
s8_lit("x64"),
s8_lit("x75"),
};
if (lister_open) {
@@ -1556,10 +1542,10 @@ fn void ui_demo_update(app_frame_t *frame, mt_tweak_t *tweak_table, i32 tweak_co
v2f32_t pos = v2f32_divs(v2f32_sub(frame->window_size, lister_size), 2.0);
pos.y *= 0.05f;
r2f32_t rect = r2f32_min_dim(pos, lister_size);
ui_box_t *lister = ui_box(.id = lister_id, .rect = rect, .flags = {.draw_rect = true, .draw_border = true, .clip_rect = true});
ui_box_t *lister = ui_box(.id = lister_id, .rect = rect, .flags = {.animate_appear = true, .draw_rect = true, .draw_border = true, .clip_rect = true});
locl f32 verti_scroller_value;
ui_scroller_t scroller = ui_begin_scroller((ui_scroller_params_t){
ui_scroller_t scroller = ui_begin_scroller(UILOC, (ui_scroller_params_t){
.parent = lister,
.verti = {
.enabled = true,