diff options
author | Bent Bisballe Nyeng <deva@aasimon.org> | 2019-03-17 15:25:56 +0100 |
---|---|---|
committer | Bent Bisballe Nyeng <deva@aasimon.org> | 2019-03-17 15:25:56 +0100 |
commit | f23bee5a5a0eff34cbea1d7d238f7b5d23b28cbf (patch) | |
tree | 052328155c2da13e5eebf311336902e0ed6883b3 | |
parent | a0093df2f962b34289c545d85a2baad036b1bcc5 (diff) |
Skip tab button when scroll on the tab widget if the tab button is invisible.
-rw-r--r-- | plugingui/tabwidget.cc | 48 | ||||
-rw-r--r-- | plugingui/tabwidget.h | 2 |
2 files changed, 45 insertions, 5 deletions
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<TabButton> buttons; StackedWidget stack; |