diff options
Diffstat (limited to 'test')
| -rw-r--r-- | test/text.script | 6 | ||||
| -rw-r--r-- | test/text.zig | 9 |
2 files changed, 12 insertions, 3 deletions
diff --git a/test/text.script b/test/text.script index 5bea6f5..4381f94 100644 --- a/test/text.script +++ b/test/text.script @@ -5,3 +5,9 @@ expect-pixel .zig-cache/text/native.png 84 11 32 64 96 255 expect-pixel .zig-cache/text/native.png 84 24 32 64 96 255 expect-pixel .zig-cache/text/native.png 97 11 16 16 16 255 expect-pixel .zig-cache/text/native.png 84 27 16 16 16 255 +# Another face is another width: ten sans `i` at scale 2 advance 60 px +# where the mono (bold here, the line below) advances 160. +expect-pixel .zig-cache/text/native.png 66 198 32 64 96 255 +expect-pixel .zig-cache/text/native.png 80 185 16 16 16 255 +expect-pixel .zig-cache/text/native.png 168 236 32 64 96 255 +expect-pixel .zig-cache/text/native.png 180 222 16 16 16 255 diff --git a/test/text.zig b/test/text.zig index b570435..e47e788 100644 --- a/test/text.zig +++ b/test/text.zig @@ -5,11 +5,14 @@ const sk = @import("sketch"); pub const width = 640; pub const height = 360; -const lines = [_]struct { scale: f32, text: []const u8 }{ +const lines = [_]struct { scale: f32, text: []const u8, face: sk.Face = .mono }{ .{ .scale = 1, .text = "0123456789" }, .{ .scale = 1.5, .text = "mov rax, [rbp-0x18] ; 1.5" }, .{ .scale = 2.25, .text = "0x7ffed849acf0 i -> W" }, .{ .scale = 4, .text = "fn main() !void {}" }, + // The other faces: the sans is proportional, the bold mono is not. + .{ .scale = 2, .text = "iiiiiiiiii", .face = .sans }, + .{ .scale = 2, .text = "iiiiiiiiii", .face = .mono_bold }, }; pub fn draw(f: *sk.Frame) void { @@ -18,9 +21,9 @@ pub fn draw(f: *sk.Frame) void { const k = f.in.window_height / height; var y: f32 = 10 * k; for (lines) |line| { - const size = f.host.textSize(line.scale * k, line.text); + const size = f.host.textSizeIn(line.face, line.scale * k, line.text); f.fill(sk.Rect{ .x = 10 * k, .y = y, .w = size[0], .h = size[1] }, 0x204060); - f.text(10 * k, y, line.scale * k, line.text, 0xffffff); + f.textIn(line.face, 10 * k, y, line.scale * k, line.text, 0xffffff); y += size[1] + 6 * k; } } |
