ui: Account for padding of parent container during scrollbar layout (#27402)
Closes https://github.com/zed-industries/zed/issues/23386 This PR updates the scrollbar-component to account for padding present in the parent container. Since the linked issue was opened, https://github.com/zed-industries/zed/pull/25288 improved the behaviour so that the scrollbar does allow scrolling the entire container, however the scrollbar thumb still does not go the entire way to the bottom. This can be seen here: https://github.com/user-attachments/assets/89204355-e6b8-428b-9fa9-bb614051b6fa This happens because during layouting of the scrollbar, padding of the parent container is not taken into account. The scrollbar thumb size is calculated as if no padding was present. With this change, padding is now included in the calculation, which resolves the issue: https://github.com/user-attachments/assets/1d4c62e0-4555-4332-a9ab-4e114684b4b3 The change here is to store the calculated content size during prepaint _including_ padding and use this for layouting the scrollbar. This ensures that the actual scroll max and the content size are always in sync. Furthermore, the existing `TODO`-comment is also resolved, as we now no longer look at the size of the last child but the actual parent size instead. This also removes an existing panic of the scrollbar-component in cases where the content size was 0, which was previously not accounted for (this never happened in practice so far, for example because of the padding added here: https://github.com/zed-industries/zed/blob/43712285bfa8aa75bac1ca8a7eb5146dd36239be/crates/editor/src/hover_popover.rs#L802-L809 which prevented the container size from ever being 0). --- Lastly, as I was wiring through the changes of the `content_size` I noticed that some code was duplicated during the initial layouting as well as in the click handlers. I refactored this in the second commit to use `along` where possible as well as computing the new click offset in one closure which can be passed to both event listeners. As always, should any of these changes not be wanted, feel free to let me know and I will revert these. Looking forward to your feedback 😄 Release Notes: - Fixed scrollbars sometimes not scrolling all the way to the bottom.
This commit is contained in:
@@ -2671,11 +2671,7 @@ impl Pane {
|
||||
}
|
||||
})
|
||||
.children(pinned_tabs.len().ne(&0).then(|| {
|
||||
let content_width = self
|
||||
.tab_bar_scroll_handle
|
||||
.content_size()
|
||||
.map(|content_size| content_size.size.width)
|
||||
.unwrap_or(px(0.));
|
||||
let content_width = self.tab_bar_scroll_handle.content_size().width;
|
||||
let viewport_width = self.tab_bar_scroll_handle.viewport().size.width;
|
||||
// We need to check both because offset returns delta values even when the scroll handle is not scrollable
|
||||
let is_scrollable = content_width > viewport_width;
|
||||
|
||||
Reference in New Issue
Block a user