From cfb830ca263defc307f9cfac74fb6771f6b7bfc6 Mon Sep 17 00:00:00 2001 From: Mikko Rasa Date: Tue, 17 Sep 2019 22:38:04 +0300 Subject: [PATCH] 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. --- source/panel.cpp | 31 ++++++++++++++++++++++++++++++- source/panel.h | 1 + 2 files changed, 31 insertions(+), 1 deletion(-) 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 &); -- 2.43.0