diff options
| author | Gabriel Schneider <[email protected]> | 2026-11-10 16:05:20 -0300 |
|---|---|---|
| committer | Gabriel Schneider <[email protected]> | 2026-11-10 16:43:58 -0300 |
| commit | 165bb6c1344b98de7bef1d3c2b72147b4a40797a (patch) | |
| tree | 0e70e6222700063f604f78673f6ab3a5bfb9242d /anim/src/stage.zig | |
| parent | 66a2a7cf733f6abc1f79561c52d901ce67019fb1 (diff) | |
| download | computeranim-165bb6c1344b98de7bef1d3c2b72147b4a40797a.tar.gz computeranim-165bb6c1344b98de7bef1d3c2b72147b4a40797a.zip | |
canim: the renderer speaks the design language
The blocks, their states and the tokens carry the catalogue's names:
atoms in ui, chain/reg/slot in rows, insn with its line column, jump lane
and annotations (read, write, taken or not, a call with its arguments, a
return, a syscall) in disasm, bytes and hexdump with field paper and the
reading column, the three splits and relayout in stage, the ties (thread,
link and pin, projection, echo). A lens is a band over the whole context,
its drawing left and its bytes right. Frames' spans on the stack, each
instruction's line and a callee's parameter count come from the tracer.
A gallery scene draws every block; the test compares six of its pages
with pictures kept in test/gallery, drawn from a recording kept there
too. The scenes are ported; the motion checks report no pop and no
metronome in any of them.
Co-Authored-By: Claude Fable 5.2 <[email protected]>
Diffstat (limited to 'anim/src/stage.zig')
| -rw-r--r-- | anim/src/stage.zig | 84 |
1 files changed, 84 insertions, 0 deletions
diff --git a/anim/src/stage.zig b/anim/src/stage.zig new file mode 100644 index 0000000..31a149a --- /dev/null +++ b/anim/src/stage.zig @@ -0,0 +1,84 @@ +//! The `stage` (design/README.md, "5. The frame"): where every panel is, +//! by the scene's split, and `relayout`, the one move of the layout: a +//! change of split, 48 f on `glide`, with nothing else moving under it. +//! Every panel of the context reads its box here each frame, so a +//! relayout moves them all together. +const std = @import("std"); +const anim = @import("anim"); +const ui = @import("ui.zig"); +const theme = ui.theme; +const Split = theme.layout.Split; +const Rect = theme.Rect; + +pub const Part = enum { band, source, disasm, registers, stack, backtrace }; + +pub const Stage = struct { + first: Split, + moves: [8]Move = undefined, + count: usize = 0, + + const Move = struct { from: Split, to: Split, p: anim.Value }; + + /// A stage at `split`, made where a scene's components can keep a pointer to it. + pub fn init(s: *anim.Frame, split: Split) *Stage { + return s.new(Stage{ .first = split }); + } + + /// The split the stage ends in, after every move so far. + pub fn last(st: *const Stage) Split { + return if (st.count == 0) st.first else st.moves[st.count - 1].to; + } + + /// A change of split: every panel glides to its place in `to`. + pub fn relayout(st: *Stage, s: *anim.Frame, to: Split) void { + const p = s.value(0); + st.moves[st.count] = .{ .from = st.last(), .to = to, .p = p }; + st.count += 1; + s.play(.{p.to(1)}, .{ .seconds = theme.time.relayout, .ease = anim.ease.linear }); + } + + /// The split as it stands at this instant. + pub fn now(st: *const Stage, at: anim.Placed) Split { + var split = st.first; + for (st.moves[0..st.count]) |m| { + const p = at.value(m.p); + if (p <= 0) continue; + split = between(m.from, m.to, theme.ease(.glide, p)); + } + return split; + } + + /// Whether a relayout is under way: nothing else moves under it. + pub fn moving(st: *const Stage, at: anim.Placed) bool { + for (st.moves[0..st.count]) |m| { + const p = at.value(m.p); + if (p > 0 and p < 1) return true; + } + return false; + } + + pub fn box(st: *const Stage, at: anim.Placed, part: Part) Rect { + const split = st.now(at); + return switch (part) { + inline else => |tag| @field(split, @tagName(tag)), + }; + } +}; + +fn between(a: Split, b: Split, p: f32) Split { + var out = b; + inline for (.{ "band", "source", "disasm", "registers", "stack", "backtrace" }) |name| { + const x = @field(a, name); + const y = @field(b, name); + @field(out, name) = .{ .x = std.math.lerp(x.x, y.x, p), .y = std.math.lerp(x.y, y.y, p), .w = std.math.lerp(x.w, y.w, p), .h = std.math.lerp(x.h, y.h, p) }; + } + out.dump_rows = if (p < 0.5) a.dump_rows else b.dump_rows; + return out; +} + +test "a relayout passes through the splits it joins" { + const sp = theme.layout.split; + const half = between(sp.beside, sp.subject, 0.5); + try std.testing.expectEqual(@as(f32, 200), half.band.h); + try std.testing.expectEqual(sp.subject.stack, between(sp.beside, sp.subject, 1).stack); +} |
