From 4087e3cfb9ddc88396b42d9e1e7509061ded51d4 Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Thu, 23 Apr 2020 21:43:08 +0200 Subject: LibGUI: Add TabWidget functions to activate next/previous tab --- Libraries/LibGUI/TabWidget.cpp | 22 ++++++++++++++++++++++ Libraries/LibGUI/TabWidget.h | 3 +++ 2 files changed, 25 insertions(+) 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 on_change; protected: -- cgit v1.2.3