DVUI

addEventMouseWheel

Add a mouse wheel event. Positive ticks means scrolling up / scrolling right.

If the shift key is being held, any vertical scroll will be transformed to horizontal.

When mouse_type is non-null, it sets what dvui.mouseType returns. See mouseWheelBatch.

This can be called outside begin/end. You should add all the events for a frame either before begin() or just after begin() and before calling normal dvui widgets. end() clears the event list.

Parameters

#
self:*Self
*Self
ticks:f32
f32
dir:dvui.enums.Direction
dvui.enums.Direction
mouse_type:?dvui.enums.MouseType
?dvui.enums.MouseType

Source

Implementation

#
pub fn addEventMouseWheel(self: *Self, ticks: f32, dir: dvui.enums.Direction, mouse_type: ?dvui.enums.MouseType) std.mem.Allocator.Error!bool {
    if (mouse_type) |mt| self.mouse_type = mt;

    self.positionMouseEventRemove();

    const winId = self.subwindows.windowFor(self.mouse_pt);

    //std.debug.print("mouse wheel {d}\n", .{ticks});

    self.event_num += 1;
    try self.events.append(self.arena(), Event{
        .num = self.event_num,
        .evt = .{
            .mouse = .{
                .action = if (dir == .vertical)
                    if (self.modifiers.shiftOnly())
                        .{ .wheel_x = ticks }
                    else
                        .{ .wheel_y = ticks }
                else
                    .{ .wheel_x = ticks },
                .button = .none,
                .mod = self.modifiers,
                .p = self.mouse_pt,
                .floating_win = winId,
            },
        },
    });

    const ret = (self.data().id != winId);
    try self.positionMouseEventAdd();
    return ret;
}