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

124
src/ui.c
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,69 +714,76 @@ void ui_box_compute_styling(ui_context* ui, ui_box* box)
//TODO: interpolate based on transition values
u32 flags = box->computedStyle.animationFlags;
if(flags & UI_STYLE_ANIMATE_BG_COLOR)
if(box->fresh)
{
ui_animate_color(ui, &box->computedStyle.bgColor, targetStyle->bgColor, animationTime);
box->computedStyle = *targetStyle;
}
else
{
box->computedStyle.bgColor = targetStyle->bgColor;
}
if(flags & UI_STYLE_ANIMATE_BG_COLOR)
{
ui_animate_color(ui, &box->computedStyle.bgColor, targetStyle->bgColor, animationTime);
}
else
{
box->computedStyle.bgColor = targetStyle->bgColor;
}
if(flags & UI_STYLE_ANIMATE_FG_COLOR)
{
ui_animate_color(ui, &box->computedStyle.fgColor, targetStyle->fgColor, animationTime);
}
else
{
box->computedStyle.fgColor = targetStyle->fgColor;
}
if(flags & UI_STYLE_ANIMATE_FG_COLOR)
{
ui_animate_color(ui, &box->computedStyle.fgColor, targetStyle->fgColor, animationTime);
}
else
{
box->computedStyle.fgColor = targetStyle->fgColor;
}
if(flags & UI_STYLE_ANIMATE_BORDER_COLOR)
{
ui_animate_color(ui, &box->computedStyle.borderColor, targetStyle->borderColor, animationTime);
}
else
{
box->computedStyle.borderColor = targetStyle->borderColor;
}
if(flags & UI_STYLE_ANIMATE_BORDER_COLOR)
{
ui_animate_color(ui, &box->computedStyle.borderColor, targetStyle->borderColor, animationTime);
}
else
{
box->computedStyle.borderColor = targetStyle->borderColor;
}
if(flags & UI_STYLE_ANIMATE_FONT_COLOR)
{
ui_animate_color(ui, &box->computedStyle.fontColor, targetStyle->fontColor, animationTime);
}
else
{
box->computedStyle.fontColor = targetStyle->fontColor;
}
if(flags & UI_STYLE_ANIMATE_FONT_COLOR)
{
ui_animate_color(ui, &box->computedStyle.fontColor, targetStyle->fontColor, animationTime);
}
else
{
box->computedStyle.fontColor = targetStyle->fontColor;
}
if(flags & UI_STYLE_ANIMATE_FONT_SIZE)
{
ui_animate_f32(ui, &box->computedStyle.fontSize, targetStyle->fontSize, animationTime);
}
else
{
box->computedStyle.fontSize = targetStyle->fontSize;
}
if(flags & UI_STYLE_ANIMATE_FONT_SIZE)
{
ui_animate_f32(ui, &box->computedStyle.fontSize, targetStyle->fontSize, animationTime);
}
else
{
box->computedStyle.fontSize = targetStyle->fontSize;
}
if(flags & UI_STYLE_ANIMATE_BORDER_SIZE)
{
ui_animate_f32(ui, &box->computedStyle.borderSize, targetStyle->borderSize, animationTime);
}
else
{
box->computedStyle.borderSize = targetStyle->borderSize;
}
if(flags & UI_STYLE_ANIMATE_BORDER_SIZE)
{
ui_animate_f32(ui, &box->computedStyle.borderSize, targetStyle->borderSize, animationTime);
}
else
{
box->computedStyle.borderSize = targetStyle->borderSize;
}
if(flags & UI_STYLE_ANIMATE_ROUNDNESS)
{
ui_animate_f32(ui, &box->computedStyle.roundness, targetStyle->roundness, animationTime);
if(flags & UI_STYLE_ANIMATE_ROUNDNESS)
{
ui_animate_f32(ui, &box->computedStyle.roundness, targetStyle->roundness, animationTime);
}
else
{
box->computedStyle.roundness = targetStyle->roundness;
}
box->computedStyle.font = targetStyle->font;
}
else
{
box->computedStyle.roundness = targetStyle->roundness;
}
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;