Fix panel scrolling issue (clamping scroll value was only done when scrollers were on)

This commit is contained in:
Martin Fouilleul 2022-08-16 09:58:16 +02:00
parent 6fe1a29a4b
commit 0becc301d0
2 changed files with 70 additions and 55 deletions

View File

@ -519,8 +519,13 @@ ui_box* ui_box_make_str8(str8 string, ui_flags flags)
memset(box, 0, sizeof(ui_box));
box->key = key;
box->fresh = true;
ui_box_cache(ui, box);
}
else
{
box->fresh = false;
}
//NOTE: setup hierarchy
ListInit(&box->children);
@ -709,6 +714,12 @@ void ui_box_compute_styling(ui_context* ui, ui_box* box)
//TODO: interpolate based on transition values
u32 flags = box->computedStyle.animationFlags;
if(box->fresh)
{
box->computedStyle = *targetStyle;
}
else
{
if(flags & UI_STYLE_ANIMATE_BG_COLOR)
{
ui_animate_color(ui, &box->computedStyle.bgColor, targetStyle->bgColor, animationTime);
@ -773,6 +784,7 @@ void ui_box_compute_styling(ui_context* ui, ui_box* box)
}
box->computedStyle.font = targetStyle->font;
}
}
void ui_layout_prepass(ui_context* ui, ui_box* box)
{
@ -936,7 +948,8 @@ void ui_layout_compute_rect(ui_context* ui, ui_box* box, vec2 pos)
if(child->floating[i])
{
ui_style* style = child->targetStyle;
if(child->targetStyle->animationFlags & UI_STYLE_ANIMATE_POS)
if((child->targetStyle->animationFlags & UI_STYLE_ANIMATE_POS)
&& !child->fresh)
{
ui_animate_f32(ui, &child->floatPos.c[i], child->floatTarget.c[i], style->animationTime);
}
@ -1437,7 +1450,6 @@ void ui_panel_end()
panel->scroll.x += sig.wheel.x;
ui_box_activate(scrollBarX);
}
panel->scroll.x = Clamp(panel->scroll.x, 0, contentsW - panel->rect.w);
}
if(contentsH > panel->rect.h)
@ -1455,9 +1467,11 @@ void ui_panel_end()
panel->scroll.y += sig.wheel.y;
ui_box_activate(scrollBarY);
}
panel->scroll.y = Clamp(panel->scroll.y, 0, contentsH - panel->rect.h);
}
panel->scroll.x = Clamp(panel->scroll.x, 0, contentsW - panel->rect.w);
panel->scroll.y = Clamp(panel->scroll.y, 0, contentsH - panel->rect.h);
if(scrollBarX)
{
ui_box_set_floating(scrollBarX, UI_AXIS_X, panel->scroll.x);

View File

@ -168,6 +168,7 @@ struct ui_box
ui_sig* sig;
// stateful behaviour
bool fresh;
bool closed;
bool parentClosed;
bool dragging;