LibGUI: Don't accomodate invisible children in ToolBarContainer height
Skip over invisible children so they don't take up vertical space in the container. Also make sure we update the preferred size whenever the widget layout is invalidated. Fixes #3139.
This commit is contained in:
parent
2c3842bfe6
commit
00f47bba23
Notes:
sideshowbarker
2024-07-19 02:05:20 +09:00
Author: https://github.com/awesomekling Commit: https://github.com/SerenityOS/serenity/commit/00f47bba237
2 changed files with 13 additions and 1 deletions
|
@ -58,17 +58,28 @@ void ToolBarContainer::did_add_toolbar(Widget& toolbar)
|
|||
recompute_preferred_size();
|
||||
}
|
||||
|
||||
void ToolBarContainer::custom_layout()
|
||||
{
|
||||
recompute_preferred_size();
|
||||
}
|
||||
|
||||
void ToolBarContainer::recompute_preferred_size()
|
||||
{
|
||||
int preferred_size = 4 + (m_toolbars.size() - 1) * 2;
|
||||
int visible_toolbar_count = 0;
|
||||
int preferred_size = 4;
|
||||
|
||||
for (auto& toolbar : m_toolbars) {
|
||||
if (!toolbar.is_visible())
|
||||
continue;
|
||||
++visible_toolbar_count;
|
||||
if (m_orientation == Gfx::Orientation::Horizontal)
|
||||
preferred_size += toolbar.preferred_size().height();
|
||||
else
|
||||
preferred_size += toolbar.preferred_size().width();
|
||||
}
|
||||
|
||||
preferred_size += (visible_toolbar_count - 1) * 2;
|
||||
|
||||
if (m_orientation == Gfx::Orientation::Horizontal)
|
||||
set_preferred_size(0, preferred_size);
|
||||
else
|
||||
|
|
|
@ -38,6 +38,7 @@ public:
|
|||
private:
|
||||
explicit ToolBarContainer(Gfx::Orientation = Gfx::Orientation::Horizontal);
|
||||
|
||||
virtual void custom_layout() override;
|
||||
virtual void paint_event(GUI::PaintEvent&) override;
|
||||
virtual void child_event(Core::ChildEvent&) override;
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue