pub struct Scroll { /* private fields */ }Expand description
A scroll view
Implementations§
Source§impl Scroll
impl Scroll
Sourcepub fn new(child: impl IntoView) -> Self
pub fn new(child: impl IntoView) -> Self
Creates a new scroll view wrapping the given child view.
§Example
use floem::views::*;
let content = Label::new("Scrollable content");
let scrollable = Scroll::new(content);Sourcepub fn on_scroll(self, onscroll: impl Fn(Rect) + 'static) -> Self
pub fn on_scroll(self, onscroll: impl Fn(Rect) + 'static) -> Self
Sets a callback that will be triggered whenever the scroll position changes.
This callback receives the viewport rectangle that represents the currently visible portion of the scrollable content.
Sourcepub fn on_child_size(self, callback: impl Fn(Size) + 'static) -> Self
pub fn on_child_size(self, callback: impl Fn(Size) + 'static) -> Self
Sets a callback that will be triggered whenever the child’s size changes after layout.
This is useful for reactive code that needs to depend on the actual
laid-out size of the scroll content, ensuring proper ordering when
combined with ensure_visible.
Sourcepub fn ensure_visible(self, to: impl Fn() -> Rect + 'static) -> Self
pub fn ensure_visible(self, to: impl Fn() -> Rect + 'static) -> Self
Ensures that a specific rectangular area is visible within the scroll view by automatically scrolling to it if necessary.
§Reactivity
The viewport will automatically update to include the target rectangle whenever the rectangle’s
position or size changes, as determined by the to function which will update any time there are
changes in the signals that it depends on.
Sourcepub fn scroll_delta(self, delta: impl Fn() -> Vec2 + 'static) -> Self
pub fn scroll_delta(self, delta: impl Fn() -> Vec2 + 'static) -> Self
Scrolls the view by the specified delta vector.
§Reactivity
The scroll position will automatically update whenever the delta vector changes,
as determined by the delta function which will update any time there are changes in the signals that it depends on.
Sourcepub fn scroll_to(self, origin: impl Fn() -> Option<Point> + 'static) -> Self
pub fn scroll_to(self, origin: impl Fn() -> Option<Point> + 'static) -> Self
Scrolls the view to the specified target point.
§Reactivity
The scroll position will automatically update whenever the target point changes,
as determined by the origin function which will update any time there are changes in the signals that it depends on.
Sourcepub fn scroll_to_percent(self, percent: impl Fn() -> f32 + 'static) -> Self
pub fn scroll_to_percent(self, percent: impl Fn() -> f32 + 'static) -> Self
Scrolls the view to the specified percentage (0-100) of its scrollable content.
§Reactivity
The scroll position will automatically update whenever the target percentage changes,
as determined by the percent function which will update any time there are changes in the signals that it depends on.
Sourcepub fn scroll_to_view(self, view: impl Fn() -> Option<ViewId> + 'static) -> Self
pub fn scroll_to_view(self, view: impl Fn() -> Option<ViewId> + 'static) -> Self
Scrolls the view to make a specific view visible.
§Reactivity
The scroll position will automatically update whenever the target view changes,
as determined by the view function which will update any time there are changes in the signals that it depends on.
Sourcepub fn ensure_area_visible(
&mut self,
window_state: &mut WindowState,
rect: Rect,
)
pub fn ensure_area_visible( &mut self, window_state: &mut WindowState, rect: Rect, )
Ensure that an entire area is visible in the scroll view.
Sourcepub fn pan_to_visible(&mut self, window_state: &mut WindowState, rect: Rect)
pub fn pan_to_visible(&mut self, window_state: &mut WindowState, rect: Rect)
Pan the smallest distance that makes the target Rect visible.
If the target rect is larger than viewport size, we will prioritize the region of the target closest to its origin.
Sourcepub fn scroll_style(
self,
style: impl Fn(ScrollCustomStyle) -> ScrollCustomStyle + 'static,
) -> Self
pub fn scroll_style( self, style: impl Fn(ScrollCustomStyle) -> ScrollCustomStyle + 'static, ) -> Self
Sets the custom style properties of the Scroll.
Trait Implementations§
Source§impl CustomStylable<ScrollCustomStyle> for Scroll
impl CustomStylable<ScrollCustomStyle> for Scroll
Source§impl View for Scroll
impl View for Scroll
fn id(&self) -> ViewId
fn debug_name(&self) -> Cow<'static, str>
fn view_style(&self) -> Option<Style>
Source§fn update(&mut self, cx: &mut UpdateCx<'_>, state: Box<dyn Any>)
fn update(&mut self, cx: &mut UpdateCx<'_>, state: Box<dyn Any>)
View’s Id handle Read moreSource§fn scroll_to(
&mut self,
cx: &mut WindowState,
target: ViewId,
rect: Option<Rect>,
) -> bool
fn scroll_to( &mut self, cx: &mut WindowState, target: ViewId, rect: Option<Rect>, ) -> bool
target view to be
visible. Returns true if this view contains or is the target.Source§fn style_pass(&mut self, cx: &mut StyleCx<'_>)
fn style_pass(&mut self, cx: &mut StyleCx<'_>)
Source§fn compute_layout(&mut self, cx: &mut ComputeLayoutCx<'_>) -> Option<Rect>
fn compute_layout(&mut self, cx: &mut ComputeLayoutCx<'_>) -> Option<Rect>
fn event_before_children( &mut self, cx: &mut EventCx<'_>, event: &Event, ) -> EventPropagation
fn event_after_children( &mut self, cx: &mut EventCx<'_>, event: &Event, ) -> EventPropagation
Source§fn paint(&mut self, cx: &mut PaintCx<'_>)
fn paint(&mut self, cx: &mut PaintCx<'_>)
View-specific implementation. Will be called in PaintCx::paint_view.
Usually you’ll call paint_view for every child view. But you might also draw text, adjust the offset, clip
or draw text.fn view_class(&self) -> Option<StyleClassRef>
Auto Trait Implementations§
impl Freeze for Scroll
impl !RefUnwindSafe for Scroll
impl !Send for Scroll
impl !Sync for Scroll
impl Unpin for Scroll
impl !UnwindSafe for Scroll
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> ContainerExt for Twhere
T: IntoView + 'static,
impl<T> ContainerExt for Twhere
T: IntoView + 'static,
Source§impl<T> Decorators for Twhere
T: IntoView,
impl<T> Decorators for Twhere
T: IntoView,
Source§fn style(self, style: impl Fn(Style) -> Style + 'static) -> Self::Intermediate
fn style(self, style: impl Fn(Style) -> Style + 'static) -> Self::Intermediate
Source§fn debug_name(self, name: impl Into<String>) -> Self::Intermediate
fn debug_name(self, name: impl Into<String>) -> Self::Intermediate
Source§fn debug_name_if<S: Into<String>>(
self,
apply: impl Fn() -> bool + 'static,
name: impl Fn() -> S + 'static,
) -> Self::Intermediate
fn debug_name_if<S: Into<String>>( self, apply: impl Fn() -> bool + 'static, name: impl Fn() -> S + 'static, ) -> Self::Intermediate
Source§fn dragging_style(
self,
style: impl Fn(Style) -> Style + 'static,
) -> Self::Intermediate
fn dragging_style( self, style: impl Fn(Style) -> Style + 'static, ) -> Self::Intermediate
Source§fn class<C: StyleClass>(self, _class: C) -> Self::Intermediate
fn class<C: StyleClass>(self, _class: C) -> Self::Intermediate
Source§fn class_if<C: StyleClass>(
self,
apply: impl Fn() -> bool + 'static,
_class: C,
) -> Self::Intermediate
fn class_if<C: StyleClass>( self, apply: impl Fn() -> bool + 'static, _class: C, ) -> Self::Intermediate
Source§fn remove_class<C: StyleClass>(self, _class: C) -> Self::Intermediate
fn remove_class<C: StyleClass>(self, _class: C) -> Self::Intermediate
Style::focusable insteadSource§fn disable_default_event(
self,
disable: impl Fn() -> (EventListener, bool) + 'static,
) -> Self::Intermediate
fn disable_default_event( self, disable: impl Fn() -> (EventListener, bool) + 'static, ) -> Self::Intermediate
Source§fn draggable(self) -> Self::Intermediate
fn draggable(self) -> Self::Intermediate
Style::draggable directly insteadSource§fn disabled(
self,
disabled_fn: impl Fn() -> bool + 'static,
) -> Self::Intermediate
fn disabled( self, disabled_fn: impl Fn() -> bool + 'static, ) -> Self::Intermediate
Style::set_disabled directly insteadSource§fn on_event(
self,
listener: EventListener,
action: impl FnMut(&Event) -> EventPropagation + 'static,
) -> Self::Intermediate
fn on_event( self, listener: EventListener, action: impl FnMut(&Event) -> EventPropagation + 'static, ) -> Self::Intermediate
EventListener.Source§fn on_key_down(
self,
key: Key,
cmp: impl Fn(Modifiers) -> bool + 'static,
action: impl Fn(&Event) + 'static,
) -> Self::Intermediate
fn on_key_down( self, key: Key, cmp: impl Fn(Modifiers) -> bool + 'static, action: impl Fn(&Event) + 'static, ) -> Self::Intermediate
Source§fn on_key_up(
self,
key: Key,
cmp: impl Fn(Modifiers) -> bool + 'static,
action: impl Fn(&Event) + 'static,
) -> Self::Intermediate
fn on_key_up( self, key: Key, cmp: impl Fn(Modifiers) -> bool + 'static, action: impl Fn(&Event) + 'static, ) -> Self::Intermediate
Source§fn on_event_cont(
self,
listener: EventListener,
action: impl Fn(&Event) + 'static,
) -> Self::Intermediate
fn on_event_cont( self, listener: EventListener, action: impl Fn(&Event) + 'static, ) -> Self::Intermediate
EventListener. This event will be handled with
the given handler and the event will continue propagating.Source§fn on_event_stop(
self,
listener: EventListener,
action: impl Fn(&Event) + 'static,
) -> Self::Intermediate
fn on_event_stop( self, listener: EventListener, action: impl Fn(&Event) + 'static, ) -> Self::Intermediate
EventListener. This event will be handled with
the given handler and the event will stop propagating.Source§fn on_click(
self,
action: impl FnMut(&Event) -> EventPropagation + 'static,
) -> Self::Intermediate
fn on_click( self, action: impl FnMut(&Event) -> EventPropagation + 'static, ) -> Self::Intermediate
EventListener::Click.Source§fn on_click_cont(self, action: impl Fn(&Event) + 'static) -> Self::Intermediate
fn on_click_cont(self, action: impl Fn(&Event) + 'static) -> Self::Intermediate
EventListener::Click. This event will be handled with
the given handler and the event will continue propagating.Source§fn on_click_stop(
self,
action: impl FnMut(&Event) + 'static,
) -> Self::Intermediate
fn on_click_stop( self, action: impl FnMut(&Event) + 'static, ) -> Self::Intermediate
EventListener::Click. This event will be handled with
the given handler and the event will stop propagating.Source§fn action(self, action: impl FnMut() + 'static) -> Self::Intermediate
fn action(self, action: impl FnMut() + 'static) -> Self::Intermediate
Source§fn on_double_click(
self,
action: impl Fn(&Event) -> EventPropagation + 'static,
) -> Self::Intermediate
fn on_double_click( self, action: impl Fn(&Event) -> EventPropagation + 'static, ) -> Self::Intermediate
EventListener::DoubleClickSource§fn on_double_click_cont(
self,
action: impl Fn(&Event) + 'static,
) -> Self::Intermediate
fn on_double_click_cont( self, action: impl Fn(&Event) + 'static, ) -> Self::Intermediate
EventListener::DoubleClick. This event will be handled with
the given handler and the event will continue propagating.Source§fn on_double_click_stop(
self,
action: impl Fn(&Event) + 'static,
) -> Self::Intermediate
fn on_double_click_stop( self, action: impl Fn(&Event) + 'static, ) -> Self::Intermediate
EventListener::DoubleClick. This event will be handled with
the given handler and the event will stop propagating.Source§fn on_secondary_click(
self,
action: impl Fn(&Event) -> EventPropagation + 'static,
) -> Self::Intermediate
fn on_secondary_click( self, action: impl Fn(&Event) -> EventPropagation + 'static, ) -> Self::Intermediate
EventListener::SecondaryClick. This is most often the “Right” click.Source§fn on_secondary_click_cont(
self,
action: impl Fn(&Event) + 'static,
) -> Self::Intermediate
fn on_secondary_click_cont( self, action: impl Fn(&Event) + 'static, ) -> Self::Intermediate
EventListener::SecondaryClick. This is most often the “Right” click.
This event will be handled with the given handler and the event will continue propagating.Source§fn on_secondary_click_stop(
self,
action: impl Fn(&Event) + 'static,
) -> Self::Intermediate
fn on_secondary_click_stop( self, action: impl Fn(&Event) + 'static, ) -> Self::Intermediate
EventListener::SecondaryClick. This is most often the “Right” click.
This event will be handled with the given handler and the event will stop propagating.Source§fn on_resize(self, action: impl Fn(Rect) + 'static) -> Self::Intermediate
fn on_resize(self, action: impl Fn(Rect) + 'static) -> Self::Intermediate
Source§fn on_move(self, action: impl Fn(Point) + 'static) -> Self::Intermediate
fn on_move(self, action: impl Fn(Point) + 'static) -> Self::Intermediate
Source§fn on_cleanup(self, action: impl Fn() + 'static) -> Self::Intermediate
fn on_cleanup(self, action: impl Fn() + 'static) -> Self::Intermediate
Source§fn animation(
self,
animation: impl Fn(Animation) -> Animation + 'static,
) -> Self::Intermediate
fn animation( self, animation: impl Fn(Animation) -> Animation + 'static, ) -> Self::Intermediate
Source§fn clear_focus(self, when: impl Fn() + 'static) -> Self::Intermediate
fn clear_focus(self, when: impl Fn() + 'static) -> Self::Intermediate
Source§fn request_focus(self, when: impl Fn() + 'static) -> Self::Intermediate
fn request_focus(self, when: impl Fn() + 'static) -> Self::Intermediate
Source§fn window_scale(
self,
scale_fn: impl Fn() -> f64 + 'static,
) -> Self::Intermediate
fn window_scale( self, scale_fn: impl Fn() -> f64 + 'static, ) -> Self::Intermediate
Source§fn window_title(
self,
title_fn: impl Fn() -> String + 'static,
) -> Self::Intermediate
fn window_title( self, title_fn: impl Fn() -> String + 'static, ) -> Self::Intermediate
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more