From bb322b64caf171bcee7a9a0049d9ae6952919372 Mon Sep 17 00:00:00 2001 From: jacob Date: Fri, 7 Nov 2025 19:40:47 -0600 Subject: [PATCH] add padding parameter to ui_fit --- src/proto/pp_widgets.c | 20 ++++++++++++++------ src/proto/pp_widgets.h | 3 +++ src/ui/ui_common.c | 5 +++-- src/ui/ui_core.c | 4 ++-- src/ui/ui_core.h | 4 ++-- 5 files changed, 24 insertions(+), 12 deletions(-) diff --git a/src/proto/pp_widgets.c b/src/proto/pp_widgets.c index b79250f8..06856cdf 100644 --- a/src/proto/pp_widgets.c +++ b/src/proto/pp_widgets.c @@ -11,8 +11,12 @@ PP_WidgetTheme PP_GetWidgetTheme(void) theme.window_width = 300; theme.window_padding = theme.window_border - 1; theme.divider_color = theme.window_border_color; + theme.font_size = 16; theme.window_title_font_size = 16; + theme.text_padding_x = 3; + theme.text_padding_y = 3; + return theme; } @@ -75,7 +79,7 @@ void PP_EndCommandsWidget(PP_CommandsWidget *widget) // UI_Push(Rounding, UI_RPIX(15)); UI_Push(Rounding, UI_RPIX(15)); UI_Push(Width, UI_PIX(theme.window_width, 0)); - UI_Push(Height, UI_FIT(0)); + UI_Push(Height, UI_FIT(0, 0)); UI_Push(ChildLayoutAxis, Axis_Y); UI_Push(FloatingPos, widget->pos); UI_SetNext(Flags, UI_BoxFlag_Floating); @@ -102,7 +106,7 @@ void PP_EndCommandsWidget(PP_CommandsWidget *widget) /* Title box */ UI_SetNext(FontSize, theme.window_title_font_size); UI_SetNext(ChildAlignment, UI_Alignment_Center); - UI_SetNext(Width, UI_FIT(1)); + UI_SetNext(Width, UI_FIT(0, 1)); UI_SetNext(Text, Lit("Commands")); UI_SetNext(Flags, UI_BoxFlag_DrawText); UI_BuildBox(UI_NilKey); @@ -171,8 +175,12 @@ void PP_EndCommandsWidget(PP_CommandsWidget *widget) /* Command hotkey button */ UI_SetNext(Text, UI_StringF("Test")); - UI_SetNext(Width, UI_FIT(1)); + UI_SetNext(Width, UI_FIT(theme.text_padding_x, 1)); + UI_SetNext(Height, UI_FIT(theme.text_padding_y, 1)); UI_SetNext(Rounding, UI_RPIX(0)); + UI_SetNext(Border, 1); + UI_SetNext(BackgroundColor, 0); + UI_SetNext(ChildAlignment, UI_Alignment_Center); UI_SetNext(Flags, UI_BoxFlag_DrawText | UI_BoxFlag_Interactable); UI_PushCP(UI_BuildRow(UI_NilKey)); { @@ -245,13 +253,13 @@ UI_Box *PP_BuildConsoleWidget(b32 minimized) { UI_SetNext(BackgroundColor, 0); UI_SetNext(Width, UI_PIX(500, 0)); - UI_SetNext(Height, UI_FIT(1)); + UI_SetNext(Height, UI_FIT(0, 1)); } else { UI_SetNext(BackgroundColor, Rgba(1, 1, 1, 0.02)); UI_SetNext(Width, UI_FILL(1, 0)); - UI_SetNext(Height, UI_FIT(1)); + UI_SetNext(Height, UI_FIT(0, 1)); } console_box = UI_BuildColumn(UI_KeyF("Console box")); UI_PushCP(console_box); @@ -325,7 +333,7 @@ UI_Box *PP_BuildConsoleWidget(b32 minimized) UI_Push(Border, 0); UI_Push(Text, text); UI_Push(Width, UI_FILL(1, 0)); - UI_Push(Height, UI_FIT(1)); + UI_Push(Height, UI_FIT(0, 1)); UI_Push(Flags, UI_BoxFlag_DrawText); UI_BuildBox(UI_NilKey); } diff --git a/src/proto/pp_widgets.h b/src/proto/pp_widgets.h index c9c43a0d..bc6a5e2f 100644 --- a/src/proto/pp_widgets.h +++ b/src/proto/pp_widgets.h @@ -13,6 +13,9 @@ Struct(PP_WidgetTheme) f32 window_border; f32 window_padding; f32 window_width; + + f32 text_padding_x; + f32 text_padding_y; }; //////////////////////////////////////////////////////////// diff --git a/src/ui/ui_common.c b/src/ui/ui_common.c index 34e8b058..616c81d0 100644 --- a/src/ui/ui_common.c +++ b/src/ui/ui_common.c @@ -1,5 +1,6 @@ //////////////////////////////////////////////////////////// //~ Label helpers + UI_Box *UI_BuildLabel(String text) { UI_Box *parent = UI_UseTop(Parent); @@ -15,8 +16,8 @@ UI_Box *UI_BuildLabel(String text) UI_SetNext(Tint, tint); UI_SetNext(Font, font); UI_SetNext(FontSize, font_size); - UI_SetNext(Width, UI_FIT(1)); - UI_SetNext(Height, UI_FIT(1)); + UI_SetNext(Width, UI_FIT(0, 1)); + UI_SetNext(Height, UI_FIT(0, 1)); UI_SetNext(Text, text); UI_SetNext(Flags, UI_BoxFlag_DrawText); box = UI_BuildBox(UI_NilKey); diff --git a/src/ui/ui_core.c b/src/ui/ui_core.c index 1a6bd13e..fd63370b 100644 --- a/src/ui/ui_core.c +++ b/src/ui/ui_core.c @@ -801,7 +801,7 @@ i64 UI_EndFrame(UI_Frame frame) text_size = box->font->ascent + box->font->descent; } } - box->solved_dims[axis] = text_size; + box->solved_dims[axis] = text_size + (pref_size.v * 2); } } } @@ -857,7 +857,7 @@ i64 UI_EndFrame(UI_Frame frame) } } } - box->solved_dims[axis] = accum; + box->solved_dims[axis] = accum + (pref_size.v * 2); } } } diff --git a/src/ui/ui_core.h b/src/ui/ui_core.h index 843e923b..f5ef5258 100644 --- a/src/ui/ui_core.h +++ b/src/ui/ui_core.h @@ -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_PIX(_v, _s) UI_SIZE(UI_SizeKind_Pixel, (_v), (_s)) -#define UI_FIT(_s) UI_SIZE(UI_SizeKind_Fit, 0, (_s)) -#define UI_FILL(_v, _s) UI_SIZE(UI_SizeKind_Fill, (_v), (_s)) +#define UI_FIT(_v, _s) UI_SIZE(UI_SizeKind_Fit, (_v), (_s)) +#define UI_FILL(_v, _s) UI_SIZE(UI_SizeKind_Fill, (_v), (_s)) #define UI_FNT(_v, _s) UI_SIZE(UI_SizeKind_Pixel, (f32)UI_PeekTop(FontSize) * (_v), (_s)) ////////////////////////////////////////////////////////////