diff options
Diffstat (limited to 'anim/src/map.zig')
| -rw-r--r-- | anim/src/map.zig | 48 |
1 files changed, 32 insertions, 16 deletions
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; |
