summaryrefslogtreecommitdiff
path: root/src/sketch/web.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 /src/sketch/web.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 'src/sketch/web.zig')
-rw-r--r--src/sketch/web.zig6
1 files changed, 6 insertions, 0 deletions
diff --git a/src/sketch/web.zig b/src/sketch/web.zig
index 27313a6..4445e8d 100644
--- a/src/sketch/web.zig
+++ b/src/sketch/web.zig
@@ -395,6 +395,7 @@ fn Driver(comptime App: type) type {
.newBuffer = newBuffer,
.freeBuffer = freeBuffer,
.imageSize = imageSize,
+ .textSize = textSize,
.loadSound = loadSound,
.decodeSound = unsupportedSound,
.samples = samples,
@@ -429,6 +430,11 @@ fn Driver(comptime App: type) type {
fn imageSize(_: *anyopaque, img: abi.Image) [2]u32 {
return .{ js.imageWidth(@backingInt(img)), js.imageHeight(@backingInt(img)) };
}
+ /// As host.js draws text: 8 px a character and a 16 px line at scale 1.
+ fn textSize(_: *anyopaque, scale: f32, bytes: []const u8) [2]f32 {
+ const count = std.unicode.utf8CountCodepoints(bytes) catch bytes.len;
+ return .{ @as(f32, @floatFromInt(count)) * 8 * scale, 16 * scale };
+ }
/// Only sounds the page has decoded (opened or dropped files): the
/// browser decodes asynchronously, so there is no reading on demand.
fn loadSound(_: *anyopaque, name: []const u8) abi.Audio {