diff options
author | Oriko <oriko1010@protonmail.com> | 2020-04-06 01:02:24 +0300 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2020-04-06 09:01:42 +0200 |
commit | 12c7375cdd40f6bed39ffaa6516f7ae85ea5f058 (patch) | |
tree | 2f52af62edb10e2d077fa255ed33d42944521dcd /Libraries | |
parent | c0a4cf5e8d78f8a24551c2e98219d0c6eff4aefb (diff) | |
download | serenity-12c7375cdd40f6bed39ffaa6516f7ae85ea5f058.zip |
LibGUI: Add remove_tab and on_change to TabWidget
Diffstat (limited to 'Libraries')
-rw-r--r-- | Libraries/LibGUI/TabWidget.cpp | 10 | ||||
-rw-r--r-- | Libraries/LibGUI/TabWidget.h | 5 |
2 files changed, 15 insertions, 0 deletions
diff --git a/Libraries/LibGUI/TabWidget.cpp b/Libraries/LibGUI/TabWidget.cpp index f3e7a5dcd0..384a57d682 100644 --- a/Libraries/LibGUI/TabWidget.cpp +++ b/Libraries/LibGUI/TabWidget.cpp @@ -47,6 +47,12 @@ void TabWidget::add_widget(const StringView& title, Widget& widget) add_child(widget); } +void TabWidget::remove_widget(Widget& widget) +{ + m_tabs.remove_first_matching([&widget](auto& entry) { return &widget == entry.widget; }); + remove_child(widget); +} + void TabWidget::set_active_widget(Widget* widget) { if (widget == m_active_widget) @@ -58,6 +64,10 @@ void TabWidget::set_active_widget(Widget* widget) if (m_active_widget) { m_active_widget->set_relative_rect(child_rect_for_size(size())); m_active_widget->set_visible(true); + deferred_invoke([this](auto&) { + if (on_change) + on_change(*m_active_widget); + }); } update_bar(); diff --git a/Libraries/LibGUI/TabWidget.h b/Libraries/LibGUI/TabWidget.h index 1e9333f155..9aa4987c80 100644 --- a/Libraries/LibGUI/TabWidget.h +++ b/Libraries/LibGUI/TabWidget.h @@ -53,6 +53,7 @@ public: int container_padding() const { return 2; } void add_widget(const StringView&, Widget&); + void remove_widget(Widget&); template<class T, class... Args> T& add_tab(const StringView& title, Args&&... args) @@ -62,6 +63,10 @@ public: return *t; } + void remove_tab(Widget& tab) { remove_widget(tab); } + + Function<void(const Widget&)> on_change; + protected: TabWidget(); |