You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In order to implement a scrollbar UI component (as far as I can tell) it is necessary to perform a duplicate computation to find the content size of the scrollable area (the full top to bottom scrollable content size). This computation has already been done by GPUI in the case of Div scrolling and I'm sure for List and Uniform List scrolling too, so I think it would be sensible and less error-prone to reuse the content size that has already been calculated by GPUI.
A scrollbar UI component needs the content size to know how far down the page the offset is as a ratio for positioning the scrollbar thumb.
// todo: PO: this is slightly wrong for horizontal scrollbar, as the last item is not necessarily the longest one.
let first_item = self.bounds_for_item(0)?;
last_item.size.height += last_item.origin.y;
last_item.size.width += last_item.origin.x;
scroll_adjustment = Some(first_item.origin);
last_item.size.height -= first_item.origin.y;
last_item.size.width -= first_item.origin.x;
}
Some(ContentSize{
size: last_item.size,
scroll_adjustment,
})
}
I can see that in Zed's ui crate a content_size trait function is implemented over Div/List/UniformList. This calculation already differs from the one used by GPUI. I think it'd be best to keep this computation in one place (GPUI) and expose the result.
Solution proposal
I propose that some 'content_size' or 'max_scroll_size' property is exposed on ScrollHandleState.
For the div implementation of scrolling this content size is calculated as max_scroll in clamp_scroll_position function inside div.rs which is called every prepaint of Div. I propose that here we check whether there's Some(tracked_focus_handle) and if there is update the property here.
I'm not sure whether its best to expose the scroll_max variable or just the content_size variable since content_size would likely cater to a larger class of problems in which scrolling content size wants to be known. On the other hand scroll_max is directly what is used to clamp the scrolling, so perfectly suits the particular use case of scrollbars. Perhaps both?
I can see that Div's prepaint already updates some properties on ScrollHandleState so the pattern of exposing certain properties in this way already exists in the codebase.
I'm fairly sure I can see what must be done in the case of Div scrolling for my proposed solution and am happy to open a PR for this, but I have not yet looked into how List and UniformList work.
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
-
Problem Statement
In order to implement a scrollbar UI component (as far as I can tell) it is necessary to perform a duplicate computation to find the content size of the scrollable area (the full top to bottom scrollable content size). This computation has already been done by GPUI in the case of Div scrolling and I'm sure for List and Uniform List scrolling too, so I think it would be sensible and less error-prone to reuse the content size that has already been calculated by GPUI.
A scrollbar UI component needs the content size to know how far down the page the offset is as a ratio for positioning the scrollbar thumb.
Zed's scrollbar
zed/crates/ui/src/components/scrollbar.rs
Lines 67 to 89 in 7eb226b
I can see that in Zed's
ui
crate a content_size trait function is implemented over Div/List/UniformList. This calculation already differs from the one used by GPUI. I think it'd be best to keep this computation in one place (GPUI) and expose the result.Solution proposal
I propose that some 'content_size' or 'max_scroll_size' property is exposed on ScrollHandleState.
For the div implementation of scrolling this content size is calculated as
max_scroll
in clamp_scroll_position function inside div.rs which is called every prepaint of Div. I propose that here we check whether there's Some(tracked_focus_handle) and if there is update the property here.zed/crates/gpui/src/elements/div.rs
Lines 1553 to 1603 in 7eb226b
I'm not sure whether its best to expose the
scroll_max
variable or just thecontent_size
variable sincecontent_size
would likely cater to a larger class of problems in which scrolling content size wants to be known. On the other hand scroll_max is directly what is used to clamp the scrolling, so perfectly suits the particular use case of scrollbars. Perhaps both?Building on an existing pattern
zed/crates/gpui/src/elements/div.rs
Lines 1271 to 1282 in 7eb226b
I can see that Div's prepaint already updates some properties on ScrollHandleState so the pattern of exposing certain properties in this way already exists in the codebase.
I'm fairly sure I can see what must be done in the case of Div scrolling for my proposed solution and am happy to open a PR for this, but I have not yet looked into how List and UniformList work.
Beta Was this translation helpful? Give feedback.
All reactions