diff options
Diffstat (limited to 'src/abi.zig')
| -rw-r--r-- | src/abi.zig | 17 |
1 files changed, 13 insertions, 4 deletions
diff --git a/src/abi.zig b/src/abi.zig index b30b7ae..327110d 100644 --- a/src/abi.zig +++ b/src/abi.zig @@ -57,6 +57,11 @@ pub const Color = extern struct { } }; +/// The face a text is set in: the Go family, bundled with the native host. +/// Mono is for data and code, sans for what is said about it. The web host +/// has one face, the page's `monospace`. +pub const Face = enum(u8) { mono, mono_bold, mono_italic, sans, sans_medium, sans_bold }; + /// How 2D drawing combines with what is already there (`Command.blend`). /// Both are fixed-function on both hosts and match: `alpha` is source /// over (canvas `source-over`, SDL `BLEND`), `add` adds the colour times @@ -341,8 +346,8 @@ pub const Command = union(enum) { /// The blend for the 2D commands after it (`rect`, `shape`, `image`; /// `text` and `clear` ignore it). Each frame starts with `alpha`. blend: BlendMode, - /// Fixed 8px cells, `scale` times larger. - text: struct { x: f32, y: f32, scale: f32, color: Color, bytes: []const u8 }, + /// One line from its top left corner; scale 1 is a 13 px font. + text: struct { x: f32, y: f32, scale: f32, color: Color, bytes: []const u8, face: Face = .mono }, clip: ?Rect, /// Logical canvas size; the host scales the window to fit. canvas: struct { w: u32, h: u32 }, @@ -583,7 +588,7 @@ pub const Host = struct { imageSize: *const fn (*anyopaque, Image) [2]u32, /// What `Command.text` gives the bytes at a scale: the width they /// advance and the height of their line, in canvas units. - textSize: *const fn (*anyopaque, f32, []const u8) [2]f32, + textSize: *const fn (*anyopaque, f32, []const u8, Face) [2]f32, /// `.none` if the file does not load. loadSound: *const fn (*anyopaque, []const u8) Audio, /// WAV, FLAC or Ogg Vorbis bytes in memory. Not cached. `.none` if @@ -637,7 +642,11 @@ pub const Host = struct { /// it is drawn, so a width is not a multiple of the scale: measure at /// the scale drawn. pub fn textSize(h: Host, scale: f32, bytes: []const u8) [2]f32 { - return h.vtable.textSize(h.ctx, scale, bytes); + return h.vtable.textSize(h.ctx, scale, bytes, .mono); + } + /// `textSize` for `f.textIn(face, ...)`. + pub fn textSizeIn(h: Host, face: Face, scale: f32, bytes: []const u8) [2]f32 { + return h.vtable.textSize(h.ctx, scale, bytes, face); } pub fn loadSound(h: Host, path: []const u8) Audio { return h.vtable.loadSound(h.ctx, path); |
