summaryrefslogtreecommitdiff
path: root/anim/src/ui.zig
diff options
context:
space:
mode:
Diffstat (limited to 'anim/src/ui.zig')
-rw-r--r--anim/src/ui.zig25
1 files changed, 25 insertions, 0 deletions
diff --git a/anim/src/ui.zig b/anim/src/ui.zig
index 282a24f..2c78c04 100644
--- a/anim/src/ui.zig
+++ b/anim/src/ui.zig
@@ -57,6 +57,17 @@ pub const Collected = struct {
};
pub var collected: Collected = .{};
+/// A selected occurrence leads, then its matches arrive in reading order.
+pub fn matchProgress(seconds: f32, rank: usize, delay: f32, duration: f32) f32 {
+ return theme.ease(.standard, std.math.clamp((seconds - @as(f32, @floatFromInt(rank)) * delay) / @max(0.001, duration), 0, 1));
+}
+
+test "matching highlights reveal the selection before its peers" {
+ try std.testing.expect(matchProgress(0.05, 0, 0.08, 0.16) > 0);
+ try std.testing.expectEqual(@as(f32, 0), matchProgress(0.05, 1, 0.08, 0.16));
+ try std.testing.expectEqual(@as(f32, 1), matchProgress(1, 3, 0.08, 0.16));
+}
+
/// 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;
@@ -635,6 +646,20 @@ pub const Ui = struct {
if (bound) |b| u.f.clip(b) else u.f.clip(null);
}
+ pub fn matchHighlight(u: Ui, r: Rect, seconds: f32, rank: usize, options: struct {
+ color: Color = .hex(0x65c9d8),
+ selected_color: Color = .hex(0xe6bd70),
+ delay: f32 = 0.075,
+ duration: f32 = 0.16,
+ opacity: f32 = 0.23,
+ }) void {
+ const progress = matchProgress(seconds, rank, options.delay, options.duration);
+ const c = if (rank == 0) options.selected_color else options.color;
+ const box: Rect = .{ .x = r.x, .y = r.y, .w = r.w * progress, .h = r.h };
+ u.faded(options.opacity * progress).fill(box, c);
+ u.faded(progress * 0.6).line(.{ r.x, r.y + r.h - 1 }, .{ r.x + box.w, r.y + r.h - 1 }, c, 1);
+ }
+
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;