gpui: Unify track_scroll method to receive a reference type (#43518)

Release Notes:

- N/A

This PR to change the `track_scroll` method to receive a reference type
like the
[Div#track_scroll](https://docs.rs/gpui/latest/gpui/trait.StatefulInteractiveElement.html#method.track_scroll),
[Div#track_focus](https://docs.rs/gpui/latest/gpui/trait.InteractiveElement.html#method.track_focus).


```diff
- .track_scroll(self.scroll_handle.clone())
+ .track_scroll(&self.scroll_handle)

- .vertical_scrollbar_for(self.scroll_handle.clone(), window, cx)
+ .vertical_scrollbar_for(&self.scroll_handle, window, cx)
```


https://github.com/zed-industries/zed/blob/56a2f9cfcf0c6a3c38f596b58002953763cd890f/crates/gpui/src/elements/div.rs#L1088-L1093


https://github.com/zed-industries/zed/blob/56a2f9cfcf0c6a3c38f596b58002953763cd890f/crates/gpui/src/elements/div.rs#L613-L620
This commit is contained in:
Jason Lee
2025-11-26 18:03:42 +01:00
committed by GitHub
parent 757c043171
commit 1a23115773
34 changed files with 63 additions and 68 deletions
+2 -2
View File
@@ -872,7 +872,7 @@ impl<const COLS: usize> RenderOnce for Table<COLS> {
interaction_state.as_ref(),
|this, state| {
this.track_scroll(
state.read_with(cx, |s, _| s.scroll_handle.clone()),
&state.read_with(cx, |s, _| s.scroll_handle.clone()),
)
},
),
@@ -906,7 +906,7 @@ impl<const COLS: usize> RenderOnce for Table<COLS> {
.unwrap_or_else(|| Scrollbars::new(super::ScrollAxes::Both));
content
.custom_scrollbars(
scrollbars.tracked_scroll_handle(state.read(cx).scroll_handle.clone()),
scrollbars.tracked_scroll_handle(&state.read(cx).scroll_handle),
window,
cx,
)
+5 -5
View File
@@ -150,9 +150,9 @@ pub trait WithScrollbar: Sized {
// }
#[track_caller]
fn vertical_scrollbar_for<ScrollHandle: ScrollableHandle>(
fn vertical_scrollbar_for<ScrollHandle: ScrollableHandle + Clone>(
self,
scroll_handle: ScrollHandle,
scroll_handle: &ScrollHandle,
window: &mut Window,
cx: &mut App,
) -> Self::Output {
@@ -441,7 +441,7 @@ impl<ScrollHandle: ScrollableHandle> Scrollbars<ScrollHandle> {
pub fn tracked_scroll_handle<TrackedHandle: ScrollableHandle>(
self,
tracked_scroll_handle: TrackedHandle,
tracked_scroll_handle: &TrackedHandle,
) -> Scrollbars<TrackedHandle> {
let Self {
id,
@@ -454,7 +454,7 @@ impl<ScrollHandle: ScrollableHandle> Scrollbars<ScrollHandle> {
} = self;
Scrollbars {
scrollable_handle: Handle::Tracked(tracked_scroll_handle),
scrollable_handle: Handle::Tracked(tracked_scroll_handle.clone()),
id,
tracked_entity: tracked_entity_id,
visibility,
@@ -968,7 +968,7 @@ impl ScrollableHandle for ScrollHandle {
}
}
pub trait ScrollableHandle: 'static + Any + Sized {
pub trait ScrollableHandle: 'static + Any + Sized + Clone {
fn max_offset(&self) -> Size<Pixels>;
fn set_offset(&self, point: Point<Pixels>);
fn offset(&self) -> Point<Pixels>;
+2 -2
View File
@@ -24,8 +24,8 @@ impl TabBar {
}
}
pub fn track_scroll(mut self, scroll_handle: ScrollHandle) -> Self {
self.scroll_handle = Some(scroll_handle);
pub fn track_scroll(mut self, scroll_handle: &ScrollHandle) -> Self {
self.scroll_handle = Some(scroll_handle.clone());
self
}