solve floating size violations

This commit is contained in:
jacob 2025-11-02 21:41:33 -06:00
parent 9e2634dfab
commit 00c95e5bee
4 changed files with 67 additions and 36 deletions

View File

@ -1932,16 +1932,21 @@ void PP_UpdateUser(void)
GPU_Stats gpu_stats = GPU_QueryStats(); GPU_Stats gpu_stats = GPU_QueryStats();
/* Draw console */ /* Draw console */
UI_Box *console_box = 0;
{ {
b32 console_minimized = !g->debug_console; b32 console_minimized = !g->debug_console;
PP_BuildDebugConsole(console_minimized); console_box = PP_BuildDebugConsole(console_minimized);
} }
/* Draw lister */ /* Draw lister */
if (g->debug_lister) if (g->debug_lister)
{ {
g->debug_lister_pos = g->ui_cursor; g->debug_lister_pos = g->ui_cursor;
g->debug_lister_pos.x -= 50;
Vec2 size = VEC2(400, 500);
Vec2 pos = g->debug_lister_pos;
pos.x -= size.x / 2;
UI_SetNext(LayoutAxis, Axis_Y); UI_SetNext(LayoutAxis, Axis_Y);
UI_SetNext(Tint, Alpha32F(0xFFFFFFFF, 0.5)); UI_SetNext(Tint, Alpha32F(0xFFFFFFFF, 0.5));
@ -1951,9 +1956,9 @@ void PP_UpdateUser(void)
UI_SetNext(Rounding, 0.25); UI_SetNext(Rounding, 0.25);
UI_SetNext(Parent, pp_root_box); UI_SetNext(Parent, pp_root_box);
UI_SetNext(Flags, UI_BoxFlag_Floating | UI_BoxFlag_ClampFloatingX | UI_BoxFlag_ClampFloatingY); UI_SetNext(Flags, UI_BoxFlag_Floating | UI_BoxFlag_ClampFloatingX | UI_BoxFlag_ClampFloatingY);
UI_SetNext(FloatingPos, g->debug_lister_pos); UI_SetNext(FloatingPos, pos);
UI_SetNext(Width, UI_PIX(100, 1)); UI_SetNext(Width, UI_PIX(size.x, 0));
UI_SetNext(Height, UI_PIX(100, 1)); UI_SetNext(Height, UI_PIX(size.y, 0));
UI_Box *lister_box = UI_BuildBox(UI_NilKey); UI_Box *lister_box = UI_BuildBox(UI_NilKey);
} }

View File

@ -1,7 +1,7 @@
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
//~ Console //~ Console
void PP_BuildDebugConsole(b32 minimized) UI_Box *PP_BuildDebugConsole(b32 minimized)
{ {
/* TODO: Remove this whole thing */ /* TODO: Remove this whole thing */
__prof; __prof;
@ -41,6 +41,7 @@ void PP_BuildDebugConsole(b32 minimized)
f32 bg_margin = 5; f32 bg_margin = 5;
i64 now_ns = TimeNs(); i64 now_ns = TimeNs();
UI_Box *console_box = 0;
UI_PushCheckpoint(); UI_PushCheckpoint();
{ {
{ {
@ -59,7 +60,7 @@ void PP_BuildDebugConsole(b32 minimized)
// UI_SetNext(Height, UI_FILL(0.33, 1)); // UI_SetNext(Height, UI_FILL(0.33, 1));
UI_SetNext(Height, UI_FIT(1)); UI_SetNext(Height, UI_FIT(1));
} }
UI_Box *console_box = UI_BuildBox(UI_NilKey); console_box = UI_BuildBox(UI_NilKey);
UI_Push(Parent, console_box); UI_Push(Parent, console_box);
} }
{ {
@ -143,4 +144,5 @@ void PP_BuildDebugConsole(b32 minimized)
} }
UI_PopCheckpoint(); UI_PopCheckpoint();
EndScratch(scratch); EndScratch(scratch);
return console_box;
} }

View File

@ -1,4 +1,4 @@
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
//~ Console //~ Console
void PP_BuildDebugConsole(b32 minimized); UI_Box *PP_BuildDebugConsole(b32 minimized);

View File

@ -501,6 +501,9 @@ i64 UI_EndBuild(GPU_Resource *render_target)
{ {
UI_Box *box = boxes_pre[pre_index]; UI_Box *box = boxes_pre[pre_index];
for (Axis axis = 0; axis < Axis_CountXY; ++axis) for (Axis axis = 0; axis < Axis_CountXY; ++axis)
{
f32 box_size = box->solved_dims[axis];
/* Solve non-floating violations */
{ {
f32 size_accum = 0; f32 size_accum = 0;
f32 flex_accum = 0; f32 flex_accum = 0;
@ -523,7 +526,7 @@ i64 UI_EndBuild(GPU_Resource *render_target)
} }
} }
} }
f32 violation = size_accum - box->solved_dims[axis]; f32 violation = size_accum - box_size;
if (violation > 0 && flex_accum > 0) if (violation > 0 && flex_accum > 0)
{ {
for (UI_Box *child = box->first; child; child = child->next) for (UI_Box *child = box->first; child; child = child->next)
@ -541,13 +544,32 @@ i64 UI_EndBuild(GPU_Resource *render_target)
} }
else else
{ {
new_size = MinF32(flex, box->solved_dims[axis]); new_size = MinF32(flex, box_size);
} }
child->solved_dims[axis] = new_size; child->solved_dims[axis] = new_size;
} }
} }
} }
} }
/* Solve floating violations */
for (UI_Box *child = box->first; child; child = child->next)
{
if (child->flags & UI_BoxFlag_Floating)
{
if (((child->flags & UI_BoxFlag_ClampFloatingX) && axis == Axis_X) ||
((child->flags & UI_BoxFlag_ClampFloatingY) && axis == Axis_Y))
{
f32 size = child->solved_dims[axis];
if (size > box_size)
{
f32 strictness = child->pref_size[axis].strictness;
f32 flex = size * (1.0 - strictness);
child->solved_dims[axis] = MaxF32(size - flex, box_size);
}
}
}
}
}
} }
/* Calculate final positions */ /* Calculate final positions */
@ -558,6 +580,7 @@ i64 UI_EndBuild(GPU_Resource *render_target)
Vec2 final_size = VEC2(box->solved_dims[0], box->solved_dims[1]); Vec2 final_size = VEC2(box->solved_dims[0], box->solved_dims[1]);
if (box->flags & UI_BoxFlag_Floating) if (box->flags & UI_BoxFlag_Floating)
{ {
/* Calculate floating box pos */
Vec2 offset = box->floating_pos; Vec2 offset = box->floating_pos;
box->p0 = AddVec2(parent->p0, offset); box->p0 = AddVec2(parent->p0, offset);
if (box->flags & UI_BoxFlag_ClampFloatingX) if (box->flags & UI_BoxFlag_ClampFloatingX)
@ -574,6 +597,7 @@ i64 UI_EndBuild(GPU_Resource *render_target)
} }
else else
{ {
/* Calculate non-floating box pos */
if (parent) if (parent)
{ {
b32 is_layout_x = parent->layout_axis == Axis_X; b32 is_layout_x = parent->layout_axis == Axis_X;