diff options
Diffstat (limited to 'src/sketch')
| -rw-r--r-- | src/sketch/root.zig | 6 | ||||
| -rw-r--r-- | src/sketch/web.zig | 2 |
2 files changed, 7 insertions, 1 deletions
diff --git a/src/sketch/root.zig b/src/sketch/root.zig index 33c9ba7..01aa977 100644 --- a/src/sketch/root.zig +++ b/src/sketch/root.zig @@ -57,6 +57,7 @@ pub const Buffer = abi.Buffer; pub const Cursor = abi.Cursor; pub const Voice = abi.Voice; pub const BlendMode = abi.BlendMode; +pub const Face = abi.Face; /// What `draw` receives: input, host services, memory by lifetime and the /// command list. Commands may be built from anything: the methods copy what @@ -146,6 +147,11 @@ pub const Frame = struct { pub fn text(f: *Frame, x: f32, y: f32, scale: f32, bytes: []const u8, color: anytype) void { f.emit(.{ .text = .{ .x = x, .y = y, .scale = scale, .color = paint(color), .bytes = f.keep(u8, bytes) } }); } + /// `text` in another face of the built-in family: bold or italic mono, + /// or the sans (`host.textSizeIn` measures it). + pub fn textIn(f: *Frame, face: Face, x: f32, y: f32, scale: f32, bytes: []const u8, color: anytype) void { + f.emit(.{ .text = .{ .x = x, .y = y, .scale = scale, .color = paint(color), .bytes = f.keep(u8, bytes), .face = face } }); + } pub fn print(f: *Frame, x: f32, y: f32, scale: f32, color: anytype, comptime fmt: []const u8, args: anytype) void { f.emit(.{ .text = .{ .x = x, .y = y, .scale = scale, .color = paint(color), .bytes = f.format(fmt, args) } }); } diff --git a/src/sketch/web.zig b/src/sketch/web.zig index 4445e8d..db9d9a8 100644 --- a/src/sketch/web.zig +++ b/src/sketch/web.zig @@ -431,7 +431,7 @@ fn Driver(comptime App: type) type { 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 { + fn textSize(_: *anyopaque, scale: f32, bytes: []const u8, _: abi.Face) [2]f32 { const count = std.unicode.utf8CountCodepoints(bytes) catch bytes.len; return .{ @as(f32, @floatFromInt(count)) * 8 * scale, 16 * scale }; } |
