From: Mikko Rasa Date: Tue, 17 Sep 2019 19:38:04 +0000 (+0300) Subject: Implement next/previous navigation in Panel X-Git-Url: http://git.tdb.fi/?a=commitdiff_plain;h=cfb830ca263defc307f9cfac74fb6771f6b7bfc6;p=libs%2Fgltk.git Implement next/previous navigation in Panel The order is the one widgets were added in, which I think should produce a sensible result in common scenarios. --- diff --git a/source/panel.cpp b/source/panel.cpp index a9d581f..97e13a2 100644 --- a/source/panel.cpp +++ b/source/panel.cpp @@ -1,4 +1,4 @@ -#include +#include #include #include #include "button.h" @@ -104,6 +104,28 @@ bool Panel::navigate(Navigation nav) return true; } } + else if(nav==NAV_NEXT || nav==NAV_PREVIOUS) + { + vector::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::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); diff --git a/source/panel.h b/source/panel.h index 8d67d14..756108a 100644 --- a/source/panel.h +++ b/source/panel.h @@ -58,6 +58,7 @@ private: }; protected: + std::vector nav_order; Layout *layout; Panel(const Panel &);