1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 18:27: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:
Andreas Kling 2021-11-24 22:23:59 +01:00
parent a18631c5e7
commit e623e73f63
2 changed files with 15 additions and 4 deletions

View file

@ -111,12 +111,21 @@ GUI::Button& Toolbar::add_action(Action& action)
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()
{
auto item = make<Item>();
item->type = Item::Type::Separator;
add<SeparatorWidget>(m_orientation == Gfx::Orientation::Horizontal ? Gfx::Orientation::Vertical : Gfx::Orientation::Horizontal);
m_items.append(move(item));
MUST(try_add_separator());
}
void Toolbar::paint_event(PaintEvent& event)