mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 06:48:12 +00:00
LibGUI: Make ToolBarContainer better at reacting to child events
Now you can remove a ToolBar from a ToolBarContainer and it will update its own preferred size automatically.
This commit is contained in:
parent
9c772a64a1
commit
1887dc6de4
2 changed files with 28 additions and 7 deletions
|
@ -32,9 +32,34 @@
|
|||
|
||||
namespace GUI {
|
||||
|
||||
void ToolBarContainer::child_event(Core::ChildEvent& event)
|
||||
{
|
||||
Frame::child_event(event);
|
||||
|
||||
if (event.type() == Core::Event::ChildAdded) {
|
||||
if (event.child() && event.child()->is_widget())
|
||||
did_add_toolbar((Widget&)*event.child());
|
||||
} else if (event.type() == Core::Event::ChildRemoved) {
|
||||
if (event.child() && event.child()->is_widget()) {
|
||||
did_remove_toolbar((Widget&)*event.child());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void ToolBarContainer::did_remove_toolbar(Widget& toolbar)
|
||||
{
|
||||
m_toolbars.remove_first_matching([&](auto& entry) { return entry.ptr() == &toolbar; });
|
||||
recompute_preferred_size();
|
||||
}
|
||||
|
||||
void ToolBarContainer::did_add_toolbar(Widget& toolbar)
|
||||
{
|
||||
m_toolbars.append(toolbar);
|
||||
recompute_preferred_size();
|
||||
}
|
||||
|
||||
void ToolBarContainer::recompute_preferred_size()
|
||||
{
|
||||
int preferred_size = 4 + (m_toolbars.size() - 1) * 2;
|
||||
|
||||
for (auto& toolbar : m_toolbars) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue