summaryrefslogtreecommitdiff
path: root/test/text.zig
diff options
context:
space:
mode:
authorGabriel Schneider <[email protected]>2026-11-10 11:13:20 -0300
committerGabriel Schneider <[email protected]>2026-11-12 13:22:02 -0300
commit86ffca0024326110962f0880727f4eb84e6a48d1 (patch)
tree055f489341053c1db258606bb63b282bc7345a89 /test/text.zig
parenta62a6aa896adda901d335ef38814a13b8839545c (diff)
downloadsketchbook-86ffca0024326110962f0880727f4eb84e6a48d1.tar.gz
sketchbook-86ffca0024326110962f0880727f4eb84e6a48d1.zip
sketchbook: frames for ffmpeg (--export, on a clock of its own), text sizes, a font from the environment
Co-Authored-By: Claude Fable 5.2 <[email protected]>
Diffstat (limited to 'test/text.zig')
-rw-r--r--test/text.zig26
1 files changed, 26 insertions, 0 deletions
diff --git a/test/text.zig b/test/text.zig
new file mode 100644
index 0000000..b570435
--- /dev/null
+++ b/test/text.zig
@@ -0,0 +1,26 @@
+//! Text for layout: each line sits on a box of the size `textSize` gives
+//! it, at whole and fractional scales, the same picture at any canvas size.
+const sk = @import("sketch");
+
+pub const width = 640;
+pub const height = 360;
+
+const lines = [_]struct { scale: f32, text: []const u8 }{
+ .{ .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 {}" },
+};
+
+pub fn draw(f: *sk.Frame) void {
+ f.canvas(@intFromFloat(f.in.window_width), @intFromFloat(f.in.window_height));
+ f.clear(0x101010);
+ 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);
+ 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);
+ y += size[1] + 6 * k;
+ }
+}