config: add remaining font modifiers

This commit is contained in:
Mitchell Hashimoto
2023-10-04 22:08:19 -07:00
parent 16cfb14200
commit b98cc3d79f
6 changed files with 26 additions and 4 deletions

View File

@ -231,6 +231,10 @@ pub fn init(
if (config.@"adjust-cell-width") |m| try set.put(alloc, .cell_width, m);
if (config.@"adjust-cell-height") |m| try set.put(alloc, .cell_height, m);
if (config.@"adjust-font-baseline") |m| try set.put(alloc, .cell_baseline, m);
if (config.@"adjust-underline-position") |m| try set.put(alloc, .underline_position, m);
if (config.@"adjust-underline-thickness") |m| try set.put(alloc, .underline_thickness, m);
if (config.@"adjust-strikethrough-position") |m| try set.put(alloc, .strikethrough_position, m);
if (config.@"adjust-strikethrough-thickness") |m| try set.put(alloc, .strikethrough_thickness, m);
break :set set;
};

View File

@ -138,6 +138,10 @@ const c = @cImport({
@"adjust-cell-width": ?MetricModifier = null,
@"adjust-cell-height": ?MetricModifier = null,
@"adjust-font-baseline": ?MetricModifier = null,
@"adjust-underline-position": ?MetricModifier = null,
@"adjust-underline-thickness": ?MetricModifier = null,
@"adjust-strikethrough-position": ?MetricModifier = null,
@"adjust-strikethrough-thickness": ?MetricModifier = null,
/// Background color for the window.
background: Color = .{ .r = 0x28, .g = 0x2C, .b = 0x34 },

View File

@ -26,6 +26,18 @@ pub fn apply(self: *Metrics, mods: ModifierSet) void {
var it = mods.iterator();
while (it.next()) |entry| {
switch (entry.key_ptr.*) {
// We clamp these values to a minimum of 1 to prevent divide-by-zero
// in downstream operations.
inline .cell_width,
.cell_height,
=> |tag| {
const original = @field(self, @tagName(tag));
@field(self, @tagName(tag)) = @max(
entry.value_ptr.apply(original),
1,
);
},
inline else => |tag| {
@field(self, @tagName(tag)) = entry.value_ptr.apply(@field(self, @tagName(tag)));
},

View File

@ -171,8 +171,9 @@ const Draw = struct {
// wave. This constant is arbitrary, change it for aesthetics.
const pos = pos: {
const MIN_HEIGHT = 7;
const height = y_max - self.pos;
break :pos if (height < MIN_HEIGHT) self.pos -| MIN_HEIGHT else self.pos;
const clamped_pos = @min(y_max, self.pos);
const height = y_max - clamped_pos;
break :pos if (height < MIN_HEIGHT) clamped_pos -| MIN_HEIGHT else clamped_pos;
};
// The full heightof the wave can be from the bottom to the

View File

@ -211,7 +211,8 @@ pub fn init(alloc: Allocator, options: renderer.Options) !Metal {
options.font_group.group.sprite = font.sprite.Face{
.width = metrics.cell_width,
.height = metrics.cell_height,
.thickness = 2 * @as(u32, if (options.config.font_thicken) 2 else 1),
.thickness = metrics.underline_thickness *
@as(u32, if (options.config.font_thicken) 2 else 1),
.underline_position = metrics.underline_position,
};

View File

@ -548,7 +548,7 @@ fn resetFontMetrics(
font_group.group.sprite = font.sprite.Face{
.width = metrics.cell_width,
.height = metrics.cell_height,
.thickness = 2 * @as(u32, if (font_thicken) 2 else 1),
.thickness = metrics.underline_thickness * @as(u32, if (font_thicken) 2 else 1),
.underline_position = metrics.underline_position,
};