From f23bee5a5a0eff34cbea1d7d238f7b5d23b28cbf Mon Sep 17 00:00:00 2001 From: Bent Bisballe Nyeng Date: Sun, 17 Mar 2019 15:25:56 +0100 Subject: Skip tab button when scroll on the tab widget if the tab button is invisible. --- plugingui/tabwidget.cc | 48 +++++++++++++++++++++++++++++++++++++++++++----- plugingui/tabwidget.h | 2 ++ 2 files changed, 45 insertions(+), 5 deletions(-) (limited to 'plugingui') diff --git a/plugingui/tabwidget.cc b/plugingui/tabwidget.cc index 17a540e..635f1bd 100644 --- a/plugingui/tabwidget.cc +++ b/plugingui/tabwidget.cc @@ -83,13 +83,32 @@ std::size_t TabWidget::getBarHeight() const void TabWidget::rotateTab(float delta) { Widget* widget{nullptr}; + Widget* current = stack.getCurrentWidget(); if(delta > 0.0f) { - widget = stack.getWidgetAfter(stack.getCurrentWidget()); + while((widget = stack.getWidgetAfter(current)) != nullptr) + { + auto button = getButtonFromWidget(widget); + if(!button || !button->visible()) + { + current = widget; + continue; + } + break; + } } else { - widget = stack.getWidgetBefore(stack.getCurrentWidget()); + while((widget = stack.getWidgetBefore(current)) != nullptr) + { + auto button = getButtonFromWidget(widget); + if(!button || !button->visible()) + { + current = widget; + continue; + } + break; + } } if(widget) @@ -98,9 +117,9 @@ void TabWidget::rotateTab(float delta) } } -void TabWidget::switchTab(Widget* tabWidget) +void TabWidget::switchTab(Widget* tab_widget) { - stack.setCurrentWidget(tabWidget); + stack.setCurrentWidget(tab_widget); } void TabWidget::setActiveButtons(Widget* current_widget) @@ -109,7 +128,8 @@ void TabWidget::setActiveButtons(Widget* current_widget) if (button.getTabWidget() == current_widget) { button.setActive(true); } - else { + else + { button.setActive(false); } } @@ -173,4 +193,22 @@ void TabWidget::relayout() sizeChanged(TabWidget::width(), TabWidget::height()); // Force re-layout } +const TabButton* TabWidget::getButtonFromWidget(const Widget* tab_widget) +{ + if(tab_widget == nullptr) + { + return nullptr; + } + + for(auto& button : buttons) + { + if(button.getTabWidget() == tab_widget) + { + return &button; + } + } + + return nullptr; +} + } // GUI:: diff --git a/plugingui/tabwidget.h b/plugingui/tabwidget.h index dc69776..129826a 100644 --- a/plugingui/tabwidget.h +++ b/plugingui/tabwidget.h @@ -64,6 +64,8 @@ private: void switchTab(Widget* tabWidget); void setActiveButtons(Widget* current_widget); + const TabButton* getButtonFromWidget(const Widget* tab_widget); + std::list buttons; StackedWidget stack; -- cgit v1.2.3