summaryrefslogtreecommitdiff
path: root/Userland/Libraries/LibGUI
diff options
context:
space:
mode:
Diffstat (limited to 'Userland/Libraries/LibGUI')
-rw-r--r--Userland/Libraries/LibGUI/TabWidget.cpp8
-rw-r--r--Userland/Libraries/LibGUI/TabWidget.h10
2 files changed, 17 insertions, 1 deletions
diff --git a/Userland/Libraries/LibGUI/TabWidget.cpp b/Userland/Libraries/LibGUI/TabWidget.cpp
index 474b805a9d..d2c4136183 100644
--- a/Userland/Libraries/LibGUI/TabWidget.cpp
+++ b/Userland/Libraries/LibGUI/TabWidget.cpp
@@ -44,13 +44,19 @@ TabWidget::~TabWidget()
{
}
-void TabWidget::add_widget(StringView title, Widget& widget)
+ErrorOr<void> TabWidget::try_add_widget(StringView title, Widget& widget)
{
m_tabs.append({ title, nullptr, &widget });
add_child(widget);
update_focus_policy();
if (on_tab_count_change)
on_tab_count_change(m_tabs.size());
+ return {};
+}
+
+void TabWidget::add_widget(StringView title, Widget& widget)
+{
+ MUST(try_add_widget(title, widget));
}
void TabWidget::remove_widget(Widget& widget)
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)...);