mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 19:27:45 +00:00
LibGUI: Add GUI::TabWidget::try_add_tab<T>(...)
This is a fallible variant of add_tab<T>(...) that returns ErrorOr.
This commit is contained in:
parent
dc47fce2d9
commit
47b6339025
2 changed files with 17 additions and 1 deletions
|
@ -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 });
|
m_tabs.append({ title, nullptr, &widget });
|
||||||
add_child(widget);
|
add_child(widget);
|
||||||
update_focus_policy();
|
update_focus_policy();
|
||||||
if (on_tab_count_change)
|
if (on_tab_count_change)
|
||||||
on_tab_count_change(m_tabs.size());
|
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)
|
void TabWidget::remove_widget(Widget& widget)
|
||||||
|
|
|
@ -36,9 +36,19 @@ public:
|
||||||
GUI::Margins const& container_margins() const { return m_container_margins; }
|
GUI::Margins const& container_margins() const { return m_container_margins; }
|
||||||
void set_container_margins(GUI::Margins const&);
|
void set_container_margins(GUI::Margins const&);
|
||||||
|
|
||||||
|
ErrorOr<void> try_add_widget(StringView, Widget&);
|
||||||
|
|
||||||
void add_widget(StringView, Widget&);
|
void add_widget(StringView, Widget&);
|
||||||
void remove_widget(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>
|
template<class T, class... Args>
|
||||||
T& add_tab(StringView title, Args&&... args)
|
T& add_tab(StringView title, Args&&... args)
|
||||||
{
|
{
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue