DVUI

Parameters

#
self:*FocusGroupWidget
*FocusGroupWidget

Source

Implementation

#
pub fn deinit(self: *FocusGroupWidget) void {
    defer if (dvui.widgetIsAllocated(self)) dvui.widgetFree(self);
    defer self.* = undefined;

    const cw = dvui.currentWindow();

    // only deregister ourselves if we were the one registered
    // also do unhandled arrow events
    if (cw.subwindows.get(dvui.subwindowCurrentId())) |sw| {
        if (sw.focus_group == self) {
            sw.focus_group = null;
            //std.debug.print("subwindow {x} focus group null\n", .{sw.id.asU64()});

            const focus_id = dvui.lastFocusedIdInFrameSince(self.last_focus);
            if (focus_id) |fid| dvui.dataSet(null, self.data().id, "_remember_focus", fid);
            const evts = dvui.events();
            for (evts) |*e| {
                if (!dvui.eventMatch(e, .{ .id = self.data().id, .focus_id = focus_id, .r = self.data().borderRectScale().r }))
                    continue;

                switch (e.evt) {
                    .key => |ke| {
                        if (ke.action != .down and ke.action != .repeat)
                            continue;

                        const key_dir = self.init_opts.nav_key_dir;
                        if ((ke.code == .up and key_dir != .horizontal) or (ke.code == .left and key_dir != .vertical)) {
                            e.handle(@src(), self.data());
                            self.focusPrev(e.num);
                            if (dvui.focusedWidgetId() == null) {
                                if (self.init_opts.wrap) {
                                    // wrap around
                                    self.focusPrev(e.num);
                                } else {
                                    // go back to where we were
                                    self.focusNext(e.num);
                                }
                            }
                        } else if ((ke.code == .down and key_dir != .horizontal) or (ke.code == .right and key_dir != .vertical)) {
                            e.handle(@src(), self.data());
                            self.focusNext(e.num);
                            if (dvui.focusedWidgetId() == null) {
                                if (self.init_opts.wrap) {
                                    // wrap around
                                    self.focusNext(e.num);
                                } else {
                                    // go back to where we were
                                    self.focusPrev(e.num);
                                }
                            }
                        }
                    },
                    else => {},
                }
            }
        }
    }

    dvui.dataSetSlice(null, self.data().id, "_tab_prev", self.tab_index.items);
    self.tab_index.deinit(cw.arena());

    if (self.child_rect_union) |u| {
        dvui.dataSet(null, self.data().id, "_rect", u);
    }
    dvui.parentReset(self.data().id, self.data().parent);
}