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.
This commit is contained in:
FrHun 2022-06-12 23:34:02 +02:00 committed by Sam Atkins
parent 3451181fbf
commit 0d56d80514
Notes: sideshowbarker 2024-07-17 09:54:50 +09:00
2 changed files with 36 additions and 36 deletions

View file

@ -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 };
}

View file

@ -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)