diff options
author | Andreas Kling <awesomekling@gmail.com> | 2019-03-23 04:05:58 +0100 |
---|---|---|
committer | Andreas Kling <awesomekling@gmail.com> | 2019-03-23 04:05:58 +0100 |
commit | 1355d09c720cf04e58c7b5478150764781d6bf13 (patch) | |
tree | 34e900caa86c7bf4fd017f7cb37b8253799c4437 | |
parent | 82ca3e58b88a5b8bff86fcab2d45b6c96a0b73ae (diff) | |
download | serenity-1355d09c720cf04e58c7b5478150764781d6bf13.zip |
GItemView: Implement up/down/left/right keyboard navigation.
-rw-r--r-- | LibGUI/GItemView.cpp | 31 |
1 files changed, 30 insertions, 1 deletions
diff --git a/LibGUI/GItemView.cpp b/LibGUI/GItemView.cpp index 4acab7073a..db0499c121 100644 --- a/LibGUI/GItemView.cpp +++ b/LibGUI/GItemView.cpp @@ -144,6 +144,9 @@ void GItemView::keydown_event(GKeyEvent& event) { if (!model()) return; + if (!m_visual_row_count || !m_visual_column_count) + return; + auto& model = *this->model(); if (event.key() == KeyCode::Key_Return) { model.activate(model.selected_index()); @@ -152,7 +155,7 @@ void GItemView::keydown_event(GKeyEvent& event) if (event.key() == KeyCode::Key_Up) { GModelIndex new_index; if (model.selected_index().is_valid()) - new_index = { model.selected_index().row() - 1, model.selected_index().column() }; + new_index = { model.selected_index().row() - m_visual_column_count, model.selected_index().column() }; else new_index = { 0, 0 }; if (model.is_valid(new_index)) { @@ -165,6 +168,32 @@ void GItemView::keydown_event(GKeyEvent& event) if (event.key() == KeyCode::Key_Down) { GModelIndex new_index; if (model.selected_index().is_valid()) + new_index = { model.selected_index().row() + m_visual_column_count, model.selected_index().column() }; + else + new_index = { 0, 0 }; + if (model.is_valid(new_index)) { + model.set_selected_index(new_index); + scroll_into_view(new_index, Orientation::Vertical); + update(); + } + return; + } + if (event.key() == KeyCode::Key_Left) { + GModelIndex new_index; + if (model.selected_index().is_valid()) + new_index = { model.selected_index().row() - 1, model.selected_index().column() }; + else + new_index = { 0, 0 }; + if (model.is_valid(new_index)) { + model.set_selected_index(new_index); + scroll_into_view(new_index, Orientation::Vertical); + update(); + } + return; + } + if (event.key() == KeyCode::Key_Right) { + GModelIndex new_index; + if (model.selected_index().is_valid()) new_index = { model.selected_index().row() + 1, model.selected_index().column() }; else new_index = { 0, 0 }; |