From ad56fafeffd346ed8c7a746bc8919e44a2cde333 Mon Sep 17 00:00:00 2001 From: jacob Date: Thu, 18 Dec 2025 22:16:35 -0600 Subject: [PATCH] round glyph advances --- src/pp/pp_sim/pp_sim_core.c | 16 ++++ src/pp/pp_sim/pp_sim_core.h | 1 + src/pp/pp_sim/pp_sim_tiles.cgh | 20 +++-- src/pp/pp_vis/pp_vis_core.c | 73 ++++++++++--------- src/pp/pp_vis/pp_vis_core.h | 2 + .../pp_vis_res/font/OpenSans-Regular.ttf | 3 - src/pp/pp_vis/pp_vis_res/font/roboto-med.ttf | 3 - src/pp/pp_vis/pp_vis_res/font/seguisb.ttf | 3 + src/ttf/ttf_dwrite/ttf_dwrite.c | 1 + 9 files changed, 74 insertions(+), 48 deletions(-) delete mode 100644 src/pp/pp_vis/pp_vis_res/font/OpenSans-Regular.ttf delete mode 100644 src/pp/pp_vis/pp_vis_res/font/roboto-med.ttf create mode 100644 src/pp/pp_vis/pp_vis_res/font/seguisb.ttf diff --git a/src/pp/pp_sim/pp_sim_core.c b/src/pp/pp_sim/pp_sim_core.c index 0b2ac391..3fe433a0 100644 --- a/src/pp/pp_sim/pp_sim_core.c +++ b/src/pp/pp_sim/pp_sim_core.c @@ -65,6 +65,22 @@ S_Key S_RandKey(void) //////////////////////////////////////////////////////////// //~ Tile helpers +String S_NameFromTileKind(S_TileKind kind) +{ + /* Tile names array */ + #define X(name, ...) [S_TileKind_##name] = CompLit(#name), + PERSIST Readonly String tile_names[] = { + S_TilesXMacro(X) + }; + #undef X + String result = Lit("Unknown"); + if (kind >= 0 && kind < countof(tile_names)) + { + result = tile_names[kind]; + } + return result; +} + Rng2I32 S_UpdateTilesInPlaceFromPlacement(u8 *tiles, S_TilePlacement placement) { Rng2I32 dirty_rect = Zi; diff --git a/src/pp/pp_sim/pp_sim_core.h b/src/pp/pp_sim/pp_sim_core.h index b7d35ecc..b5a436de 100644 --- a/src/pp/pp_sim/pp_sim_core.h +++ b/src/pp/pp_sim/pp_sim_core.h @@ -238,6 +238,7 @@ S_Key S_RandKey(void); //////////////////////////////////////////////////////////// //~ Tile helpers +String S_NameFromTileKind(S_TileKind kind); Rng2I32 S_UpdateTilesInPlaceFromPlacement(u8 *tiles, S_TilePlacement placement); //////////////////////////////////////////////////////////// diff --git a/src/pp/pp_sim/pp_sim_tiles.cgh b/src/pp/pp_sim/pp_sim_tiles.cgh index 6e84a218..30b9d848 100644 --- a/src/pp/pp_sim/pp_sim_tiles.cgh +++ b/src/pp/pp_sim/pp_sim_tiles.cgh @@ -3,12 +3,20 @@ #define S_WorldSize 128 -Enum(S_TileKind) -{ - S_TileKind_None, - S_TileKind_Floor, - S_TileKind_Wall, -}; +#define S_TilesXMacro(X) \ + X(Empty) \ + X(Floor) \ + X(Wall) \ +/* -------------------- */ + +/* Tiles enum */ +#define X(name, ...) S_TileKind_##name, + Enum(S_TileKind) + { + S_TilesXMacro(X) + S_TileKind_Count + }; +#undef X Enum(S_TilePlacementKind) { diff --git a/src/pp/pp_vis/pp_vis_core.c b/src/pp/pp_vis/pp_vis_core.c index 900d1a6e..526d946e 100644 --- a/src/pp/pp_vis/pp_vis_core.c +++ b/src/pp/pp_vis/pp_vis_core.c @@ -63,21 +63,8 @@ V_WidgetTheme V_GetWidgetTheme(void) // theme.font = GC_FontKeyFromResource(ResourceKeyFromStore(&V_Resources, Lit("font/fixedsys.ttf"))); // theme.font_size = 16; - // theme.font = GC_FontKeyFromResource(ResourceKeyFromStore(&V_Resources, Lit("font/fixedsys.ttf"))); - // theme.font_size = 64; - - // theme.font = GC_FontKeyFromResource(ResourceKeyFromStore(&V_Resources, Lit("font/OpenSans-Regular.ttf"))); - // theme.font_size = 18; - - // theme.font = GC_FontKeyFromResource(ResourceKeyFromStore(&V_Resources, Lit("font/roboto-med.ttf"))); - // theme.font_size = 18; - - // theme.font = GC_FontKeyFromResource(ResourceKeyFromStore(&V_Resources, Lit("font/SegoeUI.ttf"))); - // theme.font_size = 18; - - - theme.font = GC_FontKeyFromResource(ResourceKeyFromStore(&V_Resources, Lit("font/roboto-med.ttf"))); - theme.font_size = 100; + theme.font = GC_FontKeyFromResource(ResourceKeyFromStore(&V_Resources, Lit("font/seguisb.ttf"))); + theme.font_size = 16; theme.window_background_color = Rgb32(0xff1a1d1e); theme.window_border_color = Rgb32(0xff343a3b); @@ -87,8 +74,8 @@ V_WidgetTheme V_GetWidgetTheme(void) theme.divider_color = theme.window_border_color; theme.window_title_font_size = 16; - theme.text_padding_x = 3; - theme.text_padding_y = 3; + theme.text_padding_x = 5; + theme.text_padding_y = 5; return theme; } @@ -756,7 +743,7 @@ void V_TickForever(WaveLaneCtx *lane) else if (m2_held) { frame->is_selecting = 1; - frame->equipped_tile = S_TileKind_None; + frame->equipped_tile = S_TileKind_Empty; } if (frame->is_selecting && last_frame->is_selecting) @@ -809,6 +796,9 @@ void V_TickForever(WaveLaneCtx *lane) space->axis = Axis_X; V.root_space = space; + space->pref_size[Axis_X] = UI_GROW(1, 0); + space->pref_size[Axis_Y] = UI_GROW(1, 0); + { V_Panel *panel = PushStruct(perm, V_Panel); panel->space = space; @@ -847,20 +837,20 @@ void V_TickForever(WaveLaneCtx *lane) } } - { - V_Panel *panel = PushStruct(perm, V_Panel); - panel->space = space; - DllQueuePushNP(space->first_panel, space->last_panel, panel, next_in_space, prev_in_space); - ++space->panels_count; + // { + // V_Panel *panel = PushStruct(perm, V_Panel); + // panel->space = space; + // DllQueuePushNP(space->first_panel, space->last_panel, panel, next_in_space, prev_in_space); + // ++space->panels_count; - { - V_Window *window = PushStruct(perm, V_Window); - window->panel = panel; - // window->is_tile_window = 1; - DllQueuePushNP(panel->first_window, panel->last_window, window, next_in_panel, prev_in_panel); - ++panel->windows_count; - } - } + // { + // V_Window *window = PushStruct(perm, V_Window); + // window->panel = panel; + // // window->is_tile_window = 1; + // DllQueuePushNP(panel->first_window, panel->last_window, window, next_in_panel, prev_in_panel); + // ++panel->windows_count; + // } + // } } if (frame->is_editing) @@ -885,6 +875,8 @@ void V_TickForever(WaveLaneCtx *lane) } UI_Key space_key = UI_TransKey(); + UI_SetNext(Width, space->pref_size[Axis_X]); + UI_SetNext(Width, space->pref_size[Axis_Y]); if (space->axis == Axis_X) { UI_BuildRowEx(space_key); @@ -899,20 +891,24 @@ void V_TickForever(WaveLaneCtx *lane) for (V_Panel *panel = space->first_panel; panel; panel = panel->next_in_space) { // UI_SetNext(Width, UI_SHRINK(0, 1)); + UI_SetNext(Width, UI_GROW(1, 0)); + UI_SetNext(Height, UI_GROW(1, 0)); UI_PushCP(UI_BuildColumn()); { i64 active_window_idx = ClampI64(panel->active_window_idx, 0, MaxI64(panel->windows_count - 1, 0)); //- Build panel window tabs + f32 tab_spacing = 10; V_Window *active_window = 0; { - UI_SetNext(Width, UI_SHRINK(0, 1)); - UI_SetNext(Height, UI_SHRINK(0, 1)); + UI_SetNext(Width, UI_SHRINK(0, 0)); + UI_SetNext(Height, UI_SHRINK(0, 0)); UI_PushCP(UI_BuildRow()); i64 window_idx = 0; for (V_Window *window = panel->first_window; window; window = window->next_in_panel) { if (!window->is_viewport_window) { + UI_BuildSpacer(UI_PIX(tab_spacing, 0), Axis_X); if (window_idx == active_window_idx) { active_window = window; @@ -924,8 +920,9 @@ void V_TickForever(WaveLaneCtx *lane) } UI_SetNext(BackgroundColor, VEC4(0.2, 0.2, 0.2, 1)); UI_SetNext(Border, 1); - UI_SetNext(Width, UI_SHRINK(0, 1)); - UI_SetNext(Height, UI_SHRINK(0, 1)); + UI_SetNext(Width, UI_SHRINK(theme.text_padding_x, 0)); + UI_SetNext(Height, UI_SHRINK(theme.text_padding_y, 0)); + UI_SetNext(ChildAlignment, UI_Alignment_Center); UI_PushCP(UI_BuildRow()); { if (window->is_tile_window) @@ -960,7 +957,11 @@ void V_TickForever(WaveLaneCtx *lane) { if (window->is_tile_window) { - UI_BuildLabelF("Raaah"); + for (S_TileKind tile_kind = 0; tile_kind < S_TileKind_Count; ++tile_kind) + { + String name = S_NameFromTileKind(tile_kind); + UI_BuildLabel(name); + } } } UI_PopCP(UI_TopCP()); diff --git a/src/pp/pp_vis/pp_vis_core.h b/src/pp/pp_vis/pp_vis_core.h index bc956f07..2ab146c2 100644 --- a/src/pp/pp_vis/pp_vis_core.h +++ b/src/pp/pp_vis/pp_vis_core.h @@ -161,6 +161,8 @@ Struct(V_Space) struct V_Panel *first_panel; struct V_Panel *last_panel; + UI_Size pref_size[Axis_CountXY]; + Axis axis; }; diff --git a/src/pp/pp_vis/pp_vis_res/font/OpenSans-Regular.ttf b/src/pp/pp_vis/pp_vis_res/font/OpenSans-Regular.ttf deleted file mode 100644 index 1beddae5..00000000 --- a/src/pp/pp_vis/pp_vis_res/font/OpenSans-Regular.ttf +++ /dev/null @@ -1,3 +0,0 @@ -version https://git-lfs.github.com/spec/v1 -oid sha256:037236ed4bf58a85f67074c165d308260fd6be01c86d7df4e79ea16eb273f8c5 -size 96932 diff --git a/src/pp/pp_vis/pp_vis_res/font/roboto-med.ttf b/src/pp/pp_vis/pp_vis_res/font/roboto-med.ttf deleted file mode 100644 index 02435fc5..00000000 --- a/src/pp/pp_vis/pp_vis_res/font/roboto-med.ttf +++ /dev/null @@ -1,3 +0,0 @@ -version https://git-lfs.github.com/spec/v1 -oid sha256:8559132c89ad51d8a2ba5b171887a44a7ba93776e205f553573de228e64b45f8 -size 162588 diff --git a/src/pp/pp_vis/pp_vis_res/font/seguisb.ttf b/src/pp/pp_vis/pp_vis_res/font/seguisb.ttf new file mode 100644 index 00000000..37813437 --- /dev/null +++ b/src/pp/pp_vis/pp_vis_res/font/seguisb.ttf @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:8bc62d2bf64eb5e720c8df2b6a259189ea14a61627d8cc56f1ac9bc58aff16d2 +size 707492 diff --git a/src/ttf/ttf_dwrite/ttf_dwrite.c b/src/ttf/ttf_dwrite/ttf_dwrite.c index a972c60d..1d0bb781 100644 --- a/src/ttf/ttf_dwrite/ttf_dwrite.c +++ b/src/ttf/ttf_dwrite/ttf_dwrite.c @@ -243,6 +243,7 @@ TTF_GlyphResult TTF_RasterizeGlyphFromCodepoint(Arena *arena, u32 codepoint, Res hr = IDWriteFontFace_GetDesignGlyphMetrics(font->face, &glyph_idx, 1, &m, 0); } f32 advance = (f32)m.advanceWidth * pixels_per_design_unit; + advance = RoundF32(advance); /* Best-guess a position in the middle of the render target based on metrics */ Vec2I32 rt_baseline = Zi;