mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 02:07:35 +00:00
LibGUI: Add GUI::Toolbar::try_add_separator()
This is a fallible variant of add_separator() that returns ErrorOr.
This commit is contained in:
parent
a18631c5e7
commit
e623e73f63
2 changed files with 15 additions and 4 deletions
|
@ -111,12 +111,21 @@ GUI::Button& Toolbar::add_action(Action& action)
|
||||||
return *button;
|
return *button;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ErrorOr<void> Toolbar::try_add_separator()
|
||||||
|
{
|
||||||
|
// NOTE: Grow the m_items capacity before potentially adding a child widget.
|
||||||
|
TRY(m_items.try_ensure_capacity(m_items.size() + 1));
|
||||||
|
|
||||||
|
auto item = TRY(adopt_nonnull_own_or_enomem(new (nothrow) Item));
|
||||||
|
item->type = Item::Type::Separator;
|
||||||
|
TRY(try_add<SeparatorWidget>(m_orientation == Gfx::Orientation::Horizontal ? Gfx::Orientation::Vertical : Gfx::Orientation::Horizontal));
|
||||||
|
m_items.unchecked_append(move(item));
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
|
||||||
void Toolbar::add_separator()
|
void Toolbar::add_separator()
|
||||||
{
|
{
|
||||||
auto item = make<Item>();
|
MUST(try_add_separator());
|
||||||
item->type = Item::Type::Separator;
|
|
||||||
add<SeparatorWidget>(m_orientation == Gfx::Orientation::Horizontal ? Gfx::Orientation::Vertical : Gfx::Orientation::Horizontal);
|
|
||||||
m_items.append(move(item));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Toolbar::paint_event(PaintEvent& event)
|
void Toolbar::paint_event(PaintEvent& event)
|
||||||
|
|
|
@ -18,6 +18,8 @@ public:
|
||||||
virtual ~Toolbar() override;
|
virtual ~Toolbar() override;
|
||||||
|
|
||||||
ErrorOr<NonnullRefPtr<GUI::Button>> try_add_action(GUI::Action&);
|
ErrorOr<NonnullRefPtr<GUI::Button>> try_add_action(GUI::Action&);
|
||||||
|
ErrorOr<void> try_add_separator();
|
||||||
|
|
||||||
GUI::Button& add_action(GUI::Action&);
|
GUI::Button& add_action(GUI::Action&);
|
||||||
void add_separator();
|
void add_separator();
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue