DVUI

addEventKey

Add a keyboard event (key up/down/repeat) to the dvui event list.

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
event:Event.Key
Event.Key

Source

Implementation

#
pub fn addEventKey(self: *Self, event: Event.Key) std.mem.Allocator.Error!bool {
    if (dvui.debug.target == .mouse_until_esc and event.action == .down and event.code == .escape) {
        // an escape will stop the debug stuff from following the mouse,
        // but need to stop it at the end of the frame when we've gotten
        // the info
        dvui.debug.target = .mouse_quitting;
        return true;
    }

    self.positionMouseEventRemove();

    self.modifiers = event.mod;

    self.event_num += 1;
    try self.events.append(self.arena(), Event{
        .num = self.event_num,
        .evt = .{ .key = event },
        .target_windowId = self.subwindows.focused_id,
        .target_widgetId = if (self.subwindows.focused()) |sw| sw.focused_widget_id else null,
    });

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