DVUI

addEventMouseMotion

Add a mouse motion event that the mouse is now at physical pixel pt. This is only for a mouse - for touch motion use addEventTouchMotion().

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
opts:AddEventMouseMotionOptions
AddEventMouseMotionOptions

Source

Implementation

#
pub fn addEventMouseMotion(self: *Self, opts: AddEventMouseMotionOptions) std.mem.Allocator.Error!bool {
    self.positionMouseEventRemove();

    //log.debug("mouse motion {d} {d} -> {d} {d}", .{ x, y, newpt.x, newpt.y });
    const dp = opts.pt.diff(self.mouse_pt);
    self.mouse_pt = opts.pt;
    const winId = self.subwindows.windowFor(self.mouse_pt);

    // maybe could do focus follows mouse here
    // - generate a .focus event here instead of just doing focusWindow(winId, null);
    // - how to make it optional?

    const target_id = opts.target_id orelse if (self.capture) |cap| cap.id else null;

    self.event_num += 1;
    try self.events.append(self.arena(), Event{
        .num = self.event_num,
        .target_widgetId = target_id,
        .evt = .{
            .mouse = .{
                .action = .{ .motion = dp },
                .button = if (dvui.debug.touch_simulate_events and dvui.debug.touch_simulate_down) .touch0 else .none,
                .mod = self.modifiers,
                .p = self.mouse_pt,
                .floating_win = winId,
            },
        },
    });

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