//! `nodes`, a lens (design/README.md, "3. Panels"): the structs the //! program's pointers reach from a root variable (`objects.reach`: the //! recording's types say which fields are pointers and which is the //! value), drawn as boxes of a value and a pointer with arrows between //! them, in the band's left half; and in its right half the `hexdump` of //! the bytes they are drawn from. A node's place is its allocation's, so //! nodes stay where they are while pointers change: a list reversing is //! its arrows turning round. Above each node its address, the same digits //! as its row in the dump; under it its `pin`: the registers, and the //! scene's variables, that hold its address. This is the idea drawn from //! memory: it reacts when the step's projection arrives from its bytes. //! Reads `Moment.variables`, `Moment.read`, `Moment.allocation`. const std = @import("std"); const sk = @import("sketch"); const anim = @import("anim"); const zt = @import("ztrace"); const ui = @import("ui.zig"); const rows = @import("rows.zig"); const context = @import("context.zig"); const cursors = @import("cursor.zig"); const Recording = @import("Recording.zig"); const objects = @import("objects.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; const t = theme.color.text; const m = theme.metric.context; pub const Nodes = struct { cursor: cursors.Cursor, stage: *const Stage, title: []const u8 = "the list", /// The variable the structure hangs from. root: []const u8, /// The scene's variables that point at nodes, named in their pins with the registers. track: []const []const u8 = &.{}, /// No registers in the pins: an instrumented program's registers say nothing of it. quiet: bool = false, focus: bool = true, /// A pin's names past the second by name where they fit before the next /// node, not a count (the introduction's: what its caption names). named: bool = false, pub fn draw(g: *const Nodes, f: *sk.Frame, placed: anim.Placed) void { const box = g.stage.box(placed, .band); if (box.h < m.tag + m.row) return; const u = context.at(f, placed, box).faded(placed.value(g.stage.drawing)); // A relayout moves the band: what is drawn in it stays inside it // (its view, drawn below, clips itself and hands the clip back). u.clip(.{ .x = 0, .y = 0, .w = box.w, .h = box.h }); defer u.unclip(); const now = g.cursor.now(placed); const rec = g.cursor.rec; const heap = theme.color.region.heap; const legend = [_]ui.Legend{ .{ .text = "value", .ink = ui.rgb(t.primary) }, .{ .text = "next", .ink = ui.rgb(heap) }, .{ .text = "malloc's", .ink = ui.rgb(t.dim) }, .{ .text = "never read", .ink = ui.rgb(t.faint) }, }; _ = u.panel(box.w, box.h, g.title, .{ .focus = g.focus }); const moment = now.shown(.idea); const things = objects.reach(f.scratch, rec, moment, null); const before = objects.reach(f.scratch, rec, now.before(), null); // Its view: the heap the nodes are in, from the first one's chunk to the last's. var lo: u64 = std.math.maxInt(u64); var hi: u64 = 0; for (rec.allocations) |a| if (things.len > 0 and a.size == things[0].type.record.size) { lo = @min(lo, (a.ptr - 16) & ~@as(u64, 15)); hi = @max(hi, (a.ptr + a.size + 15) & ~@as(u64, 15)); }; if (lo < hi) { @import("map.zig").measure(.view, (hi - lo) / 16); const count = theme.layout.rowsIn(g.stage.box(placed, .view).h); // Its window round the rows the step touches: from the last step's, scrolled // (whole rows, 24 f, as the step begins), never a jump. const first_new = hexdump.window(now, lo, hi, count); const first_old = hexdump.windowAt(rec, now.stops[2], now.stops[1], lo, hi, count); const scroll = if (now.resting() or first_old == first_new) 1 else cursors.glide(std.math.clamp(now.time / time.move, 0, 1)); const first = if (scroll >= 0.5) first_new else first_old; const shown = @min(count, (hi - first) / 16); const v = hexdump.panel(f, placed, g.stage, u.print("the heap, {x} to {x}", .{ first, first + 16 * shown - 1 }), &legend); if (v.rows > 0) { const top = @min(first_old, first_new); const rows_apart: f32 = @floatFromInt((@max(first_old, first_new) - top) / 16); const at = std.math.lerp(@as(f32, @floatFromInt((first_old - top) / 16)), @as(f32, @floatFromInt((first_new - top) / 16)), scroll); v.u.clip(.{ .x = 0, .y = m.tag, .w = g.stage.box(placed, .view).w, .h = @as(f32, @floatFromInt(@min(shown, v.rows))) * m.row + 2 * m.pad }); hexdump.draw(v.u, now, 0, m.tag + m.pad - at * m.row, top, @min(@min(shown, v.rows) + @as(usize, @intFromFloat(rows_apart)), (hi - top) / 16), .{ .things = things }); v.u.unclip(); } if (v.rows > 0) @import("map.zig").window(.view, .{ first, first + 16 * (@min(shown, v.rows) -| 1) }, .{ first, first + 16 * (@min(shown, v.rows) -| 1) }, 1); v.veil(now); u.clip(.{ .x = 0, .y = 0, .w = box.w, .h = box.h }); } if (things.len == 0) { const root = rec.variable(f.scratch, moment, g.root); const empty = root != null and (Recording.word(moment, root.?.addr, 8) catch null) == 0; u.text(.sans, theme.size.sans.micro, 24, m.tag + 40, if (empty) u.print("empty: {s} is NULL", .{g.root}) else "nothing yet", t.faint); return; } // The drawing: one place for every node the program will ever make, // so none moves when another comes or goes. const subject = box.h >= theme.layout.split.subject.band.h - 1; const size = if (subject) theme.metric.node.subject else theme.metric.node.beside; const label: f32 = if (subject) theme.size.mono.small else theme.size.mono.context; const value_size: f32 = if (subject) theme.size.mono.flight else theme.size.mono.small; var slots: usize = 0; for (rec.allocations) |a| slots += @intFromBool(a.size == things[0].type.record.size); slots = @max(slots, 1); const n: f32 = @floatFromInt(slots); const x0 = (box.w - n * size[0] - (n - 1) * size[2]) / 2; const ly = m.tag + @as(f32, if (subject) 72 else 16); const ny = ly + label * 1.2 + 4; const places = f.scratch.alloc(Rect, things.len) catch return; for (things, places, 0..) |o, *place, i| { place.* = .{ .x = x0 + @as(f32, @floatFromInt(o.slot orelse i)) * (size[0] + size[2]), .y = ny, .w = size[0], .h = size[1] }; ties.anchor(u, .{ .node = o.addr }, place.*); } // Each node as much as it has risen from its bytes (`establish`): by address. const rising = placed.value(g.stage.rise); const shows = f.scratch.alloc(f32, things.len) catch return; const belows = f.scratch.alloc(f32, things.len) catch return; for (things, shows, belows) |o, *show, *below| { var k: usize = 0; for (things) |other| k += @intFromBool(other.addr < o.addr); const r = ties.rise(rising, k, things.len); show.* = r.element; below.* = r.below; } // Arrows first, under the nodes' edges. const since = now.since(.idea, 0); const whole = u; for (things, places, shows) |o, place, show| for (o.type.record.fields) |field| { if (field.type != .pointer) continue; const from_addr = o.addr + field.offset; const start = ui.Vec{ place.x + place.w - theme.metric.node.pointer_w / 2 + 6, place.y + place.h / 2 }; const new = if (Recording.word(now.moment(), from_addr, 8) catch null) |target| placeOf(things, places, target) else null; const old = if (Recording.word(now.before(), from_addr, 8) catch null) |target| placeOf(things, places, target) else null; // An arrow is there once both its ends are. var reach = show; if (Recording.word(now.moment(), from_addr, 8) catch null) |target| for (things, shows) |other, other_show| { if (other.addr == target) reach = @min(reach, other_show); }; if (reach <= 0) continue; const v = if (reach < 1) whole.faded(reach) else whole; const fresh = now.writeAge(from_addr, 8) == 0; const ink = ui.rgb(heap); const head = theme.metric.node.arrow_head; if (!fresh or !now.walking()) { if (if (now.landed(.idea, 0)) new else old) |to| v.route(route(v, start, place, to), ink, .{ .width = theme.stroke.line, .head = head, .progress = if (fresh) cursors.standard(now.moving(.idea, 0, time.redirect.head)) else 1 }); continue; } // A pointer rewritten. Anticipation: as its half is armed the // old arrow goes dashed and faint. Then the half strikes, the // new arrow grows to the node it now points at, and that node // answers with a bright frame. The old one lingers, then goes. const armed = since >= -time.strike.arm; if (old) |to| { const ghost = if (armed) v.faded(1 - std.math.clamp((since - time.redirect.ghost_hold) / time.redirect.ghost_out, 0, 1)) else v; ghost.route(route(v, start, place, to), if (armed) ui.rgb(t.faint) else ink, .{ .dashed = armed, .head = if (armed) null else head, .width = if (armed) theme.stroke.rule else theme.stroke.line }); } if (new) |to| { v.route(route(v, start, place, to), ink, .{ .width = theme.stroke.line, .head = head, .progress = cursors.standard(std.math.clamp((since - time.snap) / time.redirect.head, 0, 1)) }); const landed = since - time.snap - time.redirect.head; const out = 4; if (landed >= 0 and landed < time.redirect.landing) v.faded(1 - landed / time.redirect.landing).frame(.{ .x = to.x - out, .y = to.y - out, .w = to.w + 2 * out, .h = to.h + 2 * out }, theme.mark(.attention).solid, theme.stroke.rule); } }; for (things, places, shows, belows) |o, place, show, below| { const new = for (before) |was| { if (was.addr == o.addr) break false; } else true; // Its pin's names run right as far as the next node (or the band's edge). var room = box.w - m.pad - 8; for (places) |q| if (q.x > place.x) { room = @min(room, q.x - 8); }; // What begins fades in; it does not pop. if (show > 0) g.node(u.faded(show * (if (new) now.moving(.idea, 0, time.quick) else 1)).moved(0, below), now, o, place, label, value_size, room); } g.tags(u, now, things, places, label); } fn node(g: *const Nodes, u: ui.Ui, now: cursors.Now, o: objects.Object, r: Rect, label: f32, value_size: f32, room: f32) void { const moment = now.shown(.idea); const heap = theme.color.region.heap; const pw = theme.metric.node.pointer_w; const value: Rect = .{ .x = r.x, .y = r.y, .w = r.w - pw - 2, .h = r.h }; const pointer: Rect = .{ .x = r.x + r.w - pw, .y = r.y, .w = pw, .h = r.h }; // Its address over it, in heap's ink: the digits of its row in the dump. const digits = u.print("{x}", .{o.addr}); const lw = @as(f32, @floatFromInt(digits.len)) * label * 3 / 5; const ly = r.y - 4 - label * 1.2; u.text(.mono, label, r.x + (r.w - lw) / 2, ly + label * 0.96, digits, heap); ties.anchor(u, .{ .node_address = o.addr }, .{ .x = r.x, .y = ly, .w = r.w, .h = label * 1.2 }); if (o.freed) { // Handed back: its bytes are still there, and nobody owns them. u.dashedFrame(r, theme.mark(.freed).solid, theme.stroke.line); } else { u.fill(value, theme.color.raised); u.fill(pointer, theme.color.well); } if (o.valueField()) |field| { const bytes: usize = @intCast(@min(8, field.type.size() orelse 8)); const at = o.addr + field.offset; ties.anchor(u, .{ .node_part = at }, value); var ink: ui.Ink = .{}; if (!o.freed) ink = u.cellWritten(value, now.written(at, bytes, .idea, 0), theme.color.raised); if (now.wasRead(at, bytes) and now.writeAge(at, bytes) != 0) u.cellRead(value, now.reading(.idea, 0)); if (Recording.word(moment, at, bytes) catch null) |n| { const shift: u6 = @intCast(64 - 8 * bytes); const signed = @as(i64, @bitCast(n << shift)) >> shift; u.label(ink.face, value_size, value, .center, objects.reading(u.f.scratch, signed, field.type), if (o.freed) ui.rgb(t.faint) else ink.ink); } else u.unknown(value); } // The first pointer field: the square its arrow leaves from, or a slash for null. for (o.type.record.fields) |field| { if (field.type != .pointer) continue; const at = o.addr + field.offset; ties.anchor(u, .{ .node_part = at }, pointer); const held = Recording.word(moment, at, 8) catch null; const struck = !o.freed and u.cellWritten(pointer, now.written(at, 8, .idea, 0), theme.color.well).face == .mono_bold; if (now.wasRead(at, 8) and now.writeAge(at, 8) != 0) u.cellRead(pointer, now.reading(.idea, 0)); const sq = theme.metric.node.origin; if (held == null) { u.unknown(pointer); } else if (held.? == 0) { u.line(.{ pointer.x + 10, pointer.y + pointer.h - 8 }, .{ pointer.x + pointer.w - 10, pointer.y + 8 }, if (struck) t.ink else t.dim, theme.stroke.rule); } else u.fill(.{ .x = pointer.x + pointer.w / 2 - sq / 2, .y = pointer.y + pointer.h / 2 - sq / 2, .w = sq, .h = sq }, if (struck) t.ink else heap); break; } // Who points here: a pin under it, landing with its link. const names = g.pins(u, now, o.addr); const cx = r.x + r.w / 2; ties.anchor(u, .{ .node_pin = o.addr }, .{ .x = cx - 1, .y = r.y + r.h, .w = 2, .h = label + 10 }); if (names.names.len > 0 and names.shows > 0) { u.faded(names.shows).pinUnderInked(cx, r.y + r.h, &.{}, &.{}, heap, label); u.faded(names.shows * names.text).pinNames(cx, r.y + r.h, names.names, names.inks, label, if (g.named) room else 0); } } /// Where variable `name`'s tag is: it travels from node to node in the /// drawing's slot, as the idea strikes, after its word has been struck /// (`glide`, `time.pin`: 30 f to the next node, 36 f further); it does not jump. fn tagOf(g: *const Nodes, u: ui.Ui, now: cursors.Now, name: []const u8) Tag { const rec = g.cursor.rec; const at = struct { fn value(r: *Recording, scratch: std.mem.Allocator, then: Recording.Moment, n: []const u8) u64 { const v = r.variable(scratch, then, n) orelse return 0; if (!r.assigned(v, then.index)) return 0; return (Recording.word(then, v.addr, 8) catch null) orelse 0; } }; const to = at.value(rec, u.f.scratch, now.moment(), name); const from = at.value(rec, u.f.scratch, now.before(), name); if (from == to or now.resting()) return .{ .from = from, .to = to, .p = 1 }; const far: f32 = if (from != 0 and to != 0 and @abs(@as(i64, @bitCast(to -% from))) > 0x30) time.pin.nodes else time.pin.node; const p = switch (now.plan.gait) { .walk => std.math.clamp(now.since(.idea, 0) / far, 0, 1), .run => now.moving(.idea, 0, time.run_ease), .sprint => 1, }; return .{ .from = from, .to = to, .p = p }; } /// The tags on their way: from node to node along the band's bottom, /// or arriving where there was none (fading in, rising 8), or leaving /// for none (fading out). fn tags(g: *const Nodes, u: ui.Ui, now: cursors.Now, things: []const objects.Object, places: []const Rect, label: f32) void { const heap = theme.color.region.heap; for (g.track) |name| { const tag = g.tagOf(u, now, name); if (!tag.moving() or tag.p <= 0) continue; const a = placeOf(things, places, tag.from); const b = placeOf(things, places, tag.to); // It keeps the side it had where it leaves; one that comes to // names already there goes on the stub's right. const was_regs = (now.before().regs(g.cursor.rec.tid) catch null) orelse zt.Regs{}; const left_from = g.namesBefore(u, now, tag.from, was_regs); const was_right = left_from.len >= 2 and !std.mem.eql(u8, left_from[0], name); const crowded = was_right or (a == null and g.pins(u, now, tag.to).names.len > 0); const names: []const []const u8 = if (crowded) &.{ "", name } else &.{name}; const ink = g.home(u, now, name); const inks: []const u24 = if (crowded) &.{ t.primary, ink } else &.{ink}; if (a != null and b != null) { const x = std.math.lerp(a.?.x + a.?.w / 2, b.?.x + b.?.w / 2, cursors.glide(tag.p)); u.pinUnderInked(x, a.?.y + a.?.h, names, inks, heap, label); } else if (b) |r| { const p = std.math.clamp(tag.p / (time.pin.in / time.pin.node), 0, 1); u.faded(p).pinUnderInked(r.x + r.w / 2, r.y + r.h + (1 - p) * theme.time.caption_rise, names, inks, heap, label); } else if (a) |r| { u.faded(1 - std.math.clamp(tag.p / (time.pin.out / time.pin.node), 0, 1)).pinUnderInked(r.x + r.w / 2, r.y + r.h, names, inks, heap, label); } } } /// `text`: how much its names show: a register joining or leaving /// crosses the middle of its change with them faded out, so the names /// it leaves and those it gets never swap in a frame. const Pins = struct { names: []const []const u8, inks: []const u24, shows: f32, text: f32 = 1 }; /// The registers that hold `addr` (before this step, and after it once /// their link has landed), then the scene's variables that do. fn pins(g: *const Nodes, u: ui.Ui, now: cursors.Now, addr: u64) Pins { const rec = g.cursor.rec; var out: std.ArrayList([]const u8) = .empty; var inks: std.ArrayList(u24) = .empty; var shows: f32 = 0; var text: f32 = 1; const is = (now.moment().regs(rec.tid) catch null) orelse zt.Regs{}; const was = (now.before().regs(rec.tid) catch null) orelse is; // The scene's variables first: what the narration names, in the ink // of where each lives. One on its way from another node is drawn // apart (`tags`). for (g.track) |name| { const tag = g.tagOf(u, now, name); // Where it is: at the node it leaves until it sets off. const here = if (tag.p <= 0) tag.from else tag.to; if ((tag.moving() and tag.p > 0) or here != addr) continue; out.append(u.f.scratch, name) catch break; inks.append(u.f.scratch, g.home(u, now, name)) catch break; shows = 1; } if (!g.quiet) for (theme.metric.all_registers[0..16]) |name| { const i = context.index(name).?; const before = was.named(name) == addr; const after = is.named(name) == addr; if (!before and !after) continue; const s = ties.pinShows(now, i, .node); const this = if (before and after) 1 else if (after) s.new else s.old; if (before != after) text = @min(text, @abs(2 * this - 1)); if (this < 0.5) continue; out.append(u.f.scratch, name) catch break; inks.append(u.f.scratch, t.primary) catch break; shows = @max(shows, this); }; // Names keep their side: the first to come is on the left, the next // on the right, and a name that lands where another is stays on the // right it travelled on; one left alone where it was on the right stays there. const came = u.f.scratch.alloc(u64, out.items.len) catch return .{ .names = out.items, .inks = inks.items, .shows = shows, .text = text }; for (out.items, came) |name, *at| at.* = g.arrival(u, now, name, addr); for (1..@max(out.items.len, 1)) |i| { var k = i; while (k > 0 and came[k - 1] > came[k]) : (k -= 1) { std.mem.swap(u64, &came[k - 1], &came[k]); std.mem.swap([]const u8, &out.items[k - 1], &out.items[k]); std.mem.swap(u24, &inks.items[k - 1], &inks.items[k]); } } // Two names whose order the step turns (one reassigned to the same node): the names // fade out in the old order and in the new one over the step's first 24 f, never swapped in a frame. if (out.items.len == 2 and !now.resting() and now.stops[1] != now.stops[2]) both: { // Both on the pin before the step too. const then = g.namesAt(u, now.stops[1], addr); for (out.items) |name| { if (for (then) |o| { if (std.mem.eql(u8, o, name)) break false; } else true) break :both; } const a = g.arrivalAt(u, now.stops[1], now.stops[2], out.items[0], addr); const b = g.arrivalAt(u, now.stops[1], now.stops[2], out.items[1], addr); if (a > b) { const p = std.math.clamp(now.time / (2 * time.quick), 0, 1); text = @min(text, @abs(2 * p - 1)); if (p < 0.5) { std.mem.swap([]const u8, &out.items[0], &out.items[1]); std.mem.swap(u24, &inks.items[0], &inks.items[1]); } } } // Both sides taken: a variable the scene names (what the narration // follows) takes the right from a register, which is counted. if (out.items.len > 2 and context.index(out.items[1]) != null) for (out.items[2..], 2..) |name, j| { if (context.index(name) != null) continue; var k = j; while (k > 1) : (k -= 1) { std.mem.swap([]const u8, &out.items[k - 1], &out.items[k]); std.mem.swap(u24, &inks.items[k - 1], &inks.items[k]); } break; }; if (out.items.len == 1) { const first_before = g.firstBefore(u, now, addr, was); // Kept on the right in the step before (the other had just left): it goes over // to the left at the start of this one, fading out and in (24 f), never in a frame. const older = g.namesAt(u, now.stops[2], addr); const was_right = now.stops[2] != now.stops[1] and older.len >= 2 and !std.mem.eql(u8, older[0], out.items[0]); const over = if (now.resting()) 1 else std.math.clamp(now.time / (2 * time.quick), 0, 1); if (was_right and first_before == null) text = @min(text, @abs(2 * over - 1)); if ((first_before != null and !std.mem.eql(u8, first_before.?, out.items[0])) or (was_right and first_before == null and over < 0.5)) { out.insert(u.f.scratch, 0, "") catch {}; inks.insert(u.f.scratch, 0, t.primary) catch {}; } } return .{ .names = out.items, .inks = inks.items, .shows = shows, .text = text }; } /// When `name` came to point at `addr`: the moment its value last /// became it (a variable's, its last assignment), as of the stop shown /// (or the one before, for a name that is leaving). fn arrival(g: *const Nodes, u: ui.Ui, now: cursors.Now, name: []const u8, addr: u64) u64 { return g.arrivalAt(u, now.stops[0], now.stops[1], name, addr); } /// The same, as of stop `here` (the one before it `before`). fn arrivalAt(g: *const Nodes, u: ui.Ui, here: u64, before: u64, name: []const u8, addr: u64) u64 { const rec = g.cursor.rec; if (context.index(name)) |_| { var i = if (rec.registers[here].named(name) == addr) here else before; while (i > 0 and rec.registers[i - 1].named(name) == addr) i -= 1; return i; } const v = rec.variable(u.f.scratch, rec.moment(here), name) orelse return here; var i = if ((Recording.word(rec.moment(here), v.addr, 8) catch null) == addr) here else before; // Its assignment: a store, of a new value or of the one its slot held. while (i > 0 and !Recording.touches(rec.written(i - 1, i), v.addr, 8) and !Recording.touches(rec.storedSame(i - 1, i), v.addr, 8)) i -= 1; return i; } /// The first name on `addr`'s pin before this step, if another name was beside it. fn firstBefore(g: *const Nodes, u: ui.Ui, now: cursors.Now, addr: u64, was: zt.Regs) ?[]const u8 { const names = g.namesBefore(u, now, addr, was); return if (names.len >= 2) names[0] else null; } /// The names on `addr`'s pin before this step, in their order (the first left). fn namesBefore(g: *const Nodes, u: ui.Ui, now: cursors.Now, addr: u64, was: zt.Regs) []const []const u8 { const rec = g.cursor.rec; var out: std.ArrayList([]const u8) = .empty; for (g.track) |name| { const v = rec.variable(u.f.scratch, now.before(), name) orelse continue; if (!rec.assigned(v, now.before().index)) continue; if ((Recording.word(now.before(), v.addr, 8) catch null) != addr) continue; out.append(u.f.scratch, name) catch break; } if (!g.quiet) for (theme.metric.all_registers[0..16]) |name| if (was.named(name) == addr) { out.append(u.f.scratch, name) catch break; }; return out.items; } /// The names on `addr`'s pin at moment `at`. fn namesAt(g: *const Nodes, u: ui.Ui, at: u64, addr: u64) []const []const u8 { const rec = g.cursor.rec; const mo = rec.moment(at); var out: std.ArrayList([]const u8) = .empty; for (g.track) |name| { const v = rec.variable(u.f.scratch, mo, name) orelse continue; if (!rec.assigned(v, mo.index)) continue; if ((Recording.word(mo, v.addr, 8) catch null) != addr) continue; out.append(u.f.scratch, name) catch break; } const regs = (mo.regs(rec.tid) catch null) orelse return out.items; if (!g.quiet) for (theme.metric.all_registers[0..16]) |name| if (regs.named(name) == addr) { out.append(u.f.scratch, name) catch break; }; return out.items; } /// The ink of where variable `name` lives: stack for a local, data for a global. fn home(g: *const Nodes, u: ui.Ui, now: cursors.Now, name: []const u8) u24 { const v = g.cursor.rec.variable(u.f.scratch, now.moment(), name) orelse return t.primary; return rows.ink(rows.regionOf(now.moment(), v.addr)); } }; /// A variable's tag: the node it was under before the step and the one /// it is under after it (0: none), and how far it has gone. const Tag = struct { from: u64, to: u64, p: f32, fn moving(tag: Tag) bool { return tag.from != tag.to and tag.p < 1; } }; fn placeOf(things: []const objects.Object, places: []const Rect, addr: u64) ?Rect { for (things, places) |o, place| if (o.addr == addr) return place; return null; } /// From the pointer square at `start` (in the node at `from`) to the node /// at `to`: straight to a node on its right; to one on its left, under /// the nodes, in from below. fn route(u: ui.Ui, start: ui.Vec, from: Rect, to: Rect) []const ui.Vec { const out = u.f.scratch.alloc(ui.Vec, 4) catch return &.{}; if (to.x > from.x) { out[0] = start; out[1] = .{ to.x - 3, to.y + to.h / 2 }; return out[0..2]; } const under = from.y + from.h + 6; out[0] = .{ start[0], from.y + from.h }; out[1] = .{ start[0], under }; const into = to.x + (to.w - theme.metric.node.pointer_w) / 2; out[2] = .{ into, under }; out[3] = .{ into, to.y + to.h + 1 }; return out; }