DVUI

processEventsAfter

Parameters

#
self:*FloatingWindowWidget
*FloatingWindowWidget

Source

Implementation

#
pub fn processEventsAfter(self: *FloatingWindowWidget) void {
    const rs = self.data().rectScale();
    // duplicate processEventsBefore because you could have a click down,
    // motion, and up in same frame and you wouldn't know you needed to do
    // anything until you got capture here
    //
    // bottom_right corner happens in processEventsBefore
    const evts = dvui.events();
    for (evts) |*e| {
        if (!dvui.eventMatch(e, .{ .id = self.data().id, .r = rs.r, .cleanup = true }))
            continue;

        switch (e.evt) {
            .mouse => |me| {
                switch (me.action) {
                    .focus => {
                        e.handle(@src(), self.data());
                        // unhandled focus (clicked on nothing)
                        dvui.focusWidget(null, null, null);
                    },
                    .press => {
                        if (me.button.pointer()) {
                            const dp = dragPart(me, rs);
                            if (dp == .middle) {
                                if (!self.drag_area.contains(me.p)) continue;
                            } else {
                                if (self.init_options.resize == .none) continue;
                            }
                            e.handle(@src(), self.data());
                            // capture and start drag
                            dvui.captureMouse(self.data(), e.num);
                            self.drag_part = dp;
                            dvui.dragPreStart(e.evt.mouse.button, e.evt.mouse.p, .{ .cursor = self.drag_part.?.cursor() });
                        }
                    },
                    .release => {
                        if (me.button.pointer() and dvui.captured(self.data().id)) {
                            e.handle(@src(), self.data());
                            dvui.captureMouse(null, e.num); // stop drag and capture
                            dvui.dragEnd();
                        }
                    },
                    .motion => {
                        if (dvui.captured(self.data().id)) {
                            // move if dragging
                            if (dvui.dragging(me.p, null)) |dps| {
                                const p = me.p.plus(dvui.dragOffset()).toNatural();
                                self.dragAdjust(p, dps.toNatural(), self.drag_part.?);

                                e.handle(@src(), self.data());
                                dvui.refresh(null, @src(), self.data().id);
                            }
                        }
                    },
                    .position => {
                        const dp = dragPart(me, rs);
                        if (dp == .middle) {
                            if (!self.drag_area.contains(me.p)) continue;
                        } else {
                            if (self.init_options.resize == .none) continue;
                        }
                        dvui.cursorSet(dp.cursor());
                    },
                    else => {},
                }
            },
            .key => |ke| {
                // catch any tabs that weren't handled by widgets
                if ((ke.action == .down or ke.action == .repeat) and ke.matchBind("next_widget")) {
                    e.handle(@src(), self.data());
                    dvui.tabIndexNext(e.num);
                }

                if ((ke.action == .down or ke.action == .repeat) and ke.matchBind("prev_widget")) {
                    e.handle(@src(), self.data());
                    dvui.tabIndexPrev(e.num);
                }
            },
            else => {},
        }
    }
}