From fee681ac78eb7438bb749bbff870d4255e32a551 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Sun, 27 Nov 2022 15:44:12 -0800 Subject: [PATCH] dashed underlines --- src/font/sprite.zig | 1 + src/font/sprite/Face.zig | 1 + src/font/sprite/underline.zig | 16 ++++++++++++++++ src/renderer/OpenGL.zig | 1 + 4 files changed, 19 insertions(+) diff --git a/src/font/sprite.zig b/src/font/sprite.zig index f5b232061..16c307554 100644 --- a/src/font/sprite.zig +++ b/src/font/sprite.zig @@ -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 diff --git a/src/font/sprite/Face.zig b/src/font/sprite/Face.zig index 829cecc09..60c356548 100644 --- a/src/font/sprite/Face.zig +++ b/src/font/sprite/Face.zig @@ -86,6 +86,7 @@ const Kind = enum { .underline, .underline_double, .underline_dotted, + .underline_dashed, => .underline, }, diff --git a/src/font/sprite/underline.zig b/src/font/sprite/underline.zig index 4ce2aad31..87c25a9d5 100644 --- a/src/font/sprite/underline.zig +++ b/src/font/sprite/underline.zig @@ -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" { diff --git a/src/renderer/OpenGL.zig b/src/renderer/OpenGL.zig index 35659490d..b83f746cb 100644 --- a/src/renderer/OpenGL.zig +++ b/src/renderer/OpenGL.zig @@ -1010,6 +1010,7 @@ pub fn updateCell( .single => .underline, .double => .underline_double, .dotted => .underline_dotted, + .dashed => .underline_dashed, else => .underline, };