Impl InteractiveElement, StatefulInteractiveElement for Scrollable.
This commit is contained in:
parent
030a706a4c
commit
6b019e3954
2 changed files with 22 additions and 8 deletions
|
|
@ -183,8 +183,8 @@ impl Render for ScrollableStory {
|
||||||
.child(
|
.child(
|
||||||
v_flex()
|
v_flex()
|
||||||
.id("test-1")
|
.id("test-1")
|
||||||
.focusable()
|
|
||||||
.scrollable(cx.view().clone(), ScrollbarAxis::Vertical)
|
.scrollable(cx.view().clone(), ScrollbarAxis::Vertical)
|
||||||
|
.focusable()
|
||||||
.p_3()
|
.p_3()
|
||||||
.w(test_width)
|
.w(test_width)
|
||||||
.gap_1()
|
.gap_1()
|
||||||
|
|
|
||||||
|
|
@ -2,9 +2,9 @@ use std::{cell::Cell, rc::Rc};
|
||||||
|
|
||||||
use super::{Scrollbar, ScrollbarAxis, ScrollbarState};
|
use super::{Scrollbar, ScrollbarAxis, ScrollbarState};
|
||||||
use gpui::{
|
use gpui::{
|
||||||
canvas, div, relative, AnyElement, AnyView, Element, ElementId, GlobalElementId,
|
canvas, div, relative, AnyElement, AnyView, Div, Element, ElementId, GlobalElementId,
|
||||||
InteractiveElement as _, IntoElement, ParentElement, Pixels, Position, ScrollHandle,
|
InteractiveElement, IntoElement, ParentElement, Pixels, Position, ScrollHandle, SharedString,
|
||||||
SharedString, Size, StatefulInteractiveElement, Style, StyleRefinement, Styled, WindowContext,
|
Size, Stateful, StatefulInteractiveElement, Style, StyleRefinement, Styled, WindowContext,
|
||||||
};
|
};
|
||||||
|
|
||||||
/// A scroll view is a container that allows the user to scroll through a large amount of content.
|
/// A scroll view is a container that allows the user to scroll through a large amount of content.
|
||||||
|
|
@ -13,8 +13,8 @@ pub struct Scrollable<E> {
|
||||||
element: Option<E>,
|
element: Option<E>,
|
||||||
view: AnyView,
|
view: AnyView,
|
||||||
axis: ScrollbarAxis,
|
axis: ScrollbarAxis,
|
||||||
/// This is not used yet.
|
/// This is a fake element to handle Styled, InteractiveElement, not used.
|
||||||
_style: StyleRefinement,
|
_element: Stateful<Div>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<E> Scrollable<E>
|
impl<E> Scrollable<E>
|
||||||
|
|
@ -31,10 +31,10 @@ where
|
||||||
|
|
||||||
Self {
|
Self {
|
||||||
element: Some(element),
|
element: Some(element),
|
||||||
|
_element: div().id("fake"),
|
||||||
id,
|
id,
|
||||||
view,
|
view,
|
||||||
axis,
|
axis,
|
||||||
_style: StyleRefinement::default(),
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -105,11 +105,25 @@ where
|
||||||
if let Some(element) = &mut self.element {
|
if let Some(element) = &mut self.element {
|
||||||
element.style()
|
element.style()
|
||||||
} else {
|
} else {
|
||||||
&mut self._style
|
self._element.style()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl<E> InteractiveElement for Scrollable<E>
|
||||||
|
where
|
||||||
|
E: Element + InteractiveElement,
|
||||||
|
{
|
||||||
|
fn interactivity(&mut self) -> &mut gpui::Interactivity {
|
||||||
|
if let Some(element) = &mut self.element {
|
||||||
|
element.interactivity()
|
||||||
|
} else {
|
||||||
|
self._element.interactivity()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
impl<E> StatefulInteractiveElement for Scrollable<E> where E: Element + StatefulInteractiveElement {}
|
||||||
|
|
||||||
impl<E> IntoElement for Scrollable<E>
|
impl<E> IntoElement for Scrollable<E>
|
||||||
where
|
where
|
||||||
E: Element,
|
E: Element,
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue