summaryrefslogtreecommitdiff
path: root/anim/src
diff options
context:
space:
mode:
authorGabriel Schneider <[email protected]>2026-11-13 01:24:16 -0300
committerGabriel Schneider <[email protected]>2026-11-13 01:34:46 -0300
commit5a40dca5adb6e9e650f55f3ec6f254a13bf50493 (patch)
tree5fdffebd75ed3fbac1eae5dec0a3f2d491450342 /anim/src
parent4b4113a0217ee27c78e7efddb66ff5a455d49083 (diff)
downloadcomputeranim-5a40dca5adb6e9e650f55f3ec6f254a13bf50493.tar.gz
computeranim-5a40dca5adb6e9e650f55f3ec6f254a13bf50493.zip
debugger: align source and add rich Vim-style navigation
Diffstat (limited to 'anim/src')
-rw-r--r--anim/src/aligned.zig51
-rw-r--r--anim/src/disasm.zig24
-rw-r--r--anim/src/map.zig48
-rw-r--r--anim/src/root.zig4
-rw-r--r--anim/src/rows.zig13
-rw-r--r--anim/src/source.zig22
-rw-r--r--anim/src/ui.zig22
7 files changed, 146 insertions, 38 deletions
diff --git a/anim/src/aligned.zig b/anim/src/aligned.zig
index ce2f5a0..24601c2 100644
--- a/anim/src/aligned.zig
+++ b/anim/src/aligned.zig
@@ -37,6 +37,57 @@ const theme = ui.theme;
const Rect = ui.Rect;
const t = theme.color.text;
+pub const LiveRow = struct {
+ instruction: ?usize,
+ source: ?@import("ztrace").store.Line = null,
+ again: bool = false,
+};
+
+/// The same column alignment for a bounded live listing. Source-only gaps have no address.
+pub fn livePlan(lines: []const ?@import("ztrace").store.Line, out: []LiveRow) []LiveRow {
+ var n: usize = 0;
+ var previous: ?@import("ztrace").store.Line = null;
+ for (lines, 0..) |line, i| {
+ const head = if (line) |l| previous == null or previous.?.file != l.file or previous.?.line != l.line else false;
+ if (head and previous != null) {
+ const before = previous.?;
+ const after = line.?;
+ if (before.file == after.file and after.line > before.line and after.line - before.line <= 8) {
+ var number = before.line + 1;
+ while (number < after.line and n < out.len) : (number += 1) {
+ out[n] = .{ .instruction = null, .source = .{ .file = after.file, .line = number } };
+ n += 1;
+ }
+ }
+ }
+ if (n == out.len) break;
+ var again = false;
+ if (head) for (lines[0..i]) |old| {
+ if (old) |l| if (l.file == line.?.file and l.line == line.?.line) {
+ again = true;
+ break;
+ };
+ };
+ out[n] = .{ .instruction = i, .source = if (head) line else null, .again = again };
+ n += 1;
+ previous = line;
+ }
+ return out[0..n];
+}
+
+test "live columns retain repeated runs and source-only gaps" {
+ const Line = @import("ztrace").store.Line;
+ const a: Line = .{ .file = 1, .line = 4 };
+ const b: Line = .{ .file = 1, .line = 7 };
+ var out: [16]LiveRow = undefined;
+ const got = livePlan(&.{ a, a, b, a, null }, &out);
+ try std.testing.expectEqual(@as(usize, 7), got.len);
+ try std.testing.expect(got[1].source == null);
+ try std.testing.expect(got[2].instruction == null and got[2].source.?.line == 5);
+ try std.testing.expect(got[5].again);
+ try std.testing.expect(got[6].source == null);
+}
+
const size = theme.size.mono.context;
const adv = ui.advance(size);
const pitch = theme.metric.context.row;
diff --git a/anim/src/disasm.zig b/anim/src/disasm.zig
index 3fbe4ff..afeef1b 100644
--- a/anim/src/disasm.zig
+++ b/anim/src/disasm.zig
@@ -792,7 +792,7 @@ const Say = struct {
const count = a.argumentRows(row, to, moment);
const shown = a.rec.moment(moment);
// Flags by name, where a system call of its name says which argument they are.
- const nr: ?u64 = if (std.meta.stringToEnum(std.os.linux.SYS, name)) |sys| @intFromEnum(sys) else null;
+ const nr: ?u64 = if (std.meta.stringToEnum(std.os.linux.SYS, name)) |sys| @backingInt(sys) else null;
const names: []const []const u8 = if (nr) |n| zt.syscalls.names(n) else &.{};
for (carriers[0..count], 1..) |reg, k| {
const ry = a.y + @as(f32, @floatFromInt(k)) * m.row;
@@ -819,7 +819,7 @@ const Say = struct {
fn cForm(a: Say, row: Insn, to: u64, moment: u64, result: ?u64, width: f32) []const u8 {
const u = a.u;
const name = a.functionName(to, moment);
- const nr: ?u64 = if (std.meta.stringToEnum(std.os.linux.SYS, name)) |sys| @intFromEnum(sys) else null;
+ const nr: ?u64 = if (std.meta.stringToEnum(std.os.linux.SYS, name)) |sys| @backingInt(sys) else null;
const names: []const []const u8 = if (nr) |n| zt.syscalls.names(n) else &.{};
const count = @min(row.params orelse argumentCount(a.rec, row, name) orelse names.len, 6);
// Out of room the arguments go from the right, `…` for them; the result stays.
@@ -1081,14 +1081,14 @@ pub fn flagsRead(mn: []const u8) u16 {
const cond = if (std.mem.startsWith(u8, mn, "cmov")) mn[4..] else if (std.mem.startsWith(u8, mn, "set")) mn[3..] else if (mn.len > 1 and mn[0] == 'j' and !std.mem.eql(u8, mn, "jmp")) mn[1..] else return 0;
const f = flag_bits;
const table = [_]struct { []const u8, u16 }{
- .{ "a", f.cf | f.zf }, .{ "nbe", f.cf | f.zf }, .{ "be", f.cf | f.zf }, .{ "na", f.cf | f.zf },
- .{ "ae", f.cf }, .{ "nb", f.cf }, .{ "nc", f.cf }, .{ "b", f.cf },
- .{ "c", f.cf }, .{ "nae", f.cf }, .{ "e", f.zf }, .{ "z", f.zf },
- .{ "ne", f.zf }, .{ "nz", f.zf }, .{ "g", f.zf | f.sf | f.of }, .{ "nle", f.zf | f.sf | f.of },
- .{ "le", f.zf | f.sf | f.of }, .{ "ng", f.zf | f.sf | f.of }, .{ "ge", f.sf | f.of }, .{ "nl", f.sf | f.of },
- .{ "l", f.sf | f.of }, .{ "nge", f.sf | f.of }, .{ "o", f.of }, .{ "no", f.of },
- .{ "s", f.sf }, .{ "ns", f.sf }, .{ "p", f.pf }, .{ "pe", f.pf },
- .{ "np", f.pf }, .{ "po", f.pf },
+ .{ "a", f.cf | f.zf }, .{ "nbe", f.cf | f.zf }, .{ "be", f.cf | f.zf }, .{ "na", f.cf | f.zf },
+ .{ "ae", f.cf }, .{ "nb", f.cf }, .{ "nc", f.cf }, .{ "b", f.cf },
+ .{ "c", f.cf }, .{ "nae", f.cf }, .{ "e", f.zf }, .{ "z", f.zf },
+ .{ "ne", f.zf }, .{ "nz", f.zf }, .{ "g", f.zf | f.sf | f.of }, .{ "nle", f.zf | f.sf | f.of },
+ .{ "le", f.zf | f.sf | f.of }, .{ "ng", f.zf | f.sf | f.of }, .{ "ge", f.sf | f.of }, .{ "nl", f.sf | f.of },
+ .{ "l", f.sf | f.of }, .{ "nge", f.sf | f.of }, .{ "o", f.of }, .{ "no", f.of },
+ .{ "s", f.sf }, .{ "ns", f.sf }, .{ "p", f.pf }, .{ "pe", f.pf },
+ .{ "np", f.pf }, .{ "po", f.pf },
};
for (table) |e| if (std.mem.eql(u8, cond, e[0])) return e[1];
return 0;
@@ -1396,7 +1396,9 @@ fn operandsWidth(u: ui.Ui, row: Insn, ops: Operands, stub: []const u8) f32 {
/// would fall there falls before the `[`.
fn operands(u: ui.Ui, row: Insn, ops: Operands, stub: []const u8, base_y: f32, width: f32, ink: u24) void {
if (target(row)) |to| {
- _ = u.address(c.operands, base_y, to, .{ .ink = ui.rgb(theme.color.region.code_), .name = stub });
+ const end = u.address(c.operands, base_y, to, .{ .ink = ui.rgb(theme.color.region.code_) });
+ const remaining = c.operands + width - end - 10;
+ if (stub.len > 0 and remaining >= adv) u.text(.mono, size, end + 10, base_y, rows.fitted(u, ui.symbol(u, stub), remaining), t.primary);
return;
}
const text = ops.text;
diff --git a/anim/src/map.zig b/anim/src/map.zig
index 2a2077a..a70244f 100644
--- a/anim/src/map.zig
+++ b/anim/src/map.zig
@@ -69,20 +69,20 @@ var held: [7]usize = @splat(0);
/// While the map draws: `panel` wants `n` rows for what it shows now.
pub fn measure(panel: Panel, n: usize) void {
- if (ui.mapping) held[@intFromEnum(panel)] = @max(held[@intFromEnum(panel)], n);
+ if (ui.mapping) held[@backingInt(panel)] = @max(held[@backingInt(panel)], n);
}
/// A working panel shows the rows of keys `now` (first and last), going
/// there from `was`, `p` of the way (eased): its outline on the map and
/// its window on its strip glide with its scroll, and never jump.
pub fn window(panel: Panel, now: [2]u64, was: [2]u64, p: f32) void {
- if (!ui.mapping) windows[@intFromEnum(panel)] = .{ .now = now, .was = was, .p = p };
+ if (!ui.mapping) windows[@backingInt(panel)] = .{ .now = now, .was = was, .p = p };
}
/// A map panel's row of key `key` is at `r`, in `u`'s units.
pub fn row(panel: Panel, key: u64, u: ui.Ui, r: Rect) void {
if (!ui.mapping) return;
- const i = @intFromEnum(panel);
+ const i = @backingInt(panel);
if (counts[i] == rows[i].len) return;
const a = u.at.xf.apply(.{ r.x, r.y });
const b = u.at.xf.apply(.{ r.x + r.w, r.y + r.h });
@@ -128,7 +128,7 @@ pub fn split(rec: *const Recording, band_h: f32, way: [2]u64) Split {
const foot = st.y + st.h;
const want = struct {
fn of(panel: Panel, default: usize) f32 {
- const n = held[@intFromEnum(panel)];
+ const n = held[@backingInt(panel)];
return @floatFromInt(if (n > 0) n else default);
}
}.of;
@@ -472,7 +472,7 @@ pub const Map = struct {
// on its way (the disassembly over the source's foot, the stack over
// the registers' lower rows were, for a third of a second).
inline for (.{ "band", "view", "disasm", "stack", "source", "registers", "backtrace" }, 0..) |name, order| {
- const i = @intFromEnum(@field(Panel, name));
+ const i = @backingInt(@field(Panel, name));
const box = @field(working, name);
if (box.h > 0) if (window_px[i]) |w| {
const a = back.apply(.{ w[0], w[1] });
@@ -480,7 +480,7 @@ pub const Map = struct {
// On the map as it fills the frame (half its units): the panel's rows on the window's rows, its tag above them;
// a window that is the panel whole (the band, the registers) has its tag in it.
const s0 = (b[0] - a[0]) / 2 / box.w;
- const whole = i == @intFromEnum(Panel.band) or i == @intFromEnum(Panel.registers);
+ const whole = i == @backingInt(Panel.band) or i == @backingInt(Panel.registers);
const lead = (if (whole) 0 else theme.metric.context.tag + theme.metric.context.pad) * s0;
const from: Rect = .{ .x = a[0] / 2, .y = a[1] / 2 - lead, .w = box.w * s0, .h = box.h * s0 };
const p = theme.ease(.glide, std.math.clamp((t - diving.move - @as(f32, @floatFromInt(order)) * diving.apart) / diving.travel, 0, 1));
@@ -491,7 +491,7 @@ pub const Map = struct {
// The tags, rules and lanes, and the strips, come in as the map lands.
const chrome = std.math.clamp((t - diving.lift) / 12, 0, 1);
// The registers arrive whole from the map and fold as they land: each quiet row glides into its cell.
- context.zoomed[i] = .{ .box = box, .to = .{ .x = x, .y = y, .w = box.w * scale, .h = box.h * scale }, .chrome = chrome, .fold = if (i == @intFromEnum(Panel.registers)) p else 1 };
+ context.zoomed[i] = .{ .box = box, .to = .{ .x = x, .y = y, .w = box.w * scale, .h = box.h * scale }, .chrome = chrome, .fold = if (i == @backingInt(Panel.registers)) p else 1 };
};
}
// Each pane's column squeezing into its strip: their places on the map give way first, then they go.
@@ -500,7 +500,7 @@ pub const Map = struct {
inline else => |tag| @field(working, @tagName(tag)),
};
const gone = 1 - stripShows(panel, t);
- if (box.h > 0 and gone > 0 and windows[@intFromEnum(panel)] != null) m.squeeze(f, fixed, at, panel, box, ways[@intFromEnum(panel)], .{ .masking = masking, .shows = gone, .veil = veil, .bright = bright });
+ if (box.h > 0 and gone > 0 and windows[@backingInt(panel)] != null) m.squeeze(f, fixed, at, panel, box, ways[@backingInt(panel)], .{ .masking = masking, .shows = gone, .veil = veil, .bright = bright });
};
}
@@ -658,7 +658,7 @@ pub const Map = struct {
/// Where the map's row of key `key` in `panel` is this frame, in canvas pixels.
fn rows_of(panel: Panel, key: u64) ?[4]f32 {
- const i = @intFromEnum(panel);
+ const i = @backingInt(panel);
for (rows[i][0..counts[i]]) |rw| if (rw.key == key) return rw.box;
return null;
}
@@ -673,7 +673,7 @@ pub const Map = struct {
const split_ = m.stage.now(at);
inline for (.{ "band", "view", "source", "disasm", "registers", "stack", "backtrace" }) |name| {
const panel = @field(Panel, name);
- const i = @intFromEnum(panel);
+ const i = @backingInt(panel);
const box = @field(split_, name);
if (box.h > 0) {
const a = at.xf.apply(.{ box.x, box.y });
@@ -812,7 +812,7 @@ pub const Map = struct {
for (stripped, out) |panel, *c| {
c.* = .{};
const boxes = m.column(at, panel);
- const i = @intFromEnum(panel);
+ const i = @backingInt(panel);
for (rows[i][0..counts[i]]) |rw| {
if (c.n == c.keys.len) break;
const place = spotIn(boxes, rw.box[0] + 1, rw.box[1], false) orelse continue;
@@ -844,7 +844,7 @@ pub const Map = struct {
var caps: [stripped.len]f32 = undefined;
for (stripped, cols, &wins, &firsts, &caps, heights) |panel, *col, *win, *first, *cap, sh| {
cap.* = (sh - st.top - st.foot) / st.pitch;
- win.* = spanOf2(then[@intFromEnum(panel)], col);
+ win.* = spanOf2(then[@backingInt(panel)], col);
// Whole rows at rest: its strokes on the image's pixels.
first.* = firstShown(col, win.* orelse .{ 0, 0 }, @floor(cap.*));
}
@@ -880,7 +880,7 @@ pub const Map = struct {
const near = @round(spot.r);
if (near < 0 or near >= atlas_rows) break;
const i: usize = @intFromFloat(near);
- shows[slot][i][@intFromEnum(mk.kind)] = @max(shows[slot][i][@intFromEnum(mk.kind)], @min(mk.shows, 1));
+ shows[slot][i][@backingInt(mk.kind)] = @max(shows[slot][i][@backingInt(mk.kind)], @min(mk.shows, 1));
place[slot][i] = spot.r;
break;
};
@@ -1141,7 +1141,7 @@ pub var maps_frame: u64 = std.math.maxInt(u64);
fn ownMap(panel: Panel, at: anim.Placed, box: Rect) ?*const Map {
for (maps) |maybe| if (maybe) |m| {
- const b = m.frame.box(at, @enumFromInt(@intFromEnum(panel)));
+ const b = m.frame.box(at, @fromBackingInt(@intCast(@backingInt(panel))));
if (@abs(b.x - box.x) < 0.5 and @abs(b.y - box.y) < 0.5 and @abs(b.w - box.w) < 0.5 and @abs(b.h - box.h) < 0.5) return m;
};
return current;
@@ -1170,7 +1170,7 @@ fn flash(now: @import("cursor.zig").Now) void {
const sixteen = span.addr & ~@as(u64, 15);
const panel: Panel, const key: u64 = if (Map.rows_of(.stack, word) != null) .{ .stack, word } else .{ .view, sixteen };
if (Map.rows_of(panel, key) == null) continue;
- if (windows[@intFromEnum(panel)]) |win| if (key >= win.now[0] and key <= win.now[1]) continue;
+ if (windows[@backingInt(panel)]) |win| if (key >= win.now[0] and key <= win.now[1]) continue;
if (n_flashes == flashes.len) return;
flashes[n_flashes] = .{ .panel = panel, .key = key, .ink = mark.ink, .p = p };
n_flashes += 1;
@@ -1209,7 +1209,7 @@ fn pixels(f: *sk.Frame, k: f32, slot: usize, x: f32, y: f32, w: f32, h: f32, col
/// Where a pane's window is on its column now: its first and last row,
/// between where it was and where it is, as far as its scroll has gone.
fn windowOn(panel: Panel, col: *const Column) ?[2]f32 {
- return spanOf2(windows[@intFromEnum(panel)], col);
+ return spanOf2(windows[@backingInt(panel)], col);
}
/// The first row a strip of `cap` rows shows: the column's top, or where
@@ -1253,6 +1253,22 @@ pub fn strip(panel: Panel, u: ui.Ui, box: Rect) void {
f.image(atlas.images[theme.time.minimap_fade], sk.Rect{ .x = a[0], .y = a[1], .w = b[0] - a[0], .h = b[1] - a[1] }, .{ .src = sk.Rect{ .x = @as(f32, @floatFromInt(slot)) * st.w * k, .y = 0, .w = st.w * k, .h = r.h * k }, .tint = sk.Color.white.alphaFloat(v.at.pose.opacity) });
}
+/// A bounded live pane's actual collected text, using the gallery's strip grammar.
+/// Collect with `ui.strokes` under an empty clip; this never indexes a recording.
+pub fn liveStrip(u: ui.Ui, runs: []const ui.Collected.Run, box: Rect, content_width: f32, row_count: usize, first: f32, visible: f32, current_row: ?f32) void {
+ u.fill(box, theme.color.raised);
+ const count = @max(@as(f32, @floatFromInt(row_count)), visible);
+ const sy = box.h / (count * theme.metric.context.row);
+ const sx = box.w / content_width;
+ for (runs) |run| {
+ u.fill(.{ .x = box.x + run.x0 * sx, .y = box.y + run.y * sy, .w = @max(1, (run.x1 - run.x0) * sx), .h = @min(2, @max(1, 16 * sy)) }, run.ink);
+ }
+ if (current_row) |row_| u.fill(.{ .x = box.x, .y = box.y + row_ * box.h / count, .w = box.w, .h = 2 }, theme.mark(.current).solid);
+ const y = box.y + std.math.clamp(first / count, 0, 1) * box.h;
+ const h = @max(6, @min(visible / count * box.h, box.y + box.h - y));
+ u.frame(.{ .x = box.x, .y = y, .w = box.w, .h = h }, theme.color.text.primary, 1);
+}
+
test "the map's columns hold their panels" {
try std.testing.expectEqual(@as(f32, 1688), theme.layout.panelH(theme.map.disasm_rows));
const st = theme.map.stage;
diff --git a/anim/src/root.zig b/anim/src/root.zig
index bc807de..a165d2a 100644
--- a/anim/src/root.zig
+++ b/anim/src/root.zig
@@ -30,7 +30,8 @@ pub const Levels = cursors.Levels;
pub const rows = @import("rows.zig");
pub const Stage = @import("stage.zig").Stage;
-pub const Source = @import("source.zig").Source;
+pub const source = @import("source.zig");
+pub const Source = source.Source;
const contexts = @import("context.zig");
pub const Registers = contexts.Registers;
pub const Stack = contexts.Stack;
@@ -58,6 +59,7 @@ pub const anchor = tying.anchor;
pub const findPlace = tying.find;
pub const Array = @import("array.zig").Array;
pub const Loupe = @import("loupe.zig").Loupe;
+pub const minimap = @import("map.zig");
pub const syscalls = @import("syscalls.zig");
pub const descent = @import("descent.zig");
pub const Crossing = syscalls.Crossing;
diff --git a/anim/src/rows.zig b/anim/src/rows.zig
index bdf9454..4666ffd 100644
--- a/anim/src/rows.zig
+++ b/anim/src/rows.zig
@@ -113,7 +113,7 @@ pub const Hops = struct {
/// then the chain ends early in `more`; nothing is taken from the middle.
pub fn chain(u: ui.Ui, x: f32, y: f32, moment: Recording.Moment, value: u64, room: f32, marks: Marks) Hops {
var links_buf: [6]zt.telescope.Link = undefined;
- var text_buf: [48]u8 = undefined;
+ var text_buf: [256]u8 = undefined;
const links = zt.telescope.chase(moment, value, &links_buf, &text_buf) catch return .{};
const base = baseline(y);
const mid = y + row_h / 2;
@@ -247,13 +247,20 @@ pub fn rip(u: ui.Ui, y: f32, w: f32, moment: Recording.Moment, pc: u64, eflags:
u.current(.{ .x = theme.stroke.rule, .y = y, .w = w - 2 * theme.stroke.rule, .h = row_h }, theme.metric.plaque.rip, fire);
u.text(.mono_bold, size, m.side, baseline(y), "rip", gold.on_solid);
const fl = theme.metric.flags;
- var x = w - m.side - @as(f32, flags.len) * fl.pitch + 10;
+ const x = w - m.side - @as(f32, flags.len) * fl.pitch + 10;
// Where execution is changes with the advance: the old value goes as the new one comes, over it.
const before = was orelse RipWas{ .moment = moment, .pc = pc, .eflags = eflags };
if (before.pc != pc and before.going < 1) {
_ = chain(u.faded(1 - before.going), m.chain_x, y, before.moment, before.pc, x - 16, .{});
_ = chain(u.faded(before.going), m.chain_x, y, moment, pc, x - 16, .{});
} else _ = chain(u, m.chain_x, y, moment, pc, x - 16, .{});
+ ripFlags(u, x, y, eflags, changed, held, read, read_shows, before);
+}
+
+/// The flag chips on their own row, for narrower live register panes.
+pub fn ripFlags(u: ui.Ui, start: f32, y: f32, eflags: u64, changed: u64, held: f32, read: u64, read_shows: f32, before: RipWas) void {
+ const fl = theme.metric.flags;
+ var x = start;
for (flags) |flag| {
const set = eflags >> flag.bit & 1 != 0;
// A flag the step sets or clears crossfades as it lands (`flip`).
@@ -429,7 +436,7 @@ pub fn line(u: ui.Ui, y: f32, w: f32, number: u32, widen: f32, text: []const u8,
u.text(if (on) .mono_bold else .mono, size, m.line_number_end + widen - @as(f32, @floatFromInt(num.len)) * adv, baseline(y), num, if (on) gold.on_solid else t.faint);
// Cut as much sooner as the row is narrower than its column (a pane's strip takes 48: four characters).
const cut: usize = @intFromFloat(@max(theme.layout.program.w - w, 0) / adv);
- const limit: usize = m.source_chars - @as(usize, @intFromFloat(widen / adv)) - cut;
+ const limit: usize = m.source_chars -| @as(usize, @intFromFloat(widen / adv)) -| cut;
const end = @min(text.len, limit);
var i: usize = 0;
while (i < end) {
diff --git a/anim/src/source.zig b/anim/src/source.zig
index aedbb3e..48b361f 100644
--- a/anim/src/source.zig
+++ b/anim/src/source.zig
@@ -279,10 +279,16 @@ fn whereIs(u: ui.Ui, rec: *const Recording, i: u64) []const u8 {
}
/// A source ready to draw: a class for each byte, and where each line is.
-const Text = struct {
+pub const Text = struct {
bytes: []const u8,
styles: []const u8,
lines: []const [2]usize,
+
+ /// `bytes` is borrowed; the caller keeps it alive for this prepared text.
+ pub fn deinit(text: Text) void {
+ gpa.free(text.styles);
+ gpa.free(text.lines);
+ }
};
/// Made once for each source and kept: a scene draws the same few.
@@ -294,9 +300,11 @@ fn prepared(source: []const u8, file: []const u8) ?*const Text {
return &texts.items[texts.items.len - 1];
}
-fn prepare(source: []const u8, file: []const u8) !Text {
+pub fn prepare(source: []const u8, file: []const u8) !Text {
var analysis = try pardes.analyzeSource(gpa, file, source, false, true);
+ errdefer analysis.deinit(gpa);
var lines: std.ArrayList([2]usize) = .empty;
+ defer lines.deinit(gpa);
var start: usize = 0;
while (start < source.len) {
const end = std.mem.indexOfScalarPos(u8, source, start, '\n') orelse source.len;
@@ -321,10 +329,10 @@ test "a source is cut into lines and classed byte by byte" {
try std.testing.expectEqual(@as(usize, 3), text.lines.len);
try std.testing.expectEqualStrings(" return 0; // done", source[text.lines[1][0]..text.lines[1][1]]);
const at = std.mem.indexOf(u8, source, "return").?;
- try std.testing.expectEqual(pardes.Syn.keyword, @as(pardes.Syn, @enumFromInt(text.styles[at])));
- try std.testing.expectEqual(pardes.Syn.number, @as(pardes.Syn, @enumFromInt(text.styles[at + 7])));
- try std.testing.expectEqual(pardes.Syn.comment, @as(pardes.Syn, @enumFromInt(text.styles[at + 10])));
+ try std.testing.expectEqual(pardes.Syn.keyword, @as(pardes.Syn, @fromBackingInt(@intCast(text.styles[at]))));
+ try std.testing.expectEqual(pardes.Syn.number, @as(pardes.Syn, @fromBackingInt(@intCast(text.styles[at + 7]))));
+ try std.testing.expectEqual(pardes.Syn.comment, @as(pardes.Syn, @fromBackingInt(@intCast(text.styles[at + 10]))));
// rows.line reads these classes by number.
- try std.testing.expectEqual(@as(u8, 1), @intFromEnum(pardes.Syn.keyword));
- try std.testing.expectEqual(@as(u8, 4), @intFromEnum(pardes.Syn.comment));
+ try std.testing.expectEqual(@as(u8, 1), @backingInt(pardes.Syn.keyword));
+ try std.testing.expectEqual(@as(u8, 4), @backingInt(pardes.Syn.comment));
}
diff --git a/anim/src/ui.zig b/anim/src/ui.zig
index 2b697bf..282a24f 100644
--- a/anim/src/ui.zig
+++ b/anim/src/ui.zig
@@ -30,6 +30,10 @@ pub var chrome: f32 = 1;
/// A clip every other stays inside, in canvas pixels: a map column squeezing into its strip.
pub var bound: ?sk.Rect = null;
+/// Optional address interaction for native viewers, in canvas coordinates.
+pub var address_hit: ?struct { ctx: *anyopaque, emit: *const fn (*anyopaque, u64, sk.Rect) void } = null;
+var address_clip: ?sk.Rect = null;
+
/// What a map drawn for the strips holds, in its own units (`map.strip`
/// draws it in no transform but its own): text runs by their middle, the
/// marks by their row's middle, the arcs by their rows' tops.
@@ -338,6 +342,7 @@ pub const Ui = struct {
if (lead > 0) u.text(a.face, size, x, baseline, d[0..lead], mix(a.ink, theme.color.page, theme.metric.context.lead_alpha));
u.text(a.face, size, x + @as(f32, @floatFromInt(lead)) * adv, baseline, d[lead..], a.ink);
const end = x + @as(f32, @floatFromInt(d.len)) * adv;
+ u.hitAddress(addr, .{ .x = x, .y = baseline - size, .w = end - x, .h = theme.metric.context.row });
if (a.rwx) u.fill(.{ .x = x, .y = baseline + 3, .w = end - x, .h = theme.stroke.rule }, a.ink);
if (a.name.len == 0) return end;
const name = symbol(u, a.name);
@@ -355,6 +360,7 @@ pub const Ui = struct {
const shown = Value.of(v, pointer);
u.text(ink.face, size, x, baseline, u.print("{s}{s}", .{ shown.prefix, shown.digits() }), ink.ink);
const end = x + shown.width();
+ if (pointer) u.hitAddress(v, .{ .x = x, .y = baseline - size, .w = end - x, .h = theme.metric.context.row });
if (shown.decimal) u.text(.mono, size, end + 8, baseline, u.print("{d}", .{v}), theme.color.text.faint);
return end;
}
@@ -620,13 +626,29 @@ pub const Ui = struct {
const y0 = @max(c.y, o.y);
c = .{ .x = x0, .y = y0, .w = @max(@min(c.x + c.w, o.x + o.w) - x0, 0), .h = @max(@min(c.y + c.h, o.y + o.h) - y0, 0) };
}
+ address_clip = c;
u.f.clip(c);
}
pub fn unclip(u: Ui) void {
+ address_clip = bound;
if (bound) |b| u.f.clip(b) else u.f.clip(null);
}
+ pub fn hitAddress(u: Ui, addr: u64, r: Rect) void {
+ const hook = address_hit orelse return;
+ if (strokes or mapping or u.at.pose.opacity < 0.1) return;
+ const a = u.point(r.x, r.y);
+ const b = u.point(r.x + r.w, r.y + r.h);
+ var box: sk.Rect = .{ .x = a[0], .y = a[1], .w = b[0] - a[0], .h = b[1] - a[1] };
+ if (address_clip) |clip_| {
+ const x = @max(box.x, clip_.x);
+ const y = @max(box.y, clip_.y);
+ box = .{ .x = x, .y = y, .w = @max(0, @min(box.x + box.w, clip_.x + clip_.w) - x), .h = @max(0, @min(box.y + box.h, clip_.y + clip_.h) - y) };
+ }
+ if (box.w > 0 and box.h > 0) hook.emit(hook.ctx, addr, box);
+ }
+
/// A path through `points` with corners of radius `radius`, `progress`
/// of its length drawn from its start (a tie drawing head first, a node's
/// arrow growing to its target), dashed or whole, with a filled head at