Some fixes, impl for uniformlist

This commit is contained in:
MrSubidubi 2025-08-16 00:36:11 +02:00
parent a9dbfce8f9
commit 3da0c0aa60
2 changed files with 104 additions and 94 deletions

View file

@ -4553,7 +4553,6 @@ impl OutlinePanel {
}; };
v_flex() v_flex()
.id("outline-panel-empty")
.flex_1() .flex_1()
.justify_center() .justify_center()
.size_full() .size_full()
@ -4703,19 +4702,20 @@ impl OutlinePanel {
), ),
) )
}) })
.custom_scrollbars(
Scrollbars::for_settings::<OutlinePanelSettings>()
.tracked_scroll_handle(self.scroll_handle.clone())
.with_track_along(ScrollAxes::Horizontal)
.tracked_entity(cx.entity()),
window,
cx,
)
}; };
v_flex() v_flex()
.flex_shrink() .flex_shrink()
.size_full() .size_full()
.child(list_contents.size_full().flex_shrink()) .child(list_contents.size_full().flex_shrink())
.custom_scrollbars(
Scrollbars::for_settings::<OutlinePanelSettings>()
.tracked_scroll_handle(self.scroll_handle.clone())
.with_track_along(ScrollAxes::Horizontal),
window,
cx,
)
} }
.children(self.context_menu.as_ref().map(|(menu, position, _)| { .children(self.context_menu.as_ref().map(|(menu, position, _)| {
deferred( deferred(

View file

@ -4,8 +4,8 @@ use gpui::{
Along, App, AppContext as _, Axis as ScrollbarAxis, BorderStyle, Bounds, ContentMask, Context, Along, App, AppContext as _, Axis as ScrollbarAxis, BorderStyle, Bounds, ContentMask, Context,
Corner, Corners, CursorStyle, Div, Edges, Element, ElementId, Entity, EntityId, Corner, Corners, CursorStyle, Div, Edges, Element, ElementId, Entity, EntityId,
GlobalElementId, Hitbox, HitboxBehavior, Hsla, InteractiveElement, IntoElement, IsZero, GlobalElementId, Hitbox, HitboxBehavior, Hsla, InteractiveElement, IntoElement, IsZero,
LayoutId, ListState, MouseButton, MouseDownEvent, MouseMoveEvent, MouseUpEvent, ParentElement, LayoutId, ListState, MouseButton, MouseDownEvent, MouseMoveEvent, MouseUpEvent, Negate,
Pixels, Point, Position, Render, ScrollHandle, ScrollWheelEvent, Size, Stateful, ParentElement, Pixels, Point, Position, Render, ScrollHandle, ScrollWheelEvent, Size, Stateful,
StatefulInteractiveElement, Style, Styled, Task, UniformList, UniformListDecoration, StatefulInteractiveElement, Style, Styled, Task, UniformList, UniformListDecoration,
UniformListScrollHandle, Window, prelude::FluentBuilder as _, px, quad, relative, size, UniformListScrollHandle, Window, prelude::FluentBuilder as _, px, quad, relative, size,
}; };
@ -217,9 +217,6 @@ where
{ {
let state = &scrollbar.read(cx).0; let state = &scrollbar.read(cx).0;
if state.read(cx).disabled() {
div
} else {
div.when_some(state.read(cx).handle_to_track(), |this, handle| { div.when_some(state.read(cx).handle_to_track(), |this, handle| {
this.track_scroll(handle) this.track_scroll(handle)
}) })
@ -234,7 +231,6 @@ where
|this, space| this.pr(space), |this, space| this.pr(space),
) )
.child(state.clone()) .child(state.clone())
}
} }
impl<S: ScrollbarVisibilitySetting, T: ScrollableHandle> UniformListDecoration impl<S: ScrollbarVisibilitySetting, T: ScrollableHandle> UniformListDecoration
@ -244,13 +240,14 @@ impl<S: ScrollbarVisibilitySetting, T: ScrollableHandle> UniformListDecoration
&self, &self,
_visible_range: Range<usize>, _visible_range: Range<usize>,
_bounds: Bounds<Pixels>, _bounds: Bounds<Pixels>,
_scroll_offset: Point<Pixels>, scroll_offset: Point<Pixels>,
_item_height: Pixels, _item_height: Pixels,
_item_count: usize, _item_count: usize,
_window: &mut Window, _window: &mut Window,
_cx: &mut App, _cx: &mut App,
) -> gpui::AnyElement { ) -> gpui::AnyElement {
ScrollbarElement { ScrollbarElement {
origin: scroll_offset.negate(),
state: self.0.clone(), state: self.0.clone(),
} }
.into_any() .into_any()
@ -558,7 +555,11 @@ impl<S: ScrollbarVisibilitySetting, T: ScrollableHandle> ScrollbarState<S, T> {
fn space_to_reserve_for(&self, axis: ScrollbarAxis) -> Option<Pixels> { fn space_to_reserve_for(&self, axis: ScrollbarAxis) -> Option<Pixels> {
(self.show_state.is_disabled().not() && self.visibility.along(axis).needs_scroll_track()) (self.show_state.is_disabled().not() && self.visibility.along(axis).needs_scroll_track())
.then(|| self.width.to_pixels() + 2 * SCROLLBAR_PADDING) .then(|| self.space_to_reserve())
}
fn space_to_reserve(&self) -> Pixels {
self.width.to_pixels() + 2 * SCROLLBAR_PADDING
} }
fn handle_to_track(&self) -> Option<&ScrollHandle> { fn handle_to_track(&self) -> Option<&ScrollHandle> {
@ -692,11 +693,15 @@ impl<S: ScrollbarVisibilitySetting, T: ScrollableHandle> ScrollbarState<S, T> {
impl<S: ScrollbarVisibilitySetting, T: ScrollableHandle> Render for ScrollbarState<S, T> { impl<S: ScrollbarVisibilitySetting, T: ScrollableHandle> Render for ScrollbarState<S, T> {
fn render(&mut self, _window: &mut Window, cx: &mut Context<Self>) -> impl IntoElement { fn render(&mut self, _window: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {
ScrollbarElement { state: cx.entity() } ScrollbarElement {
state: cx.entity(),
origin: Default::default(),
}
} }
} }
struct ScrollbarElement<S: ScrollbarVisibilitySetting, T: ScrollableHandle> { struct ScrollbarElement<S: ScrollbarVisibilitySetting, T: ScrollableHandle> {
origin: Point<Pixels>,
state: Entity<ScrollbarState<S, T>>, state: Entity<ScrollbarState<S, T>>,
} }
@ -912,7 +917,11 @@ impl<S: ScrollbarVisibilitySetting, T: ScrollableHandle> Element for ScrollbarEl
window: &mut Window, window: &mut Window,
cx: &mut App, cx: &mut App,
) -> Self::PrepaintState { ) -> Self::PrepaintState {
Some(ScrollbarPrepaintState { self.state
.read(cx)
.disabled()
.not()
.then(|| ScrollbarPrepaintState {
parent_bounds: bounds, parent_bounds: bounds,
thumbs: self thumbs: self
.state .state
@ -923,15 +932,16 @@ impl<S: ScrollbarVisibilitySetting, T: ScrollableHandle> Element for ScrollbarEl
ScrollbarAxis::Horizontal => Corner::BottomLeft, ScrollbarAxis::Horizontal => Corner::BottomLeft,
ScrollbarAxis::Vertical => Corner::TopRight, ScrollbarAxis::Vertical => Corner::TopRight,
}; };
let scroll_track_bounds = Bounds::from_corner_and_size( let Bounds { origin, size } = Bounds::from_corner_and_size(
track_anchor, track_anchor,
bounds bounds
.corner(track_anchor) .corner(track_anchor)
.apply_along(axis.invert(), |corner| corner - SCROLLBAR_PADDING), .apply_along(axis.invert(), |corner| corner - SCROLLBAR_PADDING),
bounds bounds.size.apply_along(axis.invert(), |_| {
.size self.state.read(cx).width.to_pixels()
.apply_along(axis.invert(), |_| self.state.read(cx).width.to_pixels()), }),
); );
let scroll_track_bounds = Bounds::new(self.origin + origin, size);
let padded_bounds = scroll_track_bounds.extend(match axis { let padded_bounds = scroll_track_bounds.extend(match axis {
ScrollbarAxis::Horizontal => Edges { ScrollbarAxis::Horizontal => Edges {
@ -981,17 +991,17 @@ impl<S: ScrollbarVisibilitySetting, T: ScrollableHandle> Element for ScrollbarEl
&mut self, &mut self,
_id: Option<&GlobalElementId>, _id: Option<&GlobalElementId>,
_inspector_id: Option<&gpui::InspectorElementId>, _inspector_id: Option<&gpui::InspectorElementId>,
bounds: Bounds<Pixels>, Bounds { origin, size }: Bounds<Pixels>,
_request_layout: &mut Self::RequestLayoutState, _request_layout: &mut Self::RequestLayoutState,
prepaint_state: &mut Self::PrepaintState, prepaint_state: &mut Self::PrepaintState,
window: &mut Window, window: &mut Window,
cx: &mut App, cx: &mut App,
) { ) {
// Practically, we'll never hit the case of this being none
let Some(prepaint_state) = prepaint_state.take() else { let Some(prepaint_state) = prepaint_state.take() else {
return; return;
}; };
let bounds = Bounds::new(self.origin + origin, size);
window.with_content_mask(Some(ContentMask { bounds }), |window| { window.with_content_mask(Some(ContentMask { bounds }), |window| {
let colors = cx.theme().colors(); let colors = cx.theme().colors();