Skip to content

Commit

Permalink
LibWeb: Make horizontal scrollbar start from the left edge of viewport
Browse files Browse the repository at this point in the history
Horizontal scrollbar has to leave space at right edge for the vertical
scrollbar to fully extend from top-to-bottom edge of viewport. Before,
this was done by just moving it leftward beyond the edge of viewport.

Now, it gets scaled down appropriately to fit between left edge of
viewport & vertical scrollbar without clipping.
  • Loading branch information
ronak69 authored and kalenikaliaksandr committed Oct 3, 2024
1 parent 09aec4b commit 8cfe51c
Showing 1 changed file with 12 additions and 9 deletions.
21 changes: 12 additions & 9 deletions Userland/Libraries/LibWeb/Painting/PaintableBox.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -280,25 +280,28 @@ Optional<PaintableBox::ScrollbarData> PaintableBox::compute_scrollbar_data(Scrol
return {};
}

bool is_horizontal = direction == ScrollDirection::Horizontal;

auto padding_rect = absolute_padding_box_rect();
auto scrollable_overflow_rect = this->scrollable_overflow_rect().value();
auto scroll_overflow_size = direction == ScrollDirection::Horizontal ? scrollable_overflow_rect.width() : scrollable_overflow_rect.height();
auto scrollport_size = direction == ScrollDirection::Horizontal ? padding_rect.width() : padding_rect.height();
auto scroll_overflow_size = is_horizontal ? scrollable_overflow_rect.width() : scrollable_overflow_rect.height();
auto scrollport_size = is_horizontal ? padding_rect.width() : padding_rect.height();
if (scroll_overflow_size == 0)
return {};

auto min_thumb_length = min(scrollport_size, 24);
auto thumb_length = max(scrollport_size * (scrollport_size / scroll_overflow_size), min_thumb_length);
auto scrollbar_rect_length = is_horizontal ? scrollport_size - scrollbar_thumb_thickness : scrollport_size;

auto min_thumb_length = min(scrollbar_rect_length, 24);
auto thumb_length = max(scrollbar_rect_length * (scrollport_size / scroll_overflow_size), min_thumb_length);

CSSPixelFraction scroll_size = 0;
if (scroll_overflow_size > scrollport_size)
scroll_size = (scrollport_size - thumb_length) / (scroll_overflow_size - scrollport_size);
scroll_size = (scrollbar_rect_length - thumb_length) / (scroll_overflow_size - scrollport_size);
CSSPixelRect rect;
if (direction == ScrollDirection::Vertical) {
if (is_horizontal)
rect = { padding_rect.left(), padding_rect.bottom() - scrollbar_thumb_thickness, thumb_length, scrollbar_thumb_thickness };
else
rect = { padding_rect.right() - scrollbar_thumb_thickness, padding_rect.top(), scrollbar_thumb_thickness, thumb_length };
} else {
rect = { padding_rect.left() - scrollbar_thumb_thickness, padding_rect.bottom() - scrollbar_thumb_thickness, thumb_length, scrollbar_thumb_thickness };
}

return PaintableBox::ScrollbarData { rect, scroll_size };
}
Expand Down

0 comments on commit 8cfe51c

Please sign in to comment.