summaryrefslogtreecommitdiff
path: root/anim/src/array.zig
diff options
context:
space:
mode:
authorGabriel Schneider <[email protected]>2026-11-10 16:05:20 -0300
committerGabriel Schneider <[email protected]>2026-11-10 16:43:58 -0300
commit165bb6c1344b98de7bef1d3c2b72147b4a40797a (patch)
tree0e70e6222700063f604f78673f6ab3a5bfb9242d /anim/src/array.zig
parent66a2a7cf733f6abc1f79561c52d901ce67019fb1 (diff)
downloadcomputeranim-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/array.zig')
-rw-r--r--anim/src/array.zig94
1 files changed, 57 insertions, 37 deletions
diff --git a/anim/src/array.zig b/anim/src/array.zig
index 5d6b471..b4472e7 100644
--- a/anim/src/array.zig
+++ b/anim/src/array.zig
@@ -13,6 +13,10 @@ const ui = @import("ui.zig");
const cursors = @import("cursor.zig");
const Recording = @import("Recording.zig");
const objects = @import("objects.zig");
+const context = @import("context.zig");
+const hexdump = @import("hexdump.zig");
+const ties = @import("ties.zig");
+const Stage = @import("stage.zig").Stage;
const theme = ui.theme;
const time = theme.time;
const Rect = ui.Rect;
@@ -26,7 +30,7 @@ fn flightTime(units: f32) f32 {
pub const Array = struct {
cursor: cursors.Cursor,
- box: Rect,
+ stage: *const Stage,
/// The array's name in the program.
variable: []const u8,
/// Variables that index it, shown as tags in the cell they point at.
@@ -44,31 +48,42 @@ pub const Array = struct {
};
pub fn draw(g: *const Array, f: *sk.Frame, at: anim.Placed) void {
- const u: ui.Ui = .{ .f = f, .at = at };
+ const box = g.stage.box(at, .band);
+ if (box.h < theme.metric.context.tag + 24) return;
+ const u = context.at(f, at, box);
const now = g.cursor.now(at);
const rec = g.cursor.rec;
const moment = now.shown(.idea);
const v = rec.variable(f.scratch, moment, g.variable) orelse {
- _ = u.panel(g.box.w, g.box.h, g.variable, .{ .focus = g.focus });
+ _ = u.panel(box.w, box.h, g.variable, .{ .focus = g.focus });
return;
};
const kind = rec.typeOf(f.scratch, v.type);
- // Its declaration, and where it is: the address the context's pointers to it end in.
- const body = u.panel(g.box.w, g.box.h, g.variable, .{ .focus = g.focus, .note = u.print("{s} at \u{2026}{x:0>4}", .{ objects.declare(f.scratch, rec, v), v.addr & 0xffff }) });
+ // Its declaration in the tag, and in the right half its bytes.
+ _ = u.panel(box.w, box.h, objects.declare(f.scratch, rec, v), .{ .focus = g.focus });
+ const m = theme.metric.context;
+ const half = theme.layout.state.x - theme.layout.program.x;
// An array of numbers; anything else is read as 4-byte ones.
const elem: u64 = if (kind != null and kind.? == .array) kind.?.array.elem.size() orelse 4 else 4;
const signed = kind == null or kind.? != .array or kind.?.array.elem.* != .scalar or kind.?.array.elem.scalar.kind == .int;
const count: usize = @intCast(@min(v.size / elem, 32));
if (count == 0) return;
+ {
+ const first = v.addr & ~@as(u64, 15);
+ const rows_n = @min(theme.layout.rowsIn(box.h), (v.addr + v.size - first + 15) / 16);
+ u.text(.sans_medium, theme.size.sans.tag, half + 12, m.tag - 6, "its bytes", t.primary);
+ u.text(.sans, theme.size.sans.micro, half + 12 + u.width(.sans_medium, theme.size.sans.tag, "its bytes") + 12, m.tag - 6, u.print("{x} to {x}, an element a run", .{ v.addr, v.addr + v.size - 1 }), t.faint);
+ hexdump.draw(u, now, half, m.tag + m.pad, first, rows_n, .{ .array = .{ .addr = v.addr, .len = v.size, .elem = @intCast(elem) }, .region = context.ink(context.regionOf(moment, v.addr)) });
+ }
- const room = body.w - 2 * theme.metric.panel.pad_x;
- const hero = @as(f32, @floatFromInt(count)) * theme.metric.hero_cell[0] <= room;
- // Beside the context there is less room: the cells are as wide as fit.
- const compact = !hero and @as(f32, @floatFromInt(count)) * theme.metric.cell[0] > room;
- const cell: [2]f32 = if (hero) theme.metric.hero_cell else if (compact) .{ @floor(room / @as(f32, @floatFromInt(count))), theme.metric.cell[1] } else theme.metric.cell;
- const size: f32 = if (hero) theme.size.mono.hero else if (compact) theme.size.mono.data else theme.size.mono.value;
- const left = (body.w - @as(f32, @floatFromInt(count)) * cell[0]) / 2;
- const top = body.y + (body.h - cell[1]) / 2 - @as(f32, if (compact) 30 else 0);
+ // The cells, in the left half: a size up as the subject.
+ const subject = box.h >= theme.layout.split.subject.band.h - 1;
+ const compact = !subject;
+ const cell: [2]f32 = if (subject) .{ 96, 72 } else .{ 80, 44 };
+ const size: f32 = if (subject) theme.size.mono.flight else theme.size.mono.small;
+ const label: f32 = if (subject) theme.size.mono.small else theme.size.mono.context;
+ const left = (half - 32 - @as(f32, @floatFromInt(count)) * cell[0]) / 2;
+ const top = m.tag + @as(f32, if (subject) 44 else 16) + label * 1.2 + 4;
const walking = now.walking();
// What moved: a cell written with what another cell held, which this step read.
@@ -102,38 +117,42 @@ pub const Array = struct {
var heat = now.written(addr, elem, .idea, delay);
// The value on its way is the anticipation: no frame as well.
if (flown != null) heat.arm = 0;
- const ink = u.written(r, heat, theme.color.raised);
+ const ink = u.cellWritten(r, heat, theme.color.raised);
// Staging: the compare is seen (framed as read) before anything moves.
- if (now.wasRead(addr, elem) and now.writeAge(addr, elem) != 0) u.readMark(r, now.reading(.idea, 0));
- u.text(.mono, if (compact) theme.size.mono.context else theme.size.mono.small, r.x + @as(f32, if (compact) 6 else 14), r.y + @as(f32, if (compact) 24 else 34), u.print("{d}", .{i}), if (ink.face == .mono_bold) ink.ink else ui.rgb(t.faint));
+ if (now.wasRead(addr, elem) and now.writeAge(addr, elem) != 0) u.cellRead(r, now.reading(.idea, 0));
+ // Its index over it, where a node has its address: the projection lands there.
+ const index_text = u.print("{d}", .{i});
+ const ly = r.y - 4 - label * 1.2;
+ u.text(.mono, label, r.x + (r.w - @as(f32, @floatFromInt(index_text.len)) * label * 3 / 5) / 2, ly + label * 0.96, index_text, t.faint);
+ ties.anchor(u, .{ .node_address = addr }, .{ .x = r.x, .y = ly, .w = r.w, .h = label * 1.2 });
+ ties.anchor(u, .{ .node_part = addr }, r);
// Until its new value lands a cell keeps the old one, faint once
// the new is in the air: a copy does not erase.
const shown = if (pending) old[i] else values[i];
- const digits: Rect = .{ .x = r.x, .y = r.y + 18, .w = r.w, .h = r.h - 18 };
+ const digits = r;
const leaving = pending and flown != null and (!walking or now.since(.idea, delay) >= -(flightTime(cell[0]) + fl.lift));
if (shown) |n| u.label(ink.face, size, digits, .center, u.print("{d}", .{n}), if (leaving) ui.rgb(t.faint) else ink.ink) else u.unknown(digits);
}
- // Index variables: tags that slide from cell to cell as the idea strikes.
- for (g.indices, 0..) |name, nth| {
+ // Index variables: pins under the cell they index, sliding from
+ // cell to cell as the idea strikes; two in one cell share its pin.
+ var at_cell: [32]std.ArrayList([]const u8) = @splat(.empty);
+ var slide: [32]?f32 = @splat(null);
+ for (g.indices) |name| {
const iv = rec.variable(f.scratch, now.moment(), name) orelse continue;
const here = number(now.moment(), iv.addr, @min(iv.size, 8), true) orelse continue;
- var x = left + (@as(f32, @floatFromInt(here)) + 1) * cell[0];
- if (number(now.before(), iv.addr, @min(iv.size, 8), true)) |was| {
- x = std.math.lerp(left + (@as(f32, @floatFromInt(was)) + 1) * cell[0], x, cursors.standard(now.moving(.idea, 0, time.move)));
- }
if (here < 0 or here >= count) continue;
- // Under the tags of the indices before it that are in the same cell.
- var slot: f32 = 0;
- for (g.indices[0..nth]) |other| {
- const ov = rec.variable(f.scratch, moment, other) orelse continue;
- if (number(moment, ov.addr, @min(ov.size, 8), true) == here) slot += 1;
- }
- const w = u.width(.mono_bold, theme.size.mono.small, name) + 16;
- // In a narrow cell the tags hang under it, not in it.
- const tag: Rect = if (compact) .{ .x = x - cell[0] / 2 - w / 2, .y = top + cell[1] + 8 + slot * 38, .w = w, .h = 34 } else .{ .x = x - 2 - 10 - w, .y = top + 10 + slot * 38, .w = w, .h = 34 };
- u.fill(tag, t.ink);
- u.label(.mono_bold, theme.size.mono.small, tag, .center, name, t.primary);
+ const k: usize = @intCast(here);
+ at_cell[k].append(f.scratch, name) catch {};
+ if (number(now.before(), iv.addr, @min(iv.size, 8), true)) |was| if (was != here and was >= 0 and was < count) {
+ slide[k] = @floatFromInt(was);
+ };
+ }
+ for (at_cell, 0..) |names, k| {
+ if (names.items.len == 0) continue;
+ var x = left + (@as(f32, @floatFromInt(k)) + 0.5) * cell[0];
+ if (slide[k]) |was| x = std.math.lerp(left + (was + 0.5) * cell[0], x, cursors.standard(now.moving(.idea, 0, time.move)));
+ u.pinUnder(x, top + cell[1], names.items, t.primary, label);
}
// Values in flight, over everything: one over, the next under.
@@ -164,12 +183,13 @@ pub const Array = struct {
const way: f32 = if (k % 2 == 0) -1 else 1;
const c = sk.math.mix(from, to, eased) + ui.Vec{ 0, way * rise * @sin(std.math.pi * eased) };
const grown = std.math.lerp(1, fl.lift_scale, lifted);
- const w = (if (compact) cell[0] + 4 else @max(theme.metric.flight_card[0], cell[0] * 0.6)) * grown;
- const h = (if (compact) theme.metric.flight_card[1] - 8 else theme.metric.flight_card[1]) * grown;
+ const w = (cell[0] + 4) * grown;
+ const h = (cell[1] + 4) * grown;
const card: Rect = .{ .x = c[0] - w / 2, .y = c[1] - h / 2, .w = w, .h = h };
u.fill(card, theme.color.page);
u.frame(card, t.bright, theme.stroke.line);
- if (values[flight.to]) |n| u.label(.mono_bold, if (compact) theme.size.mono.value else theme.size.mono.flight, card, .center, u.print("{d}", .{n}), t.bright);
+ if (values[flight.to]) |n| u.label(.mono_bold, size, card, .center, u.print("{d}", .{n}), t.bright);
+ _ = compact;
}
}
};