diff options
author | FrHun <28605587+frhun@users.noreply.github.com> | 2022-06-12 23:34:02 +0200 |
---|---|---|
committer | Sam Atkins <atkinssj@gmail.com> | 2022-06-28 17:52:42 +0100 |
commit | 0d56d80514d707c3ebffe32bf03e5f0ec1f73678 (patch) | |
tree | 74d2b123d4184273534727438cb17007f055fe7f | |
parent | 3451181fbf2d6c33d70f3e2cd493ac39cc3ef65a (diff) | |
download | serenity-0d56d80514d707c3ebffe32bf03e5f0ec1f73678.zip |
LibGUI: Use new layout system in scrollable widgets
These changes are mainly nessecairy to remove dependence on the
temporary implicit conversions currently still in place.
-rw-r--r-- | Userland/Libraries/LibGUI/AbstractScrollableWidget.cpp | 32 | ||||
-rw-r--r-- | Userland/Libraries/LibGUI/ScrollableContainerWidget.cpp | 42 |
2 files changed, 37 insertions, 37 deletions
diff --git a/Userland/Libraries/LibGUI/AbstractScrollableWidget.cpp b/Userland/Libraries/LibGUI/AbstractScrollableWidget.cpp index 5be629187e..22f1567c05 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); - - 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 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); + } + + { + 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 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) |