pub struct Scrollable<'a, Message, W = Element<'a, Message>, Theme = Theme>where
Theme: Catalog,{ /* private fields */ }Expand description
A widget that can vertically display an infinite amount of content with a scrollbar.
§Example
use iced::widget::{column, scrollable, space};
enum Message {
// ...
}
fn view(state: &State) -> impl Widget<Message> {
scrollable(column![
"Scroll me!",
space().height(3000),
"You did it!",
])
}§Scrollbars
A scrollbar has two interactive parts: the scroller (the draggable thumb) and the rail (the track it slides on).
- Pressing and dragging the scroller moves it 1:1 with the pointer.
- Pressing the rail scrolls one page (animated like a wheel scroll
when
Self::smooth_scrollis enabled). While the button is held, the scroller then slides toward the pointer at a constant speed, stopping when its edge reaches the pointer; moving the pointer moves the target with it. This mirrors the track autoscroll of most toolkits. Shift-clicking the rail instead jumps the scroller so that its center is under the pointer, and then drags it from there.
With Self::click_to_scroll enabled, the behavior of the rail press
and the Shift-click is inverted.
Implementations§
Source§impl<'a, Message, W, Theme> Scrollable<'a, Message, W, Theme>where
Theme: Catalog,
impl<'a, Message, W, Theme> Scrollable<'a, Message, W, Theme>where
Theme: Catalog,
Sourcepub fn new(content: W) -> Self
pub fn new(content: W) -> Self
Creates a new vertical Scrollable.
Sourcepub fn with_direction(content: W, direction: impl Into<Direction>) -> Self
pub fn with_direction(content: W, direction: impl Into<Direction>) -> Self
Creates a new Scrollable with the given Direction.
Sourcepub fn horizontal(self) -> Self
pub fn horizontal(self) -> Self
Makes the Scrollable scroll horizontally, with default Scrollbar settings.
Sourcepub fn direction(self, direction: impl Into<Direction>) -> Self
pub fn direction(self, direction: impl Into<Direction>) -> Self
Sets the Direction of the Scrollable.
Sourcepub fn id(self, id: impl Into<Id>) -> Self
pub fn id(self, id: impl Into<Id>) -> Self
Sets the widget::Id of the Scrollable.
Sourcepub fn width(self, width: impl Into<Length>) -> Self
pub fn width(self, width: impl Into<Length>) -> Self
Sets the width of the Scrollable.
Sourcepub fn height(self, height: impl Into<Length>) -> Self
pub fn height(self, height: impl Into<Length>) -> Self
Sets the height of the Scrollable.
Sourcepub fn on_scroll<T>(self, f: impl Fn(Scroll) -> T + 'a) -> Self
pub fn on_scroll<T>(self, f: impl Fn(Scroll) -> T + 'a) -> Self
Sets a handler to call when the Scrollable is scrolled.
The function takes a Scroll, which contains the Viewport of
the Scrollable and the Source of the scroll that caused the
notification.
Sourcepub fn anchor_top(self) -> Self
pub fn anchor_top(self) -> Self
Anchors the vertical Scrollable direction to the top.
Sourcepub fn anchor_bottom(self) -> Self
pub fn anchor_bottom(self) -> Self
Anchors the vertical Scrollable direction to the bottom.
Sourcepub fn anchor_left(self) -> Self
pub fn anchor_left(self) -> Self
Anchors the horizontal Scrollable direction to the left.
Sourcepub fn anchor_right(self) -> Self
pub fn anchor_right(self) -> Self
Anchors the horizontal Scrollable direction to the right.
Sourcepub fn anchor_x(self, alignment: Anchor) -> Self
pub fn anchor_x(self, alignment: Anchor) -> Self
Sets the Anchor of the horizontal direction of the Scrollable, if applicable.
Sourcepub fn anchor_y(self, alignment: Anchor) -> Self
pub fn anchor_y(self, alignment: Anchor) -> Self
Sets the Anchor of the vertical direction of the Scrollable, if applicable.
Sourcepub fn spacing(self, new_spacing: impl Into<Pixels>) -> Self
pub fn spacing(self, new_spacing: impl Into<Pixels>) -> Self
Embeds the Scrollbar into the Scrollable, instead of floating on top of the
content.
The spacing provided will be used as space between the Scrollbar and the contents
of the Scrollable.
Sourcepub fn padding(self, new_padding: impl Into<Pixels>) -> Self
pub fn padding(self, new_padding: impl Into<Pixels>) -> Self
Adds padding at the ends of the Scrollbars of the Scrollable.
The padding provided will be used as space at the top and bottom of a
vertical Scrollbar, and at the left and right ends of a horizontal
Scrollbar, when they are visible.
Unlike Self::spacing, the padding does not affect the layout of the
Scrollable.
Sourcepub fn auto_scroll(self, auto_scroll: bool) -> Self
pub fn auto_scroll(self, auto_scroll: bool) -> Self
Sets whether the user should be allowed to auto-scroll the Scrollable
with the middle mouse button.
By default, it is disabled.
Sourcepub fn smooth_scroll(self, smooth_scroll: bool) -> Self
pub fn smooth_scroll(self, smooth_scroll: bool) -> Self
Sets whether wheel scrolling should be smoothed out over time, instead of
moving the Scrollable immediately.
When enabled, discrete scrolls (e.g. from a mouse wheel) move a target
scroll offset — carrying the momentum of the wheel notches — and the
Scrollable eases towards it over a few frames. High-precision
scrolls (e.g. from a touchpad), which are already smooth, are always
applied immediately.
The setting also acts as the default behavior of the scroll operations
(snap_to, scroll_to, scroll_by): operations with
[Animation::Auto] scroll smoothly if and only if it is enabled.
By default, it is enabled.
Sourcepub fn click_to_scroll(self, click_to_scroll: bool) -> Self
pub fn click_to_scroll(self, click_to_scroll: bool) -> Self
Sets whether a plain click on the scrollbar rail should jump the scroller to the click position, instead of scrolling one page.
By default, a press on the rail scrolls one page (and autoscrolls
while the button is held), while a Shift-click jumps the scroller
so that its center is under the pointer and drags it from there.
When enabled, the behavior is inverted: a plain click jumps the
scroller so that its center is under the pointer (and drags it from
there), while a Shift-click scrolls one page (and autoscrolls
while the button is held).
By default, it is disabled.
Sourcepub fn style(self, style: impl Fn(&Theme, Status) -> Style + 'a) -> Self
pub fn style(self, style: impl Fn(&Theme, Status) -> Style + 'a) -> Self
Sets the style of this Scrollable.
Sourcepub fn class(self, class: impl Into<Theme::Class<'a>>) -> Self
Available on crate feature advanced only.
pub fn class(self, class: impl Into<Theme::Class<'a>>) -> Self
advanced only.Sets the style class of the Scrollable.
Trait Implementations§
Source§impl<Message, W, Theme> Meta for Scrollable<'_, Message, W, Theme>where
Theme: Catalog,
impl<Message, W, Theme> Meta for Scrollable<'_, Message, W, Theme>where
Theme: Catalog,
Source§impl<Message, W, Theme, Renderer> Widget<Message, Theme, Renderer> for Scrollable<'_, Message, W, Theme>where
Theme: Catalog,
Renderer: Renderer,
W: Widget<Message, Theme, Renderer>,
impl<Message, W, Theme, Renderer> Widget<Message, Theme, Renderer> for Scrollable<'_, Message, W, Theme>where
Theme: Catalog,
Renderer: Renderer,
W: Widget<Message, Theme, Renderer>,
Source§fn layout(&mut self, tree: &mut Tree, renderer: &Renderer, limits: &Limits)
fn layout(&mut self, tree: &mut Tree, renderer: &Renderer, limits: &Limits)
Widget]. Read moreSource§fn operate(
&mut self,
tree: &mut Tree,
layout: Layout,
viewport: &Rectangle,
renderer: &Renderer,
operation: &mut dyn Operation,
)
fn operate( &mut self, tree: &mut Tree, layout: Layout, viewport: &Rectangle, renderer: &Renderer, operation: &mut dyn Operation, )
Operation] to the [Widget].Source§fn update(
&mut self,
tree: &mut Tree,
event: &Event,
layout: Layout,
cursor: Cursor,
renderer: &Renderer,
shell: &mut Shell<'_, Message>,
viewport: &Rectangle,
)
fn update( &mut self, tree: &mut Tree, event: &Event, layout: Layout, cursor: Cursor, renderer: &Renderer, shell: &mut Shell<'_, Message>, viewport: &Rectangle, )
Source§fn draw(
&self,
tree: &Tree,
renderer: &mut Renderer,
theme: &Theme,
defaults: &Style,
layout: Layout,
cursor: Cursor,
viewport: &Rectangle,
)
fn draw( &self, tree: &Tree, renderer: &mut Renderer, theme: &Theme, defaults: &Style, layout: Layout, cursor: Cursor, viewport: &Rectangle, )
Widget] using the associated Renderer.Source§fn mouse_interaction(
&self,
tree: &Tree,
layout: Layout,
cursor: Cursor,
viewport: &Rectangle,
renderer: &Renderer,
) -> Interaction
fn mouse_interaction( &self, tree: &Tree, layout: Layout, cursor: Cursor, viewport: &Rectangle, renderer: &Renderer, ) -> Interaction
Source§fn overlay<'b>(
&'b mut self,
tree: &'b mut Tree,
layout: Layout,
renderer: &Renderer,
viewport: &Rectangle,
translation: Vector,
window: Size,
) -> Vec<Element<'b, Message, Theme, Renderer>>
fn overlay<'b>( &'b mut self, tree: &'b mut Tree, layout: Layout, renderer: &Renderer, viewport: &Rectangle, translation: Vector, window: Size, ) -> Vec<Element<'b, Message, Theme, Renderer>>
Widget].Auto Trait Implementations§
impl<'a, Message, W, Theme> Freeze for Scrollable<'a, Message, W, Theme>
impl<'a, Message, W = Element<'a, Message, Theme, Renderer<Renderer, Renderer>>, Theme = Theme> !RefUnwindSafe for Scrollable<'a, Message, W, Theme>
impl<'a, Message, W = Element<'a, Message, Theme, Renderer<Renderer, Renderer>>, Theme = Theme> !Send for Scrollable<'a, Message, W, Theme>
impl<'a, Message, W = Element<'a, Message, Theme, Renderer<Renderer, Renderer>>, Theme = Theme> !Sync for Scrollable<'a, Message, W, Theme>
impl<'a, Message, W, Theme> Unpin for Scrollable<'a, Message, W, Theme>
impl<'a, Message, W, Theme> UnsafeUnpin for Scrollable<'a, Message, W, Theme>
impl<'a, Message, W = Element<'a, Message, Theme, Renderer<Renderer, Renderer>>, Theme = Theme> !UnwindSafe for Scrollable<'a, Message, W, Theme>
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
§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can
then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be
further downcast into Rc<ConcreteType> where ConcreteType implements Trait.§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§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