font: render dotted underlines

This commit is contained in:
Mitchell Hashimoto
2022-11-27 15:39:18 -08:00
parent c2d08c3071
commit 6a32a30a16
4 changed files with 19 additions and 0 deletions

View File

@ -16,6 +16,7 @@ pub const Sprite = enum(u32) {
underline = start,
underline_double = start + 1,
underline_dotted = start + 2,
// Note: we don't currently put the box drawing glyphs in here because
// there are a LOT and I'm lazy. What I want to do is spend more time

View File

@ -85,6 +85,7 @@ const Kind = enum {
Sprite.start...Sprite.end => switch (@intToEnum(Sprite, cp)) {
.underline,
.underline_double,
.underline_dotted,
=> .underline,
},

View File

@ -69,6 +69,7 @@ const Draw = struct {
switch (sprite) {
.underline => self.drawSingle(canvas),
.underline_double => self.drawDouble(canvas),
.underline_dotted => self.drawDotted(canvas),
}
}
@ -98,6 +99,21 @@ const Draw = struct {
.height = self.thickness,
}, .on);
}
/// Draw a dotted underline.
fn drawDotted(self: Draw, canvas: *font.sprite.Canvas) void {
const dot_width = @max(self.thickness, 3);
const dot_count = self.width / dot_width;
var i: u32 = 0;
while (i < dot_count) : (i += 2) {
canvas.rect(.{
.x = i * dot_width,
.y = self.pos,
.width = dot_width,
.height = self.thickness,
}, .on);
}
}
};
test "single" {

View File

@ -1009,6 +1009,7 @@ pub fn updateCell(
.none => unreachable,
.single => .underline,
.double => .underline_double,
.dotted => .underline_dotted,
else => .underline,
};