rename ui fit/fill -> shrink/grow

This commit is contained in:
jacob 2025-11-07 19:43:12 -06:00
parent bb322b64ca
commit ba580721c9
4 changed files with 38 additions and 38 deletions

View File

@ -79,7 +79,7 @@ void PP_EndCommandsWidget(PP_CommandsWidget *widget)
// UI_Push(Rounding, UI_RPIX(15)); // UI_Push(Rounding, UI_RPIX(15));
UI_Push(Rounding, UI_RPIX(15)); UI_Push(Rounding, UI_RPIX(15));
UI_Push(Width, UI_PIX(theme.window_width, 0)); UI_Push(Width, UI_PIX(theme.window_width, 0));
UI_Push(Height, UI_FIT(0, 0)); UI_Push(Height, UI_SHRINK(0, 0));
UI_Push(ChildLayoutAxis, Axis_Y); UI_Push(ChildLayoutAxis, Axis_Y);
UI_Push(FloatingPos, widget->pos); UI_Push(FloatingPos, widget->pos);
UI_SetNext(Flags, UI_BoxFlag_Floating); UI_SetNext(Flags, UI_BoxFlag_Floating);
@ -92,12 +92,12 @@ void PP_EndCommandsWidget(PP_CommandsWidget *widget)
UI_Push(BorderColor, titlebar_border_color); UI_Push(BorderColor, titlebar_border_color);
UI_Push(Rounding, UI_RPIX(0)); UI_Push(Rounding, UI_RPIX(0));
UI_Push(ChildLayoutAxis, Axis_X); UI_Push(ChildLayoutAxis, Axis_X);
UI_Push(Width, UI_FILL(1, 0)); UI_Push(Width, UI_GROW(1, 0));
UI_Push(Height, UI_FNT(2, 1)); UI_Push(Height, UI_FNT(2, 1));
UI_SetNext(Flags, UI_BoxFlag_DrawText | UI_BoxFlag_Interactable); UI_SetNext(Flags, UI_BoxFlag_DrawText | UI_BoxFlag_Interactable);
UI_PushCP(UI_BuildBox(titlebar_key)); UI_PushCP(UI_BuildBox(titlebar_key));
{ {
UI_Push(Width, UI_FILL(1, 0)); UI_Push(Width, UI_GROW(1, 0));
UI_Push(BorderColor, 0); UI_Push(BorderColor, 0);
/* Left title box */ /* Left title box */
@ -106,7 +106,7 @@ void PP_EndCommandsWidget(PP_CommandsWidget *widget)
/* Title box */ /* Title box */
UI_SetNext(FontSize, theme.window_title_font_size); UI_SetNext(FontSize, theme.window_title_font_size);
UI_SetNext(ChildAlignment, UI_Alignment_Center); UI_SetNext(ChildAlignment, UI_Alignment_Center);
UI_SetNext(Width, UI_FIT(0, 1)); UI_SetNext(Width, UI_SHRINK(0, 1));
UI_SetNext(Text, Lit("Commands")); UI_SetNext(Text, Lit("Commands"));
UI_SetNext(Flags, UI_BoxFlag_DrawText); UI_SetNext(Flags, UI_BoxFlag_DrawText);
UI_BuildBox(UI_NilKey); UI_BuildBox(UI_NilKey);
@ -128,7 +128,7 @@ void PP_EndCommandsWidget(PP_CommandsWidget *widget)
{ {
UI_SetNext(Tint, 0); UI_SetNext(Tint, 0);
UI_SetNext(Rounding, 0); UI_SetNext(Rounding, 0);
UI_SetNext(Width, UI_FILL(1, 0)); UI_SetNext(Width, UI_GROW(1, 0));
UI_PushCP(UI_BuildColumn(UI_NilKey)); UI_PushCP(UI_BuildColumn(UI_NilKey));
{ {
for (PP_CommandsWidgetItem *item = widget->build.first_item; item; item = item->next) for (PP_CommandsWidgetItem *item = widget->build.first_item; item; item = item->next)
@ -158,7 +158,7 @@ void PP_EndCommandsWidget(PP_CommandsWidget *widget)
UI_SetNext(BorderColor, border_color); UI_SetNext(BorderColor, border_color);
UI_SetNext(BackgroundColor, color); UI_SetNext(BackgroundColor, color);
UI_SetNext(Rounding, UI_RPIX(5)); UI_SetNext(Rounding, UI_RPIX(5));
UI_SetNext(Width, UI_FILL(1, 0)); UI_SetNext(Width, UI_GROW(1, 0));
UI_SetNext(Height, UI_FNT(1.5, 1)); UI_SetNext(Height, UI_FNT(1.5, 1));
UI_SetNext(ChildAlignment, UI_Alignment_Left); UI_SetNext(ChildAlignment, UI_Alignment_Left);
UI_SetNext(Flags, UI_BoxFlag_DrawText | UI_BoxFlag_Interactable); UI_SetNext(Flags, UI_BoxFlag_DrawText | UI_BoxFlag_Interactable);
@ -171,12 +171,12 @@ void PP_EndCommandsWidget(PP_CommandsWidget *widget)
UI_BuildLabel(item->name); UI_BuildLabel(item->name);
/* Middle spacer */ /* Middle spacer */
UI_BuildSpacer(UI_FILL(1, 0)); UI_BuildSpacer(UI_GROW(1, 0));
/* Command hotkey button */ /* Command hotkey button */
UI_SetNext(Text, UI_StringF("Test")); UI_SetNext(Text, UI_StringF("Test"));
UI_SetNext(Width, UI_FIT(theme.text_padding_x, 1)); UI_SetNext(Width, UI_SHRINK(theme.text_padding_x, 1));
UI_SetNext(Height, UI_FIT(theme.text_padding_y, 1)); UI_SetNext(Height, UI_SHRINK(theme.text_padding_y, 1));
UI_SetNext(Rounding, UI_RPIX(0)); UI_SetNext(Rounding, UI_RPIX(0));
UI_SetNext(Border, 1); UI_SetNext(Border, 1);
UI_SetNext(BackgroundColor, 0); UI_SetNext(BackgroundColor, 0);
@ -253,13 +253,13 @@ UI_Box *PP_BuildConsoleWidget(b32 minimized)
{ {
UI_SetNext(BackgroundColor, 0); UI_SetNext(BackgroundColor, 0);
UI_SetNext(Width, UI_PIX(500, 0)); UI_SetNext(Width, UI_PIX(500, 0));
UI_SetNext(Height, UI_FIT(0, 1)); UI_SetNext(Height, UI_SHRINK(0, 1));
} }
else else
{ {
UI_SetNext(BackgroundColor, Rgba(1, 1, 1, 0.02)); UI_SetNext(BackgroundColor, Rgba(1, 1, 1, 0.02));
UI_SetNext(Width, UI_FILL(1, 0)); UI_SetNext(Width, UI_GROW(1, 0));
UI_SetNext(Height, UI_FIT(0, 1)); UI_SetNext(Height, UI_SHRINK(0, 1));
} }
console_box = UI_BuildColumn(UI_KeyF("Console box")); console_box = UI_BuildColumn(UI_KeyF("Console box"));
UI_PushCP(console_box); UI_PushCP(console_box);
@ -319,7 +319,7 @@ UI_Box *PP_BuildConsoleWidget(b32 minimized)
{ {
Vec4 color = colors[log.level][log.level_id % 2]; Vec4 color = colors[log.level][log.level_id % 2];
UI_Push(BackgroundColor, color); UI_Push(BackgroundColor, color);
UI_Push(Width, UI_FILL(1, 0)); UI_Push(Width, UI_GROW(1, 0));
UI_Push(Height, UI_FNT(1.5, 1)); UI_Push(Height, UI_FNT(1.5, 1));
UI_Push(BorderColor, Rgb(0.25, 0.25, 0.25)); UI_Push(BorderColor, Rgb(0.25, 0.25, 0.25));
UI_Push(Rounding, UI_RPIX(0)); UI_Push(Rounding, UI_RPIX(0));
@ -332,8 +332,8 @@ UI_Box *PP_BuildConsoleWidget(b32 minimized)
UI_Push(BackgroundColor, 0); UI_Push(BackgroundColor, 0);
UI_Push(Border, 0); UI_Push(Border, 0);
UI_Push(Text, text); UI_Push(Text, text);
UI_Push(Width, UI_FILL(1, 0)); UI_Push(Width, UI_GROW(1, 0));
UI_Push(Height, UI_FIT(0, 1)); UI_Push(Height, UI_SHRINK(0, 1));
UI_Push(Flags, UI_BoxFlag_DrawText); UI_Push(Flags, UI_BoxFlag_DrawText);
UI_BuildBox(UI_NilKey); UI_BuildBox(UI_NilKey);
} }

View File

@ -16,8 +16,8 @@ UI_Box *UI_BuildLabel(String text)
UI_SetNext(Tint, tint); UI_SetNext(Tint, tint);
UI_SetNext(Font, font); UI_SetNext(Font, font);
UI_SetNext(FontSize, font_size); UI_SetNext(FontSize, font_size);
UI_SetNext(Width, UI_FIT(0, 1)); UI_SetNext(Width, UI_SHRINK(0, 1));
UI_SetNext(Height, UI_FIT(0, 1)); UI_SetNext(Height, UI_SHRINK(0, 1));
UI_SetNext(Text, text); UI_SetNext(Text, text);
UI_SetNext(Flags, UI_BoxFlag_DrawText); UI_SetNext(Flags, UI_BoxFlag_DrawText);
box = UI_BuildBox(UI_NilKey); box = UI_BuildBox(UI_NilKey);
@ -54,7 +54,7 @@ UI_Box *UI_BuildSpacer(UI_Size size)
UI_PushDefaults(); UI_PushDefaults();
UI_Push(Parent, parent); UI_Push(Parent, parent);
UI_Push(Tint, 0); UI_Push(Tint, 0);
UI_Push(AxisSize, UI_FILL(1, 0), .axis = !axis); UI_Push(AxisSize, UI_GROW(1, 0), .axis = !axis);
UI_Push(AxisSize, size, .axis = axis); UI_Push(AxisSize, size, .axis = axis);
box = UI_BuildBox(UI_NilKey); box = UI_BuildBox(UI_NilKey);
} }
@ -74,7 +74,7 @@ UI_Box *UI_BuildDivider(UI_Size size, Vec4 color)
UI_Push(Parent, parent); UI_Push(Parent, parent);
UI_Push(Tint, tint); UI_Push(Tint, tint);
UI_Push(BackgroundColor, color); UI_Push(BackgroundColor, color);
UI_Push(AxisSize, UI_FILL(1, 0), .axis = !axis); UI_Push(AxisSize, UI_GROW(1, 0), .axis = !axis);
UI_Push(AxisSize, size, .axis = axis); UI_Push(AxisSize, size, .axis = axis);
box = UI_BuildBox(UI_NilKey); box = UI_BuildBox(UI_NilKey);
} }

View File

@ -153,8 +153,8 @@ void UI_PushDefaults(void)
{ {
default: break; default: break;
case UI_StyleKind_Parent: { desc.style.Parent = g->root_box; } break; case UI_StyleKind_Parent: { desc.style.Parent = g->root_box; } break;
case UI_StyleKind_Width: { desc.style.Width = UI_FILL(1, 0); } break; case UI_StyleKind_Width: { desc.style.Width = UI_GROW(1, 0); } break;
case UI_StyleKind_Height: { desc.style.Height = UI_FILL(1, 0); } break; case UI_StyleKind_Height: { desc.style.Height = UI_GROW(1, 0); } break;
case UI_StyleKind_Font: { desc.style.Font = UI_GetDefaultFontResource(); } break; case UI_StyleKind_Font: { desc.style.Font = UI_GetDefaultFontResource(); } break;
case UI_StyleKind_FontSize: { desc.style.FontSize = 16.0f; } break; case UI_StyleKind_FontSize: { desc.style.FontSize = 16.0f; } break;
case UI_StyleKind_Tint: { desc.style.Tint = Color_White; } break; case UI_StyleKind_Tint: { desc.style.Tint = Color_White; } break;
@ -781,7 +781,7 @@ i64 UI_EndFrame(UI_Frame frame)
{ {
box->solved_dims[axis] = pref_size.v; box->solved_dims[axis] = pref_size.v;
} }
else if (pref_size.kind == UI_SizeKind_Fit && AnyBit(box->flags, UI_BoxFlag_DrawText)) else if (pref_size.kind == UI_SizeKind_Shrink && AnyBit(box->flags, UI_BoxFlag_DrawText))
{ {
/* TODO: Distinguish between baseline alignment & visual alignment */ /* TODO: Distinguish between baseline alignment & visual alignment */
f32 text_size = 0; f32 text_size = 0;
@ -814,14 +814,14 @@ i64 UI_EndFrame(UI_Frame frame)
{ {
Axis axis = box->parent->child_layout_axis; Axis axis = box->parent->child_layout_axis;
UI_Size pref_size = box->pref_size[axis]; UI_Size pref_size = box->pref_size[axis];
if (pref_size.kind == UI_SizeKind_Fill) if (pref_size.kind == UI_SizeKind_Grow)
{ {
f32 match_size = 0; f32 match_size = 0;
b32 found_match = 0; b32 found_match = 0;
for (UI_Box *ancestor = box->parent; ancestor != 0 && !found_match; ancestor = ancestor->parent) for (UI_Box *ancestor = box->parent; ancestor != 0 && !found_match; ancestor = ancestor->parent)
{ {
UI_Size ancestor_size = ancestor->pref_size[axis]; UI_Size ancestor_size = ancestor->pref_size[axis];
if (ancestor_size.kind == UI_SizeKind_Pixel || (ancestor_size.kind == UI_SizeKind_Fit && AnyBit(box->flags, UI_BoxFlag_DrawText))) if (ancestor_size.kind == UI_SizeKind_Pixel || (ancestor_size.kind == UI_SizeKind_Shrink && AnyBit(box->flags, UI_BoxFlag_DrawText)))
{ {
/* Match independent ancestor */ /* Match independent ancestor */
match_size = ancestor->solved_dims[axis]; match_size = ancestor->solved_dims[axis];
@ -840,7 +840,7 @@ i64 UI_EndFrame(UI_Frame frame)
for (Axis axis = 0; axis < Axis_CountXY; ++axis) for (Axis axis = 0; axis < Axis_CountXY; ++axis)
{ {
UI_Size pref_size = box->pref_size[axis]; UI_Size pref_size = box->pref_size[axis];
if (pref_size.kind == UI_SizeKind_Fit && !AnyBit(box->flags, UI_BoxFlag_DrawText)) if (pref_size.kind == UI_SizeKind_Shrink && !AnyBit(box->flags, UI_BoxFlag_DrawText))
{ {
f32 accum = 0; f32 accum = 0;
for (UI_Box *child = box->first; child; child = child->next) for (UI_Box *child = box->first; child; child = child->next)
@ -870,7 +870,7 @@ i64 UI_EndFrame(UI_Frame frame)
{ {
Axis axis = !box->parent->child_layout_axis; Axis axis = !box->parent->child_layout_axis;
UI_Size pref_size = box->pref_size[axis]; UI_Size pref_size = box->pref_size[axis];
if (pref_size.kind == UI_SizeKind_Fill) if (pref_size.kind == UI_SizeKind_Grow)
{ {
box->solved_dims[axis] = box->parent->solved_dims[axis] * pref_size.v; box->solved_dims[axis] = box->parent->solved_dims[axis] * pref_size.v;
} }
@ -1068,7 +1068,7 @@ i64 UI_EndFrame(UI_Frame frame)
final_rounding_br = final_rounding_tl; final_rounding_br = final_rounding_tl;
final_rounding_bl = final_rounding_tl; final_rounding_bl = final_rounding_tl;
} break; } break;
case UI_RoundKind_Fill: case UI_RoundKind_Grow:
{ {
final_rounding_tl = rounding.v * min_half_dims; final_rounding_tl = rounding.v * min_half_dims;
final_rounding_tr = final_rounding_tl; final_rounding_tr = final_rounding_tl;

View File

@ -15,8 +15,8 @@ Struct(UI_Key)
Enum(UI_SizeKind) Enum(UI_SizeKind)
{ {
UI_SizeKind_Pixel, /* Exact size */ UI_SizeKind_Pixel, /* Exact size */
UI_SizeKind_Fill, /* Size as percent of parent size */ UI_SizeKind_Grow, /* Size as percent of parent size */
UI_SizeKind_Fit, /* Size to contents */ UI_SizeKind_Shrink, /* Size of children + padding in pixels */
}; };
Struct(UI_Size) Struct(UI_Size)
@ -32,7 +32,7 @@ Struct(UI_Size)
Enum(UI_RoundKind) Enum(UI_RoundKind)
{ {
UI_RoundKind_Pixel, /* Exact radius */ UI_RoundKind_Pixel, /* Exact radius */
UI_RoundKind_Fill, /* Radius as percent of size */ UI_RoundKind_Grow, /* Radius as percent of size */
}; };
Struct(UI_Round) Struct(UI_Round)
@ -384,8 +384,8 @@ UI_Style UI_PopStyle(UI_StyleDesc desc);
#define UI_SIZE(_kind, _v, _s) (UI_Size) { .kind = (_kind), .v = (_v), .strictness = (_s) } #define UI_SIZE(_kind, _v, _s) (UI_Size) { .kind = (_kind), .v = (_v), .strictness = (_s) }
#define UI_PIX(_v, _s) UI_SIZE(UI_SizeKind_Pixel, (_v), (_s)) #define UI_PIX(_v, _s) UI_SIZE(UI_SizeKind_Pixel, (_v), (_s))
#define UI_FIT(_v, _s) UI_SIZE(UI_SizeKind_Fit, (_v), (_s)) #define UI_SHRINK(_v, _s) UI_SIZE(UI_SizeKind_Shrink, (_v), (_s))
#define UI_FILL(_v, _s) UI_SIZE(UI_SizeKind_Fill, (_v), (_s)) #define UI_GROW(_v, _s) UI_SIZE(UI_SizeKind_Grow, (_v), (_s))
#define UI_FNT(_v, _s) UI_SIZE(UI_SizeKind_Pixel, (f32)UI_PeekTop(FontSize) * (_v), (_s)) #define UI_FNT(_v, _s) UI_SIZE(UI_SizeKind_Pixel, (f32)UI_PeekTop(FontSize) * (_v), (_s))
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
@ -394,7 +394,7 @@ UI_Style UI_PopStyle(UI_StyleDesc desc);
#define UI_ROUND(_kind, _v) (UI_Round) { .kind = (_kind), .v = (_v)} #define UI_ROUND(_kind, _v) (UI_Round) { .kind = (_kind), .v = (_v)}
#define UI_RPIX(_v) UI_ROUND(UI_RoundKind_Pixel, (_v)) #define UI_RPIX(_v) UI_ROUND(UI_RoundKind_Pixel, (_v))
#define UI_RFILL(_v) UI_ROUND(UI_RoundKind_Fill, (_v)) #define UI_RGROW(_v) UI_ROUND(UI_RoundKind_Fill, (_v))
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
//~ Box //~ Box