mirror of
https://github.com/ghostty-org/ghostty.git
synced 2025-07-19 18:26:13 +03:00
Decouple icon width from adjust-cell-{height,width}
This commit is contained in:
@ -38,6 +38,9 @@ cursor_height: u32,
|
|||||||
/// The constraint height for nerd fonts icons.
|
/// The constraint height for nerd fonts icons.
|
||||||
icon_height: u32,
|
icon_height: u32,
|
||||||
|
|
||||||
|
/// The constraint width for nerd fonts icons.
|
||||||
|
icon_width: u32,
|
||||||
|
|
||||||
/// Minimum acceptable values for some fields to prevent modifiers
|
/// Minimum acceptable values for some fields to prevent modifiers
|
||||||
/// from being able to, for example, cause 0-thickness underlines.
|
/// from being able to, for example, cause 0-thickness underlines.
|
||||||
const Minimums = struct {
|
const Minimums = struct {
|
||||||
@ -50,6 +53,7 @@ const Minimums = struct {
|
|||||||
const cursor_thickness = 1;
|
const cursor_thickness = 1;
|
||||||
const cursor_height = 1;
|
const cursor_height = 1;
|
||||||
const icon_height = 1;
|
const icon_height = 1;
|
||||||
|
const icon_width = 1;
|
||||||
};
|
};
|
||||||
|
|
||||||
/// Metrics extracted from a font face, based on
|
/// Metrics extracted from a font face, based on
|
||||||
@ -188,6 +192,19 @@ pub fn calc(face: FaceMetrics) Metrics {
|
|||||||
// We do cap it at `cell_height` though for obvious reasons.
|
// We do cap it at `cell_height` though for obvious reasons.
|
||||||
const icon_height = @min(cell_height, cap_height * 1.2);
|
const icon_height = @min(cell_height, cap_height * 1.2);
|
||||||
|
|
||||||
|
// We set icon_width using the icon_height / cell_height
|
||||||
|
// ratio, such that
|
||||||
|
// icon_width / (2 * cell_width) == icon_height / cell_height
|
||||||
|
// This only applies when the constraint width is two cells;
|
||||||
|
// icons constrained to a single cell can take up the full
|
||||||
|
// cell width.
|
||||||
|
//
|
||||||
|
// It's important that the icon_width is calculated here using
|
||||||
|
// the cell_width and cell_height derived from the face, and
|
||||||
|
// not in Constraint.constrain, which is called after the
|
||||||
|
// adjust-cell-{width,height} modifiers have been applied.
|
||||||
|
const icon_width = 2 * cell_width * icon_height / cell_height;
|
||||||
|
|
||||||
var result: Metrics = .{
|
var result: Metrics = .{
|
||||||
.cell_width = @intFromFloat(cell_width),
|
.cell_width = @intFromFloat(cell_width),
|
||||||
.cell_height = @intFromFloat(cell_height),
|
.cell_height = @intFromFloat(cell_height),
|
||||||
@ -201,6 +218,7 @@ pub fn calc(face: FaceMetrics) Metrics {
|
|||||||
.box_thickness = @intFromFloat(underline_thickness),
|
.box_thickness = @intFromFloat(underline_thickness),
|
||||||
.cursor_height = @intFromFloat(cell_height),
|
.cursor_height = @intFromFloat(cell_height),
|
||||||
.icon_height = @intFromFloat(icon_height),
|
.icon_height = @intFromFloat(icon_height),
|
||||||
|
.icon_width = @intFromFloat(icon_width),
|
||||||
};
|
};
|
||||||
|
|
||||||
// Ensure all metrics are within their allowable range.
|
// Ensure all metrics are within their allowable range.
|
||||||
@ -440,6 +458,7 @@ fn init() Metrics {
|
|||||||
.box_thickness = 0,
|
.box_thickness = 0,
|
||||||
.cursor_height = 0,
|
.cursor_height = 0,
|
||||||
.icon_height = 0,
|
.icon_height = 0,
|
||||||
|
.icon_width = 0,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -233,20 +233,13 @@ pub const RenderOptions = struct {
|
|||||||
.icon => metrics.icon_height,
|
.icon => metrics.icon_height,
|
||||||
});
|
});
|
||||||
|
|
||||||
// We make the opinionated choice here to reduce the width
|
// We use icon_width only for icon-height symbols with
|
||||||
// of icon-height symbols by the same amount horizontally,
|
// constraint width 2. When the constraint width is 1,
|
||||||
// since otherwise wide aspect ratio icons like folders end
|
// icons can take the up full cell width.
|
||||||
// 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 is_icon_width = self.height == .icon and @min(self.max_constraint_width, constraint_width) > 1;
|
||||||
const orig_avail_width = available_width;
|
const orig_avail_width = available_width;
|
||||||
if (is_icon_width) {
|
if (is_icon_width) {
|
||||||
const cell_height: f64 = @floatFromInt(metrics.cell_height);
|
available_width = @floatFromInt(metrics.icon_width);
|
||||||
const ratio = available_height / cell_height;
|
|
||||||
available_width *= ratio;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const w = available_width -
|
const w = available_width -
|
||||||
|
Reference in New Issue
Block a user