summaryrefslogtreecommitdiff
path: root/Userland/Libraries/LibGUI/TabWidget.h
diff options
context:
space:
mode:
authorAndreas Kling <kling@serenityos.org>2021-11-24 13:13:30 +0100
committerAndreas Kling <kling@serenityos.org>2021-11-24 13:52:01 +0100
commit47b63390253ba39b01a841ad29ae434d8e5c436e (patch)
treee1227de469593ee308427ad6252d68dcc9864457 /Userland/Libraries/LibGUI/TabWidget.h
parentdc47fce2d925a4fd929331354e22f502435ef4f1 (diff)
downloadserenity-47b63390253ba39b01a841ad29ae434d8e5c436e.zip
LibGUI: Add GUI::TabWidget::try_add_tab<T>(...)
This is a fallible variant of add_tab<T>(...) that returns ErrorOr.
Diffstat (limited to 'Userland/Libraries/LibGUI/TabWidget.h')
-rw-r--r--Userland/Libraries/LibGUI/TabWidget.h10
1 files changed, 10 insertions, 0 deletions
diff --git a/Userland/Libraries/LibGUI/TabWidget.h b/Userland/Libraries/LibGUI/TabWidget.h
index bd232857e1..ac0d5402d0 100644
--- a/Userland/Libraries/LibGUI/TabWidget.h
+++ b/Userland/Libraries/LibGUI/TabWidget.h
@@ -36,10 +36,20 @@ public:
GUI::Margins const& container_margins() const { return m_container_margins; }
void set_container_margins(GUI::Margins const&);
+ ErrorOr<void> try_add_widget(StringView, Widget&);
+
void add_widget(StringView, Widget&);
void remove_widget(Widget&);
template<class T, class... Args>
+ ErrorOr<NonnullRefPtr<T>> try_add_tab(StringView title, Args&&... args)
+ {
+ auto t = TRY(T::try_create(forward<Args>(args)...));
+ TRY(try_add_widget(title, *t));
+ return *t;
+ }
+
+ template<class T, class... Args>
T& add_tab(StringView title, Args&&... args)
{
auto t = T::construct(forward<Args>(args)...);