diff options
| author | Gabriel Schneider <[email protected]> | 2026-09-15 17:36:32 -0300 |
|---|---|---|
| committer | Gabriel Schneider <[email protected]> | 2026-09-15 17:43:13 -0300 |
| commit | cf7cfd96a62b26321de970496670005cf411c94c (patch) | |
| tree | fd3da24fb47b5d88cf2135874900a35397f7e1f9 /src/gui/font.c | |
| parent | e462d566f710e714e3b7176672e98fc82a6dea62 (diff) | |
| download | pardes-cf7cfd96a62b26321de970496670005cf411c94c.tar.gz pardes-cf7cfd96a62b26321de970496670005cf411c94c.zip | |
Center GUI pane indicators using cached font ink bounds
Diffstat (limited to 'src/gui/font.c')
| -rw-r--r-- | src/gui/font.c | 23 |
1 files changed, 18 insertions, 5 deletions
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); +} |
