1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 09:58:11 +00:00

LibGUI: Fix glitchy behavior in ScrollableWidget::scroll_into_view()

This function relies on visible_content_rect() which could previously
return rectangles with negative size. This was causing TableViews to
scroll down a little bit when assigning a model to them.

Also tweak the logic so we scroll a 0x0 rect into view, giving a
slightly nicer final position.
This commit is contained in:
Andreas Kling 2020-07-04 20:17:22 +02:00
parent 36150a118d
commit 998b3f6d87

View file

@ -149,12 +149,15 @@ int ScrollableWidget::width_occupied_by_vertical_scrollbar() const
Gfx::IntRect ScrollableWidget::visible_content_rect() const
{
return {
Gfx::IntRect rect {
m_horizontal_scrollbar->value(),
m_vertical_scrollbar->value(),
min(m_content_size.width(), frame_inner_rect().width() - width_occupied_by_vertical_scrollbar() - m_size_occupied_by_fixed_elements.width()),
min(m_content_size.height(), frame_inner_rect().height() - height_occupied_by_horizontal_scrollbar() - m_size_occupied_by_fixed_elements.height())
};
if (rect.is_empty())
return {};
return rect;
}
void ScrollableWidget::scroll_into_view(const Gfx::IntRect& rect, Orientation orientation)
@ -198,12 +201,12 @@ void ScrollableWidget::set_scrollbars_enabled(bool scrollbars_enabled)
void ScrollableWidget::scroll_to_top()
{
scroll_into_view({ 0, 0, 1, 1 }, Orientation::Vertical);
scroll_into_view({}, Orientation::Vertical);
}
void ScrollableWidget::scroll_to_bottom()
{
scroll_into_view({ 0, content_height(), 1, 1 }, Orientation::Vertical);
scroll_into_view({ 0, content_height(), 0, 0 }, Orientation::Vertical);
}
Gfx::IntRect ScrollableWidget::widget_inner_rect() const