dashed underlines

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

View File

@ -17,6 +17,7 @@ pub const Sprite = enum(u32) {
underline = start,
underline_double = start + 1,
underline_dotted = start + 2,
underline_dashed = start + 3,
// 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

@ -86,6 +86,7 @@ const Kind = enum {
.underline,
.underline_double,
.underline_dotted,
.underline_dashed,
=> .underline,
},

View File

@ -70,6 +70,7 @@ const Draw = struct {
.underline => self.drawSingle(canvas),
.underline_double => self.drawDouble(canvas),
.underline_dotted => self.drawDotted(canvas),
.underline_dashed => self.drawDashed(canvas),
}
}
@ -114,6 +115,21 @@ const Draw = struct {
}, .on);
}
}
/// Draw a dashed underline.
fn drawDashed(self: Draw, canvas: *font.sprite.Canvas) void {
const dash_width = self.width / 3 + 1;
const dash_count = (self.width / dash_width) + 1;
var i: u32 = 0;
while (i < dash_count) : (i += 2) {
canvas.rect(.{
.x = i * dash_width,
.y = self.pos,
.width = dash_width,
.height = self.thickness,
}, .on);
}
}
};
test "single" {

View File

@ -1010,6 +1010,7 @@ pub fn updateCell(
.single => .underline,
.double => .underline_double,
.dotted => .underline_dotted,
.dashed => .underline_dashed,
else => .underline,
};