PushCP & PopCP helpers

This commit is contained in:
jacob 2025-11-03 20:32:32 -06:00
parent e7410b917a
commit a3f6191247
5 changed files with 62 additions and 57 deletions

View File

@ -1939,7 +1939,7 @@ void PP_UpdateUser(void)
/* Draw lister */ /* Draw lister */
if (g->lister_active) if (g->lister_active)
{ {
UI_PushCheckpoint(); UI_PushCP(pp_root_box);
{ {
Vec2 size = VEC2(400, 500); Vec2 size = VEC2(400, 500);
@ -1949,32 +1949,29 @@ void PP_UpdateUser(void)
g->lister_pos = SubVec2(g->ui_cursor, ev.activation_offset); g->lister_pos = SubVec2(g->ui_cursor, ev.activation_offset);
} }
UI_SetNext(LayoutAxis, Axis_Y); UI_Push(BackgroundColor, Rgba32F(0.075, 0.075, 0.075, 0.99));
UI_SetNext(BackgroundColor, Rgba32F(0.075, 0.075, 0.075, 0.99)); UI_Push(BorderColor, Rgba32F(0.2, 0.2, 0.2, 1));
UI_SetNext(BorderColor, Rgba32F(0.2, 0.2, 0.2, 1)); UI_Push(Border, 2);
UI_SetNext(Border, 2);
UI_SetNext(Rounding, UI_RPIX(10));
UI_SetNext(Parent, pp_root_box);
UI_SetNext(Flags, UI_BoxFlag_Floating);
UI_SetNext(FloatingPos, g->lister_pos); UI_SetNext(FloatingPos, g->lister_pos);
UI_SetNext(LayoutAxis, Axis_Y);
UI_SetNext(Rounding, UI_RPIX(10));
UI_SetNext(Flags, UI_BoxFlag_Floating);
UI_SetNext(Width, UI_PIX(size.x, 0)); UI_SetNext(Width, UI_PIX(size.x, 0));
UI_SetNext(Height, UI_PIX(size.y, 0)); UI_SetNext(Height, UI_PIX(size.y, 0));
UI_Box *lister_box = UI_BuildBox(Lit("lister")); UI_Box *lister_box = UI_BuildBox(Lit("lister"));
g->lister_key = lister_box->key; UI_PushCP(lister_box);
UI_PushCheckpoint();
{ {
UI_Push(Parent, lister_box); UI_Push(BackgroundColor, 0);
// UI_BuildSpacer(UI_PIX(10, 0)); // UI_BuildSpacer(UI_PIX(10, 0));
{ {
UI_SetNext(LayoutAxis, Axis_X); UI_SetNext(LayoutAxis, Axis_X);
UI_SetNext(Width, UI_FILL(1, 0)); UI_SetNext(Width, UI_FILL(1, 0));
UI_SetNext(Height, UI_FNT(1, 0)); UI_SetNext(Height, UI_FNT(1, 0));
// UI_SetNext(BackgroundColor, 0);
// UI_SetNext(Border, 0); // UI_SetNext(Border, 0);
UI_Box *title_bar = UI_BuildBox(Zstr); UI_Box *title_bar = UI_BuildBox(Zstr);
UI_PushCP(title_bar);
{ {
UI_Push(Parent, title_bar);
UI_Push(Width, UI_FILL(1, 0)); UI_Push(Width, UI_FILL(1, 0));
UI_Push(Padding, 0); UI_Push(Padding, 0);
UI_Push(BackgroundColor, 0); UI_Push(BackgroundColor, 0);
@ -1990,13 +1987,16 @@ void PP_UpdateUser(void)
} }
{ {
UI_Box *right_box = UI_BuildBox(Zstr); UI_Box *right_box = UI_BuildBox(Zstr);
} }
} }
UI_PopCP();
} }
} }
UI_PopCheckpoint(); UI_PopCP();
g->lister_key = lister_box->key;
} }
UI_PopCheckpoint(); UI_PopCP();
} }
/* Draw debug info */ /* Draw debug info */
@ -2013,9 +2013,8 @@ void PP_UpdateUser(void)
UI_SetNext(Height, UI_FIT(1)); UI_SetNext(Height, UI_FIT(1));
UI_SetNext(Tint, 0); UI_SetNext(Tint, 0);
UI_Box *dbg_box = UI_BuildBox(Lit("dbg")); UI_Box *dbg_box = UI_BuildBox(Lit("dbg"));
UI_PushCheckpoint(); UI_PushCP(dbg_box);
{ {
UI_Push(Parent, dbg_box);
UI_Push(BackgroundColor, 0); UI_Push(BackgroundColor, 0);
UI_Push(BorderColor, 0); UI_Push(BorderColor, 0);
UI_Push(Padding, 2); UI_Push(Padding, 2);
@ -2081,7 +2080,7 @@ void PP_UpdateUser(void)
//UI_BuildLabelF(\n")); //UI_BuildLabelF(\n"));
#endif #endif
} }
UI_PopCheckpoint(); UI_PopCP();
} }
////////////////////////////// //////////////////////////////

View File

