diff options
Diffstat (limited to 'anim/src/ui.zig')
| -rw-r--r-- | anim/src/ui.zig | 22 |
1 files changed, 22 insertions, 0 deletions
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 |
