DVUI

processEvents

Parameters

#
self:*ContextWidget
*ContextWidget

Source

Implementation

#
pub fn processEvents(self: *ContextWidget) void {
    // Touch presses in our rect: capture here first so widgets underneath wait for release.
    if (!self.focused) {
        for (dvui.events()) |*e| {
            if (e.handled or e.evt != .mouse) continue;
            const me = e.evt.mouse;
            if (me.action == .press and me.button.touch() and self.init_options.rect.contains(me.p)) {
                // touch down inside our rect
                self.hold = .{
                    .pending = true,
                    .held = 0,
                    .press_p = me.p,
                    .button = me.button,
                    .event_num = e.num,
                };
            } else if (self.hold.pending and me.action == .release and me.button.touch()) {
                // touch up anywhere
                self.hold.pending = false;
            } else if (self.hold.pending and me.action == .motion and me.button.touch()) {
                const dp = me.p.diff(self.hold.press_p);
                const dps = dp.scale(1 / dvui.windowNaturalScale(), Point.Natural);
                if (@abs(dps.x) > dvui.Dragging.threshold or @abs(dps.y) > dvui.Dragging.threshold) {
                    self.hold.pending = false;
                }
            }
        }
    }

    const evts = dvui.events();
    for (evts) |*e| {
        if (!dvui.eventMatchSimple(e, self.data()))
            continue;

        self.processEvent(e);
    }

    self.updateHold();
}