diff options
Diffstat (limited to 'Userland/Libraries/LibGUI/ScrollableContainerWidget.cpp')
-rw-r--r-- | Userland/Libraries/LibGUI/ScrollableContainerWidget.cpp | 42 |
1 files changed, 18 insertions, 24 deletions
diff --git a/Userland/Libraries/LibGUI/ScrollableContainerWidget.cpp b/Userland/Libraries/LibGUI/ScrollableContainerWidget.cpp index 749958339f..b7335dcde7 100644 --- a/Userland/Libraries/LibGUI/ScrollableContainerWidget.cpp +++ b/Userland/Libraries/LibGUI/ScrollableContainerWidget.cpp @@ -37,31 +37,25 @@ void ScrollableContainerWidget::update_widget_size() if (!m_widget) return; m_widget->do_layout(); - auto new_size = Widget::content_size(); - - if (m_widget->layout()) { - auto preferred_size = m_widget->layout()->preferred_size(); - if (m_widget->is_shrink_to_fit()) { - if (preferred_size.width() != -1) - new_size.set_width(preferred_size.width()); - if (preferred_size.height() != -1) - new_size.set_height(preferred_size.height()); - } else { - new_size = Gfx::Size { - max(new_size.width(), preferred_size.width()), - max(new_size.height(), preferred_size.height()) - }; - } + if (m_widget->is_shrink_to_fit() && m_widget->layout()) { + auto new_size = Widget::content_size(); + auto preferred_size = m_widget->effective_preferred_size(); + if (preferred_size.width().is_int()) + new_size.set_width(preferred_size.width().as_int()); + if (preferred_size.height().is_int()) + new_size.set_height(preferred_size.height().as_int()); + m_widget->resize(new_size); + set_content_size(new_size); + } else { + auto inner_size = Widget::content_size(); + auto min_size = m_widget->effective_min_size(); + auto new_size = Gfx::Size { + max(inner_size.width(), MUST(min_size.width().shrink_value())), + max(inner_size.height(), MUST(min_size.height().shrink_value())) + }; + m_widget->resize(new_size); + set_content_size(new_size); } - - auto min_size = m_widget->min_size(); - new_size = Gfx::Size { - max(new_size.width(), min_size.width()), - max(new_size.height(), min_size.height()), - }; - - m_widget->resize(new_size); - set_content_size(new_size); } void ScrollableContainerWidget::resize_event(GUI::ResizeEvent& event) |