From 143066093303adb890c438a562275042ad19350c Mon Sep 17 00:00:00 2001 From: Qwerasd Date: Tue, 8 Jul 2025 11:56:49 -0600 Subject: [PATCH] font: constrain width of two-cell icon-height icons This stops things like folder icons from becoming over-wide. The patcher typically makes these glyphs always 1 cell wide, but since we know how it will be displayed we have the benefit of being able to make it more than 1 cell when there's room. This makes our dynamic scaling *better* than a static patched font :D --- src/font/face.zig | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/src/font/face.zig b/src/font/face.zig index 8c1171fb4..dc36b0286 100644 --- a/src/font/face.zig +++ b/src/font/face.zig @@ -205,7 +205,7 @@ pub const RenderOptions = struct { ) GlyphSize { var g = glyph; - const available_width: f64 = @floatFromInt( + var available_width: f64 = @floatFromInt( metrics.cell_width * @min( self.max_constraint_width, constraint_width, @@ -216,6 +216,22 @@ pub const RenderOptions = struct { .icon => metrics.icon_height, }); + // We make the opinionated choice here to reduce the width + // of icon-height symbols by the same amount horizontally, + // since otherwise wide aspect ratio icons like folders end + // up far too wide. + // + // But we *only* do this if the constraint width is 2, since + // otherwise it would make them way too small when sized for + // a single cell. + const is_icon_width = self.height == .icon and @min(self.max_constraint_width, constraint_width) > 1; + const orig_avail_width = available_width; + if (is_icon_width) { + const cell_height: f64 = @floatFromInt(metrics.cell_height); + const ratio = available_height / cell_height; + available_width *= ratio; + } + const w = available_width - self.pad_left * available_width - self.pad_right * available_width; @@ -327,6 +343,11 @@ pub const RenderOptions = struct { .center => g.y = (h - g.height) / 2, } + // Add offset for icon width restriction, to keep it centered. + if (is_icon_width) { + g.x += (orig_avail_width - available_width) / 2; + } + // Re-add our padding before returning. g.x += self.pad_left * available_width; g.y += self.pad_bottom * available_height;