diff --git a/Userland/Libraries/LibGUI/AbstractScrollableWidget.cpp b/Userland/Libraries/LibGUI/AbstractScrollableWidget.cpp index 5be629187e4..22f1567c057 100644 --- a/Userland/Libraries/LibGUI/AbstractScrollableWidget.cpp +++ b/Userland/Libraries/LibGUI/AbstractScrollableWidget.cpp @@ -78,17 +78,23 @@ void AbstractScrollableWidget::custom_layout() int height_wanted_by_horizontal_scrollbar = m_horizontal_scrollbar->is_visible() ? int(m_horizontal_scrollbar->min_height()) : 0; int width_wanted_by_vertical_scrollbar = m_vertical_scrollbar->is_visible() ? int(m_vertical_scrollbar->min_width()) : 0; - m_vertical_scrollbar->set_relative_rect( - inner_rect.right() + 1 - m_vertical_scrollbar->min_width(), - inner_rect.top(), - m_vertical_scrollbar->min_width(), - inner_rect.height() - height_wanted_by_horizontal_scrollbar); + { + int vertical_scrollbar_width = m_vertical_scrollbar->effective_min_size().width().as_int(); + m_vertical_scrollbar->set_relative_rect( + inner_rect.right() + 1 - vertical_scrollbar_width, + inner_rect.top(), + vertical_scrollbar_width, + inner_rect.height() - height_wanted_by_horizontal_scrollbar); + } - m_horizontal_scrollbar->set_relative_rect( - inner_rect.left(), - inner_rect.bottom() + 1 - m_horizontal_scrollbar->min_height(), - inner_rect.width() - width_wanted_by_vertical_scrollbar, - m_horizontal_scrollbar->min_height()); + { + int horizontal_scrollbar_height = m_horizontal_scrollbar->effective_min_size().height().as_int(); + m_horizontal_scrollbar->set_relative_rect( + inner_rect.left(), + inner_rect.bottom() + 1 - horizontal_scrollbar_height, + inner_rect.width() - width_wanted_by_vertical_scrollbar, + horizontal_scrollbar_height); + } m_corner_widget->set_visible(m_vertical_scrollbar->is_visible() && m_horizontal_scrollbar->is_visible()); if (m_corner_widget->is_visible()) { @@ -106,8 +112,8 @@ void AbstractScrollableWidget::resize_event(ResizeEvent& event) Gfx::IntSize AbstractScrollableWidget::available_size() const { auto inner_size = Widget::content_size(); - unsigned available_width = max(inner_size.width() - m_size_occupied_by_fixed_elements.width(), 0); - unsigned available_height = max(inner_size.height() - m_size_occupied_by_fixed_elements.height(), 0); + int available_width = max(inner_size.width() - m_size_occupied_by_fixed_elements.width(), 0); + int available_height = max(inner_size.height() - m_size_occupied_by_fixed_elements.height(), 0); return { available_width, available_height }; } diff --git a/Userland/Libraries/LibGUI/ScrollableContainerWidget.cpp b/Userland/Libraries/LibGUI/ScrollableContainerWidget.cpp index 749958339fb..b7335dcde7a 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)