@ -42,8 +42,6 @@ UI_Box *PP_BuildDebugConsole(b32 minimized)
i64 now_ns = TimeNs(); i64 now_ns = TimeNs();
UI_Box *console_box = 0; UI_Box *console_box = 0;
UI_PushCheckpoint();
{
{ {
UI_SetNext(LayoutAxis, Axis_Y); UI_SetNext(LayoutAxis, Axis_Y);
UI_SetNext(Border, 0); UI_SetNext(Border, 0);
@ -61,8 +59,7 @@ UI_Box *PP_BuildDebugConsole(b32 minimized)
UI_SetNext(Height, UI_FIT(1)); UI_SetNext(Height, UI_FIT(1));
} }
console_box = UI_BuildBox(Lit("Console box")); console_box = UI_BuildBox(Lit("Console box"));
UI_Push(Parent, console_box); UI_PushCP(console_box);
}
{ {
/* Gather display logs */ /* Gather display logs */
u64 max = 20; u64 max = 20;
@ -112,7 +109,7 @@ UI_Box *PP_BuildDebugConsole(b32 minimized)
FmtUintZ(datetime.milliseconds, 3), FmtUintZ(datetime.milliseconds, 3),
FmtString(text)); FmtString(text));
} }
UI_PushCheckpoint(); UI_PushCP(0);
{ {
UI_Push(Tint, Alpha32F(0xFFFFFFFF, opacity)); UI_Push(Tint, Alpha32F(0xFFFFFFFF, opacity));
{ {
@ -125,8 +122,7 @@ UI_Box *PP_BuildDebugConsole(b32 minimized)
UI_SetNext(Rounding, UI_RPIX(0)); UI_SetNext(Rounding, UI_RPIX(0));
UI_SetNext(Border, 1); UI_SetNext(Border, 1);
UI_Box *log_box = UI_BuildBox(Zstr); UI_Box *log_box = UI_BuildBox(Zstr);
UI_Push(Parent, log_box); UI_PushCP(log_box);
}
{ {
UI_SetNext(BackgroundColor, 0); UI_SetNext(BackgroundColor, 0);
UI_SetNext(Border, 0); UI_SetNext(Border, 0);
@ -137,12 +133,15 @@ UI_Box *PP_BuildDebugConsole(b32 minimized)
UI_SetNext(Flags, UI_BoxFlag_DrawText); UI_SetNext(Flags, UI_BoxFlag_DrawText);
UI_Box *log_textbox = UI_BuildBox(Zstr); UI_Box *log_textbox = UI_BuildBox(Zstr);
} }
} UI_PopCP();
UI_PopCheckpoint();
} }
} }
UI_PopCP();
} }
UI_PopCheckpoint(); }
UI_PopCP();
}
EndScratch(scratch); EndScratch(scratch);
return console_box; return console_box;
} }

View File

@ -3,7 +3,7 @@
UI_Box *UI_BuildLabel(String text) UI_Box *UI_BuildLabel(String text)
{ {
UI_SetNext(Width, UI_FIT(1)); UI_SetNext(Width, UI_FIT(0));
UI_SetNext(Height, UI_FIT(1)); UI_SetNext(Height, UI_FIT(1));
UI_SetNext(Text, text); UI_SetNext(Text, text);
UI_SetNext(Flags, UI_BoxFlag_DrawText); UI_SetNext(Flags, UI_BoxFlag_DrawText);

View File

@ -62,7 +62,7 @@ UI_Box *UI_FrontBoxFromKey(UI_Key key)
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
//~ Checkpoint helpers //~ Checkpoint helpers
void UI_PushCheckpoint(void) void UI_PushCP(UI_Box *parent)
{ {
UI_SharedState *g = &UI_shared_state; UI_SharedState *g = &UI_shared_state;
UI_Checkpoint *cp = g->first_free_checkpoint; UI_Checkpoint *cp = g->first_free_checkpoint;
@ -78,9 +78,13 @@ void UI_PushCheckpoint(void)
cp->next = g->top_checkpoint; cp->next = g->top_checkpoint;
cp->v = g->top_checkpoint->v + 1; cp->v = g->top_checkpoint->v + 1;
g->top_checkpoint = cp; g->top_checkpoint = cp;
if (parent != 0)
{
UI_Push(Parent, parent);
}
} }
void UI_PopCheckpoint(void) void UI_PopCP(void)
{ {
UI_SharedState *g = &UI_shared_state; UI_SharedState *g = &UI_shared_state;
UI_Checkpoint *cp = g->top_checkpoint; UI_Checkpoint *cp = g->top_checkpoint;
@ -696,7 +700,10 @@ i64 UI_EndBuild(GPU_Resource *render_target, Xform ui_to_screen_xf)
} }
else else
{ {
new_size = MinF32(flex, box_size); if (size > box_size)
{
new_size = MaxF32(size - flex, box_size);
}
} }
child->solved_dims[axis] = new_size; child->solved_dims[axis] = new_size;
} }

View File

@ -265,8 +265,8 @@ UI_Box *UI_FrontBoxFromKey(UI_Key key);
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
//~ Checkpoint helpers //~ Checkpoint helpers
void UI_PushCheckpoint(void); void UI_PushCP(UI_Box *parent);
void UI_PopCheckpoint(void); void UI_PopCP(void);
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
//~ Style helpers //~ Style helpers