solve floating size violations
This commit is contained in:
parent
9e2634dfab
commit
00c95e5bee
15
src/pp/pp.c
15
src/pp/pp.c
@ -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);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -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;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,4 +1,4 @@
|
|||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
//~ Console
|
//~ Console
|
||||||
|
|
||||||
void PP_BuildDebugConsole(b32 minimized);
|
UI_Box *PP_BuildDebugConsole(b32 minimized);
|
||||||
|
|||||||
@ -502,30 +502,11 @@ 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 size_accum = 0;
|
f32 box_size = box->solved_dims[axis];
|
||||||
f32 flex_accum = 0;
|
/* Solve non-floating violations */
|
||||||
for (UI_Box *child = box->first; child; child = child->next)
|
|
||||||
{
|
|
||||||
if (!(child->flags & UI_BoxFlag_Floating))
|
|
||||||
{
|
|
||||||
f32 size = child->solved_dims[axis];
|
|
||||||
f32 strictness = child->pref_size[axis].strictness;
|
|
||||||
f32 flex = size * (1.0 - strictness);
|
|
||||||
if (axis == box->layout_axis)
|
|
||||||
{
|
|
||||||
size_accum += size;
|
|
||||||
flex_accum += flex;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
size_accum = MaxF32(size_accum, size);
|
|
||||||
flex_accum = MaxF32(flex_accum, flex);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
f32 violation = size_accum - box->solved_dims[axis];
|
|
||||||
if (violation > 0 && flex_accum > 0)
|
|
||||||
{
|
{
|
||||||
|
f32 size_accum = 0;
|
||||||
|
f32 flex_accum = 0;
|
||||||
for (UI_Box *child = box->first; child; child = child->next)
|
for (UI_Box *child = box->first; child; child = child->next)
|
||||||
{
|
{
|
||||||
if (!(child->flags & UI_BoxFlag_Floating))
|
if (!(child->flags & UI_BoxFlag_Floating))
|
||||||
@ -533,17 +514,58 @@ i64 UI_EndBuild(GPU_Resource *render_target)
|
|||||||
f32 size = child->solved_dims[axis];
|
f32 size = child->solved_dims[axis];
|
||||||
f32 strictness = child->pref_size[axis].strictness;
|
f32 strictness = child->pref_size[axis].strictness;
|
||||||
f32 flex = size * (1.0 - strictness);
|
f32 flex = size * (1.0 - strictness);
|
||||||
f32 new_size = size;
|
|
||||||
if (axis == box->layout_axis)
|
if (axis == box->layout_axis)
|
||||||
{
|
{
|
||||||
f32 chopoff = MinF32(flex, violation * (flex / flex_accum));
|
size_accum += size;
|
||||||
new_size = size - chopoff;
|
flex_accum += flex;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
new_size = MinF32(flex, box->solved_dims[axis]);
|
size_accum = MaxF32(size_accum, size);
|
||||||
|
flex_accum = MaxF32(flex_accum, flex);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
f32 violation = size_accum - box_size;
|
||||||
|
if (violation > 0 && flex_accum > 0)
|
||||||
|
{
|
||||||
|
for (UI_Box *child = box->first; child; child = child->next)
|
||||||
|
{
|
||||||
|
if (!(child->flags & UI_BoxFlag_Floating))
|
||||||
|
{
|
||||||
|
f32 size = child->solved_dims[axis];
|
||||||
|
f32 strictness = child->pref_size[axis].strictness;
|
||||||
|
f32 flex = size * (1.0 - strictness);
|
||||||
|
f32 new_size = size;
|
||||||
|
if (axis == box->layout_axis)
|
||||||
|
{
|
||||||
|
f32 chopoff = MinF32(flex, violation * (flex / flex_accum));
|
||||||
|
new_size = size - chopoff;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
new_size = MinF32(flex, box_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);
|
||||||
}
|
}
|
||||||
child->solved_dims[axis] = new_size;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -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;
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user