From: Mikko Rasa Date: Tue, 17 Sep 2019 11:55:09 +0000 (+0300) Subject: Select list items upon navigation by default X-Git-Url: http://git.tdb.fi/?a=commitdiff_plain;h=b3de715986f0e5b6359a2109c27d052c3d9cc27a;p=libs%2Fgltk.git Select list items upon navigation by default With control pressed, only the focus is moved. --- diff --git a/source/list.cpp b/source/list.cpp index a9cbcc1..5d179e1 100644 --- a/source/list.cpp +++ b/source/list.cpp @@ -2,6 +2,7 @@ #include #include #include +#include #include "graphic.h" #include "list.h" #include "part.h" @@ -234,6 +235,18 @@ void List::render_special(const Part &part, GL::Renderer &renderer) const slider.render(renderer); } +bool List::key_press(unsigned key, unsigned mod) +{ + if(key==Input::KEY_UP && mod==MOD_CTRL) + move_focus(NAV_UP, false); + else if(key==Input::KEY_DOWN && mod==MOD_CTRL) + move_focus(NAV_DOWN, false); + else + return false; + + return true; +} + void List::button_press(int x, int y, unsigned btn) { if(btn==4 || btn==5) @@ -328,22 +341,31 @@ void List::focus_in() bool List::navigate(Navigation nav) { - if(nav==NAV_UP && !items.empty()) + if((nav==NAV_UP || nav==NAV_DOWN) && !items.empty()) + move_focus(nav, true); + else if(nav==NAV_ACTIVATE) + set_selected_index(focus_index); + else + return false; + + return true; +} + +void List::move_focus(Navigation nav, bool select) +{ + if(nav==NAV_UP) { if(focus_index>0) set_focus_index(focus_index-1); } - else if(nav==NAV_DOWN && !items.empty()) + else if(nav==NAV_DOWN) { if(static_cast(focus_index+1)