diff options
author | Andreas Kling <kling@serenityos.org> | 2020-04-23 21:43:08 +0200 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2020-04-23 21:43:08 +0200 |
commit | 4087e3cfb9ddc88396b42d9e1e7509061ded51d4 (patch) | |
tree | a139b55e56b9b3ca21d96d437c7c91fc4aa0a867 | |
parent | 312501f30917e8e22321a80fde294dd50a83012b (diff) | |
download | serenity-4087e3cfb9ddc88396b42d9e1e7509061ded51d4.zip |
LibGUI: Add TabWidget functions to activate next/previous tab
-rw-r--r-- | Libraries/LibGUI/TabWidget.cpp | 22 | ||||
-rw-r--r-- | Libraries/LibGUI/TabWidget.h | 3 |
2 files changed, 25 insertions, 0 deletions
diff --git a/Libraries/LibGUI/TabWidget.cpp b/Libraries/LibGUI/TabWidget.cpp index 11af7af46d..06ebdb9d3e 100644 --- a/Libraries/LibGUI/TabWidget.cpp +++ b/Libraries/LibGUI/TabWidget.cpp @@ -273,4 +273,26 @@ void TabWidget::set_tab_title(Widget& tab, const StringView& title) } } +void TabWidget::activate_next_tab() +{ + if (m_tabs.size() <= 1) + return; + int index = active_tab_index(); + ++index; + if (index >= (int)m_tabs.size()) + index = 0; + set_active_widget(m_tabs.at(index).widget); +} + +void TabWidget::activate_previous_tab() +{ + if (m_tabs.size() <= 1) + return; + int index = active_tab_index(); + --index; + if (index < 0) + index = m_tabs.size() - 1; + set_active_widget(m_tabs.at(index).widget); +} + } diff --git a/Libraries/LibGUI/TabWidget.h b/Libraries/LibGUI/TabWidget.h index 997c6c139a..b566b0f3f7 100644 --- a/Libraries/LibGUI/TabWidget.h +++ b/Libraries/LibGUI/TabWidget.h @@ -67,6 +67,9 @@ public: void set_tab_title(Widget& tab, const StringView& title); + void activate_next_tab(); + void activate_previous_tab(); + Function<void(Widget&)> on_change; protected: |