From 8b458b2a7a83f12fd2292dc6b8b352fab18a90a8 Mon Sep 17 00:00:00 2001 From: MrSubidubi Date: Mon, 18 Aug 2025 16:07:47 +0200 Subject: [PATCH] Some more fixes --- crates/ui/src/components/scrollbar.rs | 49 +++++++++++++++++++-------- 1 file changed, 34 insertions(+), 15 deletions(-) diff --git a/crates/ui/src/components/scrollbar.rs b/crates/ui/src/components/scrollbar.rs index cf27b34cf3..850ac0748d 100644 --- a/crates/ui/src/components/scrollbar.rs +++ b/crates/ui/src/components/scrollbar.rs @@ -1,4 +1,4 @@ -use std::{fmt::Debug, marker::PhantomData, ops::Not, time::Duration}; +use std::{any::Any, fmt::Debug, marker::PhantomData, ops::Not, time::Duration}; use gpui::{ Along, App, AppContext as _, Axis as ScrollbarAxis, BorderStyle, Bounds, ContentMask, Context, @@ -220,6 +220,11 @@ where div.when_some(state.read(cx).handle_to_track(), |this, handle| { this.track_scroll(handle) }) + .when_some(state.read(cx).visible_axes(), |this, axes| match axes { + ScrollAxes::Horizontal => this.overflow_x_scroll(), + ScrollAxes::Vertical => this.overflow_y_scroll(), + ScrollAxes::Both => this.overflow_scroll(), + }) .when_some( state .read(cx) @@ -257,6 +262,7 @@ impl UniformListDecoration impl WithScrollbar for UniformList { type Output = Self; + #[track_caller] fn custom_scrollbars( self, config: Scrollbars, @@ -268,7 +274,17 @@ impl WithScrollbar for UniformList { T: ScrollableHandle, { let scrollbar = get_scrollbar_state(config, std::panic::Location::caller(), window, cx); - self.with_decoration(scrollbar) + self.when_some( + scrollbar.read_with(cx, |wrapper, cx| { + wrapper + .0 + .read(cx) + .handle_to_track::() + .cloned() + }), + |this, handle| this.track_scroll(handle), + ) + .with_decoration(scrollbar) } } @@ -276,7 +292,7 @@ impl WithScrollbar for UniformList { pub enum ScrollAxes { Horizontal, Vertical, - BothAxes, + Both, } impl ScrollAxes { @@ -287,7 +303,7 @@ impl ScrollAxes { match self { Self::Horizontal => point.apply_along(ScrollbarAxis::Horizontal, |_| value), Self::Vertical => point.apply_along(ScrollbarAxis::Vertical, |_| value), - Self::BothAxes => Point::new(value.clone(), value), + Self::Both => Point::new(value.clone(), value), } } } @@ -347,7 +363,7 @@ impl Scrollbars { } pub fn for_settings() -> Scrollbars { - Scrollbars::::new_with_setting(ScrollAxes::BothAxes) + Scrollbars::::new_with_setting(ScrollAxes::Both) } } @@ -553,6 +569,16 @@ impl ScrollbarState { } } + #[inline] + fn visible_axes(&self) -> Option { + match (&self.visibility.x, &self.visibility.y) { + (ReservedSpace::None, ReservedSpace::None) => None, + (ReservedSpace::None, _) => Some(ScrollAxes::Vertical), + (_, ReservedSpace::None) => Some(ScrollAxes::Horizontal), + _ => Some(ScrollAxes::Both), + } + } + fn space_to_reserve_for(&self, axis: ScrollbarAxis) -> Option { (self.show_state.is_disabled().not() && self.visibility.along(axis).needs_scroll_track()) .then(|| self.space_to_reserve()) @@ -562,9 +588,9 @@ impl ScrollbarState { self.width.to_pixels() + 2 * SCROLLBAR_PADDING } - fn handle_to_track(&self) -> Option<&ScrollHandle> { + fn handle_to_track(&self) -> Option<&Handle> { (!self.manually_added) - .then(|| self.scroll_handle.trackable_handle()) + .then(|| (self.scroll_handle() as &dyn Any).downcast_ref::()) .flatten() } @@ -779,13 +805,9 @@ impl ScrollableHandle for ScrollHandle { fn viewport(&self) -> Bounds { self.bounds() } - - fn trackable_handle(&self) -> Option<&ScrollHandle> { - Some(self) - } } -pub trait ScrollableHandle: 'static { +pub trait ScrollableHandle: 'static + Any + Sized { fn max_offset(&self) -> Size; fn set_offset(&self, point: Point); fn offset(&self) -> Point; @@ -799,9 +821,6 @@ pub trait ScrollableHandle: 'static { fn content_size(&self) -> Size { self.viewport().size + self.max_offset() } - fn trackable_handle(&self) -> Option<&ScrollHandle> { - None - } } enum ScrollbarMouseEvent {