LibGUI: Add AbstractView::move_cursor() and share some movement logic

A view can now be told to move its cursor in one of multiple directions
as specified by the CursorMovement enum.

View subclasses can override move_cursor(CursorMovement) to implement
their own cursor behavior. By default, AbstractView::move_cursor() is
a no-op.

This patch improves code sharing between TableView and TreeView. :^)
This commit is contained in:
Andreas Kling 2020-08-27 17:47:19 +02:00
parent 1b3169f405
commit 0b9d765f6b
Notes: sideshowbarker 2024-07-19 03:05:35 +09:00
7 changed files with 154 additions and 55 deletions

View file

@ -383,4 +383,39 @@ void AbstractTableView::set_row_height(int height)
update_row_sizes();
}
void AbstractTableView::keydown_event(KeyEvent& event)
{
if (event.key() == KeyCode::Key_Left) {
move_cursor(CursorMovement::Left);
event.accept();
return;
}
if (event.key() == KeyCode::Key_Right) {
move_cursor(CursorMovement::Right);
event.accept();
return;
}
if (event.key() == KeyCode::Key_Up) {
move_cursor(CursorMovement::Up);
event.accept();
return;
}
if (event.key() == KeyCode::Key_Down) {
move_cursor(CursorMovement::Down);
event.accept();
return;
}
if (event.key() == KeyCode::Key_Home) {
move_cursor(CursorMovement::Home);
event.accept();
return;
}
if (event.key() == KeyCode::Key_End) {
move_cursor(CursorMovement::End);
event.accept();
return;
}
return AbstractView::keydown_event(event);
}
}