mirror of
https://github.com/ghostty-org/ghostty.git
synced 2025-07-14 07:46:12 +03:00
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
This commit is contained in:
@ -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;
|
||||
|
Reference in New Issue
Block a user