summaryrefslogtreecommitdiff
path: root/anim/src/ui.zig
diff options
context:
space:
mode:
authorGabriel Schneider <[email protected]>2026-11-11 14:43:13 -0300
committerGabriel Schneider <[email protected]>2026-11-11 16:17:33 -0300
commit3093eb55ac4a7054f51f06ea2786b5f9c9ec73f6 (patch)
treef1bc91879a447f178dfaba39d0df107d01e557bd /anim/src/ui.zig
parenta72831d5c322078260314c305ddd940e4967947d (diff)
downloadcomputeranim-3093eb55ac4a7054f51f06ea2786b5f9c9ec73f6.tar.gz
computeranim-3093eb55ac4a7054f51f06ea2786b5f9c9ec73f6.zip
canim: a minimap in each pane; source wherever it can be had, libc's included
From the user. Each pane with more than it shows carries a strip of its whole column at its right edge, the pane's window outlined and what happens off it marked there; the corner minimap is gone and the dive folds each column of the map into its pane's strip. The source panel follows the pc into any file the build has: glibc's own, from the distro's debuginfod by an optional step that caches them by build id (zig build sources; nothing else touches the network), and musl's, from Zig's lib directory. The syscalls scene shows open64.c on the way down, and a new scene follows the same call through a Zig-built musl. A graph's counts and inks are as of the moment shown. Co-Authored-By: Claude Fable 5.2 <[email protected]> Claude-Session: https://claude.ai/code/session_016Y9MNCKgYCGiANnEwcEQxa
Diffstat (limited to 'anim/src/ui.zig')
-rw-r--r--anim/src/ui.zig88
1 files changed, 64 insertions, 24 deletions
diff --git a/anim/src/ui.zig b/anim/src/ui.zig
index bcefff3..589bfb6 100644
--- a/anim/src/ui.zig
+++ b/anim/src/ui.zig
@@ -17,17 +17,49 @@ pub const Vec = sk.math.Vec;
pub const scale = 1280.0 / @as(comptime_float, theme.canvas.width);
/// While the map's panels draw (`map.zig`): they publish their rows, not
-/// their windows and places. `strokes`: the minimap, a twentieth of the
-/// map, where text is a stroke a pixel high in its ink at 45% toward the
-/// page and the marks are blocks a few pixels across.
+/// their windows and places. `strokes`: the map drawn for the panes'
+/// strips (`map.strip`), where nothing shows and what a strip draws is
+/// collected (`collected`): each run of text, the marks, the arcs, the
+/// blocks' first rows.
/// shortcut: process-wide, for one scene drawn at a time; two players at once want it on the frame.
pub var mapping = false;
pub var strokes = false;
/// How much of a panel's tag and rules shows: less while it dives out of
/// its window on the map (`context.at` sets it for the panel it hands out).
pub var chrome: f32 = 1;
-/// The minimap's pixel, in the map's units.
-const px = 20;
+/// A clip every other stays inside, in canvas pixels: a map column squeezing into its strip.
+pub var bound: ?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.
+pub const Collected = struct {
+ pub const Run = struct { x0: f32, x1: f32, y: f32, ink: Color };
+ pub const Kind = enum { current, struck, read, held, tick };
+ pub const Mark = struct { x: f32, y: f32, kind: Kind, shows: f32 };
+ pub const Arc = struct { x: f32, from: f32, to: f32, ink: Color };
+ runs: [12288]Run = undefined,
+ n_runs: usize = 0,
+ marks: [1024]Mark = undefined,
+ n_marks: usize = 0,
+ arcs: [96]Arc = undefined,
+ n_arcs: usize = 0,
+
+ pub fn reset(c: *Collected) void {
+ c.n_runs = 0;
+ c.n_marks = 0;
+ c.n_arcs = 0;
+ }
+};
+pub var collected: Collected = .{};
+
+/// A mark on the row whose middle is `y` (in `u`), for the strips; `shows` of it.
+pub fn collectMark(u: Ui, x: f32, y: f32, kind: Collected.Kind, shows: f32) void {
+ if (!strokes or shows <= 0 or collected.n_marks == collected.marks.len) return;
+ const p = u.point(x, y);
+ collected.marks[collected.n_marks] = .{ .x = p[0], .y = p[1], .kind = kind, .shows = shows * u.at.pose.opacity };
+ collected.n_marks += 1;
+}
/// Adds `data` (a component: something with `draw(f, at)`) to the scene,
/// its origin at design `x, y` and its units the design's. Like any
@@ -158,9 +190,8 @@ pub const Ui = struct {
u.f.fill(sk.Rect{ .x = x, .y = y, .w = @round(b[0]) - x, .h = @round(b[1]) - y }, u.at.faded(rgb(c)));
}
- /// A stroke `w` wide, wholly inside `r` (on the minimap, a pixel at least).
- pub fn frame(u: Ui, r: Rect, c: anytype, w_: f32) void {
- const w = if (strokes) @max(w_, px) else w_;
+ /// A stroke `w` wide, wholly inside `r`.
+ pub fn frame(u: Ui, r: Rect, c: anytype, w: f32) void {
u.fill(.{ .x = r.x, .y = r.y, .w = r.w, .h = w }, c);
u.fill(.{ .x = r.x, .y = r.y + r.h - w, .w = r.w, .h = w }, c);
u.fill(.{ .x = r.x, .y = r.y + w, .w = w, .h = r.h - 2 * w }, c);
@@ -179,9 +210,14 @@ pub const Ui = struct {
pub fn text(u: Ui, face: Face, size: f32, x: f32, baseline: f32, bytes: []const u8, c: anytype) void {
if (bytes.len == 0) return;
if (strokes) {
- // A run of text: a stroke as long as it is, through its capitals' middle.
- if (std.mem.indexOfNone(u8, bytes, " ") == null) return;
- return u.fill(.{ .x = x, .y = baseline - 0.36 * size - px / 2, .w = u.width(face, size, bytes), .h = px }, mix(c, theme.color.page, 0.45));
+ // A run of text, for a strip: where it starts and ends, through its capitals' middle, and its ink.
+ if (std.mem.indexOfNone(u8, bytes, " ") == null or collected.n_runs == collected.runs.len) return;
+ const lead = std.mem.indexOfNone(u8, bytes, " ").?;
+ const a = u.point(x + u.width(face, size, bytes[0..lead]), baseline - 0.36 * size);
+ const b = u.point(x + u.width(face, size, std.mem.trimEnd(u8, bytes, " ")), baseline);
+ collected.runs[collected.n_runs] = .{ .x0 = a[0], .x1 = b[0], .y = a[1], .ink = u.at.faded(rgb(c)) };
+ collected.n_runs += 1;
+ return;
}
// Go's ascent is 0.945 em; JetBrains Mono's, which every monospace is set in, 1.02.
const at = u.point(x, baseline - @as(f32, if (set(face, size) == face) 0.945 else 1.02) * size);
@@ -254,6 +290,11 @@ pub const Ui = struct {
u.text(.sans, micro, w - 10 - u.width(.sans, micro, note), theme.metric.context.tag - 6, note, theme.color.text.faint);
}
+ /// A tag's title drawn apart from its panel: for one that crossfades with another.
+ pub fn tagTitle(u: Ui, title: []const u8, focus: bool) void {
+ u.text(.sans_medium, theme.size.sans.tag, 28, theme.metric.context.tag - 6, title, if (focus) theme.color.text.primary else theme.color.text.dim);
+ }
+
fn panelChrome(u: Ui, w: f32, h: f32, title: []const u8, focus: bool, note: []const u8, legend: []const Legend) Rect {
const options = .{ .focus = focus, .note = note, .legend = legend };
const m = theme.metric.context;
@@ -383,11 +424,8 @@ pub const Ui = struct {
const w = theme.mark(.write);
const m = theme.metric.context;
if (strokes) {
- // On the minimap: a strike a block 3 pixels across at the value's start; held, a pixel.
- const mid = r.y + r.h / 2;
- if (h.level >= 1 and h.solid * h.in > 0) {
- u.faded(h.solid * h.in).fill(.{ .x = r.x, .y = mid - 1.5 * px, .w = 3 * px, .h = 3 * px }, w.solid);
- } else if (h.level * h.corner > 0) u.faded(h.level * h.corner).fill(.{ .x = r.x, .y = mid - px / 2, .w = px, .h = px }, w.solid);
+ // For a strip: a strike, or held.
+ if (h.level >= 1 and h.solid * h.in > 0) collectMark(u, r.x, r.y + r.h / 2, .struck, h.solid * h.in) else collectMark(u, r.x, r.y + r.h / 2, .held, h.level * h.corner);
return null;
}
if (h.arm > 0) u.faded(h.arm).frame(.{ .x = r.x - 6, .y = r.y, .w = r.w + 12, .h = r.h }, w.solid, m.read_frame);
@@ -411,10 +449,7 @@ pub const Ui = struct {
/// `read` in the context: a 2-unit frame in read's colour, 6 out at
/// the sides, no fill; `shows` of it (0 to 1: it fades in and out).
pub fn read(u: Ui, r: Rect, shows: f32) void {
- if (strokes) {
- if (shows > 0) u.faded(shows).frame(.{ .x = r.x, .y = r.y + r.h / 2 - 1.5 * px, .w = 3 * px, .h = 3 * px }, theme.mark(.read).solid, px);
- return;
- }
+ if (strokes) return collectMark(u, r.x, r.y + r.h / 2, .read, shows);
if (shows > 0) u.faded(shows).frame(.{ .x = r.x - 6, .y = r.y, .w = r.w + 12, .h = r.h }, theme.mark(.read).solid, theme.metric.context.read_frame);
}
@@ -450,8 +485,7 @@ pub const Ui = struct {
/// `w` wide at its left, its edges out `out` units (the fire).
pub fn current(u: Ui, r: Rect, w: f32, out: f32) void {
const gold = theme.mark(.current);
- // On the minimap: a gold stroke across the column, 2 pixels high.
- if (strokes) return u.fill(.{ .x = r.x, .y = r.y + r.h / 2 - px, .w = r.w, .h = 2 * px }, gold.solid);
+ if (strokes) return collectMark(u, r.x, r.y + r.h / 2, .current, 1);
u.fill(r, gold.ember);
u.fill(.{ .x = r.x - out, .y = r.y - out, .w = w + 2 * out, .h = r.h + 2 * out }, gold.solid);
}
@@ -566,11 +600,17 @@ pub const Ui = struct {
pub fn clip(u: Ui, r: Rect) void {
const a = u.point(r.x, r.y);
const b = u.point(r.x + r.w, r.y + r.h);
- u.f.clip(sk.Rect{ .x = @round(a[0]), .y = @round(a[1]), .w = @round(b[0]) - @round(a[0]), .h = @round(b[1]) - @round(a[1]) });
+ var c: sk.Rect = .{ .x = @round(a[0]), .y = @round(a[1]), .w = @round(b[0]) - @round(a[0]), .h = @round(b[1]) - @round(a[1]) };
+ if (bound) |o| {
+ const x0 = @max(c.x, o.x);
+ 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) };
+ }
+ u.f.clip(c);
}
pub fn unclip(u: Ui) void {
- u.f.clip(null);
+ if (bound) |b| u.f.clip(b) else u.f.clip(null);
}
/// A path through `points` with corners of radius `radius`, `progress`