diff options
Diffstat (limited to 'src/sketch/web.zig')
| -rw-r--r-- | src/sketch/web.zig | 6 |
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 { |
