From cf7cfd96a62b26321de970496670005cf411c94c Mon Sep 17 00:00:00 2001 From: Gabriel Schneider Date: Tue, 15 Sep 2026 17:36:32 -0300 Subject: Center GUI pane indicators using cached font ink bounds --- src/gui/font.c | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) (limited to 'src/gui/font.c') diff --git a/src/gui/font.c b/src/gui/font.c index 9fc5e039..5989dd4e 100644 --- a/src/gui/font.c +++ b/src/gui/font.c @@ -126,9 +126,9 @@ void ui_font_cell_metrics(UIFont *f, float px, int32_t *cell_w, int32_t *cell_h, *ascent = asc > 0 ? asc : 1; } -int ui_font_raster(UIFont *f, float px, int32_t cp, uint8_t *out, - int32_t stride, int32_t cell_w, int32_t cell_h, - int32_t ascent) { +static int raster(UIFont *f, float px, int32_t cp, uint8_t *out, + int32_t stride, int32_t cell_w, int32_t cell_h, + int32_t ascent, int centered) { if (!f || !out || stride < cell_w || cell_w <= 0 || cell_h <= 0) return 0; for (int y = 0; y < cell_h; y++) @@ -151,8 +151,10 @@ int ui_font_raster(UIFont *f, float px, int32_t cp, uint8_t *out, const int advance = ceil_26_6(glyph->advance.x); // Fallbacks may be proportional. Center their advance in the primary face's // fixed cell, exactly as Ghostty centers a narrower fallback face. - const int gx = glyph->bitmap_left + (cell_w - advance) / 2; - const int gy = ascent - glyph->bitmap_top; + const int gx = centered ? (cell_w - (int)bitmap->width) / 2 + : glyph->bitmap_left + (cell_w - advance) / 2; + const int gy = centered ? (cell_h - (int)bitmap->rows) / 2 + : ascent - glyph->bitmap_top; const int pitch = bitmap->pitch; const int row_bytes = pitch < 0 ? -pitch : pitch; @@ -184,3 +186,14 @@ int ui_font_raster(UIFont *f, float px, int32_t cp, uint8_t *out, } return 1; } + +int ui_font_raster(UIFont *f, float px, int32_t cp, uint8_t *out, + int32_t stride, int32_t cell_w, int32_t cell_h, + int32_t ascent) { + return raster(f, px, cp, out, stride, cell_w, cell_h, ascent, 0); +} + +int ui_font_raster_centered(UIFont *f, float px, int32_t cp, uint8_t *out, + int32_t stride, int32_t width, int32_t height) { + return raster(f, px, cp, out, stride, width, height, 0, 1); +} -- cgit v1.3