gpui: Fix Interactivity prepaint to update scroll_handle bounds (#35013)
Jason Lee
created
It took a long time to check this problem.
Finally, I found that due to a detail missing when changing #34832, the
bounds of `ScrollHandle` was not updated in the Interactivity `prepaint`
phase.
```diff
- scroll_handle_state.padded_content_size = padded_content_size;
+ scroll_handle_state.max_offset = scroll_max;
```
It was correct before the change, because the `padded_content_size`
(including `bounds.size`) was saved before, and the bounds was missing
after changing to `max_offset`, but the bounds were not updated
anywhere.
So when `scroll_handle.bounds()` is obtained outside, it is always 0px
here.
@MrSubidubi
Release Notes:
- N/A
@@ -1334,7 +1334,6 @@ impl Element for Div {
} else if let Some(scroll_handle) = self.interactivity.tracked_scroll_handle.as_ref() {
let mut state = scroll_handle.0.borrow_mut();
state.child_bounds = Vec::with_capacity(request_layout.child_layout_ids.len());
- state.bounds = bounds;
for child_layout_id in &request_layout.child_layout_ids {
let child_bounds = window.layout_bounds(*child_layout_id);
child_min = child_min.min(&child_bounds.origin);
@@ -1706,6 +1705,7 @@ impl Interactivity {
if let Some(mut scroll_handle_state) = tracked_scroll_handle {
scroll_handle_state.max_offset = scroll_max;
+ scroll_handle_state.bounds = bounds;
}
*scroll_offset
@@ -3007,11 +3007,6 @@ impl ScrollHandle {
self.0.borrow().bounds
}
- /// Set the bounds into which this child is painted- pub(super) fn set_bounds(&self, bounds: Bounds<Pixels>) {- self.0.borrow_mut().bounds = bounds;- }-
/// Get the bounds for a specific child.
pub fn bounds_for_item(&self, ix: usize) -> Option<Bounds<Pixels>> {
self.0.borrow().child_bounds.get(ix).cloned()