summaryrefslogtreecommitdiff
path: root/anim/src/words.zig
diff options
context:
space:
mode:
Diffstat (limited to 'anim/src/words.zig')
-rw-r--r--anim/src/words.zig53
1 files changed, 53 insertions, 0 deletions
diff --git a/anim/src/words.zig b/anim/src/words.zig
index 6549dfb..9bec54c 100644
--- a/anim/src/words.zig
+++ b/anim/src/words.zig
@@ -110,6 +110,59 @@ pub const Caption = struct {
}
};
+/// A chapter's title (design/README.md, `chapter`, `title`): said, not
+/// carded, in the caption's place, one line of Go Medium 40, its numeral
+/// faint and its name bright (`II Registers`); it arrives rising as a
+/// caption does, over the picture it grows from.
+pub const Title = struct {
+ numeral: []const u8,
+ name: []const u8,
+ box: Rect = theme.canvas.caption,
+
+ pub fn draw(c: *const Title, f: *sk.Frame, at: anim.Placed) void {
+ const u = fixed(f, at, (1 - at.pose.opacity) * theme.time.caption_rise);
+ const size = theme.size.sans.caption;
+ const base = theme.canvas.caption_baseline[0];
+ u.text(.sans_medium, size, theme.canvas.margin_x, base, c.numeral, t.faint);
+ const x = theme.canvas.margin_x + u.width(.sans_medium, size, c.numeral) + 2 * u.width(.sans_medium, size, " ");
+ u.text(.sans_medium, size, x, base, c.name, t.bright);
+ }
+};
+
+/// The clock's label (design/README.md, `clock`): the chapter, Go 18,
+/// faint, ranged right 24 left of the clock's count (its widest, so that it
+/// stands still as the count grows), or alone at 1856 where there is no
+/// clock yet. `which` is the chapter (between two, their names
+/// crossfading); `docked` 0 alone, 1 beside the count (out over its first
+/// half, in over its second, with the clock: it is secondary, it only fades).
+pub const ChapterLabel = struct {
+ names: []const []const u8,
+ which: anim.Value,
+ docked: anim.Value,
+ /// The count at its widest, `moment 193 of 193`.
+ widest: []const u8,
+
+ pub fn draw(l: *const ChapterLabel, f: *sk.Frame, at: anim.Placed) void {
+ const u = fixed(f, at, 0);
+ const size = theme.size.sans.micro;
+ const base = theme.canvas.clock_y + 28;
+ const right = theme.canvas.stage.x + theme.canvas.stage.w;
+ const ends = [2]f32{ right, right - u.width(.mono, theme.size.mono.context, l.widest) - 24 };
+ const which = std.math.clamp(at.value(l.which), 0, @as(f32, @floatFromInt(l.names.len - 1)));
+ const lo: usize = @intFromFloat(@floor(which));
+ const hi = @min(lo + 1, l.names.len - 1);
+ const k = which - @floor(which);
+ const docked = std.math.clamp(at.value(l.docked), 0, 1);
+ for ([2]usize{ lo, hi }, [2]f32{ 1 - k, k }) |n, shows| {
+ if (shows <= 0) continue;
+ const name = l.names[n];
+ const w = u.width(.sans, size, name);
+ // Gone from where it stood alone before it comes beside the count: never over it.
+ for (ends, [2]f32{ std.math.clamp(1 - 2 * docked, 0, 1), std.math.clamp(2 * docked - 1, 0, 1) }) |end, here| if (here > 0) u.faded(shows * here).text(.sans, size, end - w, base, name, t.faint);
+ }
+ }
+};
+
/// Text with `code` between backticks set in mono, from `x` on `baseline`.
/// Returns where it ends.
pub fn runs(u: ui.Ui, x: f32, baseline: f32, text: []const u8, face: ui.Face, size: f32, mono_size: f32, ink: anytype) f32 {