processEvent
Parameters
- self:*KeyboardNavigation
- *KeyboardNavigation
- e:*Event
- *Event
- grid:*GridWidget
- *GridWidget
- cellConverter:fn ( grid: *GridWidget, point: Point.Physical, ) ?Cell
- fn ( grid: *GridWidget, point: Point.Physical, ) ?Cell
Source
Implementation
pub fn processEvent(self: *KeyboardNavigation, e: *Event, grid: *GridWidget, cellConverter: fn (
grid: *GridWidget,
point: Point.Physical,
) ?Cell) void {
defer self.enforceCursorLimits();
switch (e.evt) {
.key => |*ke| {
if (!self.is_focused or e.handled) return;
if (ke.action == .down or ke.action == .repeat) {
if (ke.matchKeyBind(self.navigation_keys.first)) {
e.handle(@src(), grid.data());
self.scrollTo(0, 0);
} else if (ke.matchKeyBind(self.navigation_keys.last)) {
e.handle(@src(), grid.data());
self.scrollTo(self.num_cols - 1, self.num_rows - 1);
} else if (ke.matchKeyBind(self.navigation_keys.col_first)) {
e.handle(@src(), grid.data());
self.scrollTo(0, self.cursor.row_num);
} else if (ke.matchKeyBind(self.navigation_keys.col_last)) {
e.handle(@src(), grid.data());
self.scrollTo(self.num_cols - 1, self.cursor.row_num);
} else if (ke.matchKeyBind(self.navigation_keys.scroll_up)) {
e.handle(@src(), grid.data());
self.scrollBy(0, -self.num_scroll);
grid.bsi.scrollPageUp(.vertical);
} else if (ke.matchKeyBind(self.navigation_keys.scroll_down)) {
e.handle(@src(), grid.data());
self.scrollBy(0, self.num_scroll);
grid.bsi.scrollPageDown(.vertical);
} else if (ke.matchKeyBind(self.navigation_keys.up)) {
e.handle(@src(), grid.data());
self.scrollBy(0, -1);
} else if (ke.matchKeyBind(self.navigation_keys.down)) {
e.handle(@src(), grid.data());
self.scrollBy(0, 1);
} else if (ke.matchKeyBind(self.navigation_keys.left)) {
e.handle(@src(), grid.data());
if (self.tab_out and self.cursor.eqColRow(0, 0)) {
dvui.tabIndexPrev(e.num);
self.is_focused = false;
} else {
self.scrollBy(-1, 0);
}
} else if (ke.matchKeyBind(self.navigation_keys.right)) {
e.handle(@src(), grid.data());
if (self.tab_out and self.cursor.eqColRow(self.num_cols - 1, self.num_rows - 1)) {
dvui.tabIndexNext(e.num);
self.is_focused = false;
} else {
self.scrollBy(1, 0);
}
}
}
},
.mouse => |*me| {
if (me.action == .focus) {
// pointToRowCol will return null if the mouse focus event
// is outside the grid.
const focused_cell = cellConverter(grid, me.p);
if (focused_cell) |cell| {
self.cursor.col_num = cell.col_num;
self.cursor.row_num = cell.row_num;
self.is_focused = true;
} else {
self.is_focused = false;
}
}
},
else => {},
}
}