From 65b543a059673eb49837b63b87f291e8b6a55152 Mon Sep 17 00:00:00 2001 From: David Vanderson Date: Thu, 16 Apr 2026 20:36:39 -0400 Subject: [PATCH] reduce motion * add global reduce_motion bool * add checkbox to debug window When reduce_motion is true, animation() rewrites the end_time to be start_time + 1, making the animation expire the next frame (and causing an immediate next frame). Timers are exempted. --- src/Debug.zig | 6 ++++-- src/dvui.zig | 6 +++++- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/src/Debug.zig b/src/Debug.zig index 2d77b3d9..1744f00a 100644 --- a/src/Debug.zig +++ b/src/Debug.zig @@ -155,9 +155,11 @@ pub fn show(self: *Debug) void { } var wd: dvui.WidgetData = undefined; - _ = dvui.checkbox(@src(), &dvui.currentWindow().debug.touch_simulate_events, "Simulate Touch With Mouse", .{ .data_out = &wd }); + _ = dvui.checkbox(@src(), &dvui.currentWindow().debug.touch_simulate_events, "Simulate Touch", .{ .data_out = &wd }); - dvui.tooltip(@src(), .{ .active_rect = wd.borderRectScale().r }, "mouse drag will scroll\ntext layout/entry have draggables and menu", .{}, .{}); + dvui.tooltip(@src(), .{ .active_rect = wd.borderRectScale().r, .position = .vertical }, "mouse drag will scroll\ntext layout/entry have draggables and menu", .{}, .{}); + + _ = dvui.checkbox(@src(), &dvui.reduce_motion, "Reduce Motion", .{}); } _ = dvui.spacer(@src(), .{ .min_size_content = .all(4) }); diff --git a/src/dvui.zig b/src/dvui.zig index 1c23144d..ecb82b4f 100644 --- a/src/dvui.zig +++ b/src/dvui.zig @@ -293,6 +293,8 @@ pub const useTreeSitter = @import("default_options").tree_sitter; /// The amount of logical pixels to scroll per "tick" of the scroll wheel pub var scroll_speed: f32 = 40; +pub var reduce_motion: bool = false; + /// Used as a default maximum in various places: /// * Options.max_size_content /// * Font.textSizeEx max_width @@ -1829,7 +1831,9 @@ pub const Animation = struct { pub fn animation(id: Id, key: []const u8, a: Animation) void { var cw = currentWindow(); const h = id.update(key); - cw.animations.put(cw.gpa, h, a) catch |err| switch (err) { + var aa = a; + if (reduce_motion) aa.end_time = aa.start_time + 1; + cw.animations.put(cw.gpa, h, aa) catch |err| switch (err) { error.OutOfMemory => { log.err("animation got {any} for id {x} key {s}\n", .{ err, id, key }); }, -- knotmirror 0.0.1