summaryrefslogtreecommitdiff
path: root/test/text.zig
diff options
context:
space:
mode:
authorGabriel Schneider <[email protected]>2026-11-10 12:53:22 -0300
committerGabriel Schneider <[email protected]>2026-11-12 13:22:02 -0300
commit45f705a5e590c3dfddc0a544e66beb9bf6205a4d (patch)
treec98d19a1b2dfc4808a46b41cf1b931703ff467b1 /test/text.zig
parentf8d3a32f4f995eeb7e162b0702998b0565c11e4e (diff)
downloadsketchbook-45f705a5e590c3dfddc0a544e66beb9bf6205a4d.tar.gz
sketchbook-45f705a5e590c3dfddc0a544e66beb9bf6205a4d.zip
sketchbook: text rasterized at one scale and drawn at another (f.textScaled), steady under a moving camera
Diffstat (limited to 'test/text.zig')
-rw-r--r--test/text.zig13
1 files changed, 10 insertions, 3 deletions
diff --git a/test/text.zig b/test/text.zig
index e47e788..74bbaed 100644
--- a/test/text.zig
+++ b/test/text.zig
@@ -5,7 +5,7 @@ const sk = @import("sketch");
pub const width = 640;
pub const height = 360;
-const lines = [_]struct { scale: f32, text: []const u8, face: sk.Face = .mono }{
+const lines = [_]struct { scale: f32, text: []const u8, face: sk.Face = .mono, raster: f32 = 0 }{
.{ .scale = 1, .text = "0123456789" },
.{ .scale = 1.5, .text = "mov rax, [rbp-0x18] ; 1.5" },
.{ .scale = 2.25, .text = "0x7ffed849acf0 i -> W" },
@@ -13,6 +13,9 @@ const lines = [_]struct { scale: f32, text: []const u8, face: sk.Face = .mono }{
// 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 },
+ // Rasterized at 3 and drawn at 1.5: half of what scale 3 covers (115 px
+ // for ten digits), not what scale 1.5 would shape (120).
+ .{ .scale = 1.5, .text = "0123456789", .raster = 3 },
};
pub fn draw(f: *sk.Frame) void {
@@ -21,9 +24,13 @@ 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.textSizeIn(line.face, line.scale * k, line.text);
+ var size = f.host.textSizeIn(line.face, line.scale * k, line.text);
+ if (line.raster > 0) {
+ const at = f.host.textSizeIn(line.face, line.raster * k, line.text);
+ size = .{ at[0] * line.scale / line.raster, at[1] * line.scale / line.raster };
+ }
f.fill(sk.Rect{ .x = 10 * k, .y = y, .w = size[0], .h = size[1] }, 0x204060);
- f.textIn(line.face, 10 * k, y, line.scale * k, line.text, 0xffffff);
+ if (line.raster > 0) f.textScaled(line.face, 10 * k, y, line.scale * k, line.raster * k, line.text, 0xffffff) else f.textIn(line.face, 10 * k, y, line.scale * k, line.text, 0xffffff);
y += size[1] + 6 * k;
}
}