]> git.tdb.fi Git - libs/gltk.git/commitdiff
Implement next/previous navigation in Panel
authorMikko Rasa <tdb@tdb.fi>
Tue, 17 Sep 2019 19:38:04 +0000 (22:38 +0300)
committerMikko Rasa <tdb@tdb.fi>
Tue, 17 Sep 2019 19:38:04 +0000 (22:38 +0300)
The order is the one widgets were added in, which I think should produce
a sensible result in common scenarios.

source/panel.cpp
source/panel.h

index a9d581f5aae63a11150df2b2fd3ebcba81d6f624..97e13a2591b34dd9107f2dd65c22baa86750f676 100644 (file)
@@ -1,4 +1,4 @@
-#include <algorithm>
+#include <msp/core/algorithm.h>
 #include <msp/core/maputils.h>
 #include <msp/core/refptr.h>
 #include "button.h"
@@ -104,6 +104,28 @@ bool Panel::navigate(Navigation nav)
                        return true;
                }
        }
+       else if(nav==NAV_NEXT || nav==NAV_PREVIOUS)
+       {
+               vector<Widget *>::iterator i = find(nav_order, input_focus);
+
+               if(nav==NAV_NEXT)
+               {
+                       if(i!=nav_order.end())
+                               ++i;
+                       if(i==nav_order.end())
+                               i = nav_order.begin();
+               }
+               else
+               {
+                       if(i==nav_order.begin())
+                               i = nav_order.end();
+                       --i;
+               }
+
+               set_input_focus(*i);
+
+               return true;
+       }
 
        return false;
 }
@@ -159,6 +181,9 @@ void Panel::on_geometry_change()
 
 void Panel::on_child_added(Widget &wdg)
 {
+       if(wdg.get_input_type()!=INPUT_NONE)
+               nav_order.push_back(&wdg);
+
        if(layout)
        {
                layout->add_widget(wdg);
@@ -168,6 +193,10 @@ void Panel::on_child_added(Widget &wdg)
 
 void Panel::on_child_removed(Widget &wdg)
 {
+       vector<Widget *>::iterator i = std::remove(nav_order.begin(), nav_order.end(), &wdg);
+       if(i!=nav_order.end())
+               nav_order.erase(i, nav_order.end());
+
        if(layout)
        {
                layout->remove_widget(wdg);
index 8d67d14ffe46ff7b7ef5afaedfb83ce912da09b9..756108a5cafce149f688906dcb196dcd4c5e5ef4 100644 (file)
@@ -58,6 +58,7 @@ private:
        };
 
 protected:
+       std::vector<Widget *> nav_order;
        Layout *layout;
 
        Panel(const Panel &);