mouseWheelBatch
This helps backends guess at the mouse type to pass to addEventMouseWheel.
Backends can call this, passing the raw wheel amount, and getting back the smallest raw wheel amount seen in this batch. First call you get the same thing back, batch resets if there is 1 second without data.
Parameters
- self:*Self
- *Self
- dir:dvui.enums.Direction
- dvui.enums.Direction
- raw_delta:f32
- f32
Source
Implementation
pub fn mouseWheelBatch(self: *Self, dir: dvui.enums.Direction, raw_delta: f32) f32 {
//dvui.log.debug("mouseWheelBatch: {any} {d}", .{ dir, raw_delta });
const delta_abs = @abs(raw_delta);
const now = std.Io.Clock.awake.now(dvui.io).nanoseconds;
if (now - self.mouse_type_last_wheel_ns > std.time.ns_per_s) {
self.mouse_type_min = .{ 99999, 99999 };
}
self.mouse_type_last_wheel_ns = now;
const ax: usize = if (dir == .horizontal) 0 else 1;
self.mouse_type_min[ax] = @min(self.mouse_type_min[ax], delta_abs);
return self.mouse_type_min[ax];
}