pub struct Scrollable<'a, Message, W = Element<'a, Message, Theme, Renderer<Renderer, Renderer>>, 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) -> Scrollable<'a, Message, W, Theme>
pub fn new(content: W) -> Scrollable<'a, Message, W, Theme>
Creates a new vertical Scrollable.
Sourcepub fn with_direction(
content: W,
direction: impl Into<Direction>,
) -> Scrollable<'a, Message, W, Theme>
pub fn with_direction( content: W, direction: impl Into<Direction>, ) -> Scrollable<'a, Message, W, Theme>
Creates a new Scrollable with the given Direction.
Sourcepub fn horizontal(self) -> Scrollable<'a, Message, W, Theme>
pub fn horizontal(self) -> Scrollable<'a, Message, W, Theme>
Makes the Scrollable scroll horizontally, with default Scrollbar settings.
Sourcepub fn direction(
self,
direction: impl Into<Direction>,
) -> Scrollable<'a, Message, W, Theme>
pub fn direction( self, direction: impl Into<Direction>, ) -> Scrollable<'a, Message, W, Theme>
Sets the Direction of the Scrollable.
Sourcepub fn id(self, id: impl Into<Id>) -> Scrollable<'a, Message, W, Theme>
pub fn id(self, id: impl Into<Id>) -> Scrollable<'a, Message, W, Theme>
Sets the widget::Id of the Scrollable.
Sourcepub fn width(
self,
width: impl Into<Length>,
) -> Scrollable<'a, Message, W, Theme>
pub fn width( self, width: impl Into<Length>, ) -> Scrollable<'a, Message, W, Theme>
Sets the width of the Scrollable.
Sourcepub fn height(
self,
height: impl Into<Length>,
) -> Scrollable<'a, Message, W, Theme>
pub fn height( self, height: impl Into<Length>, ) -> Scrollable<'a, Message, W, Theme>
Sets the height of the Scrollable.
Sourcepub fn on_scroll<T>(
self,
f: impl Fn(Scroll) -> T + 'a,
) -> Scrollable<'a, Message, W, Theme>
pub fn on_scroll<T>( self, f: impl Fn(Scroll) -> T + 'a, ) -> Scrollable<'a, Message, W, Theme>
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) -> Scrollable<'a, Message, W, Theme>
pub fn anchor_top(self) -> Scrollable<'a, Message, W, Theme>
Anchors the vertical Scrollable direction to the top.
Sourcepub fn anchor_bottom(self) -> Scrollable<'a, Message, W, Theme>
pub fn anchor_bottom(self) -> Scrollable<'a, Message, W, Theme>
Anchors the vertical Scrollable direction to the bottom.
Sourcepub fn anchor_left(self) -> Scrollable<'a, Message, W, Theme>
pub fn anchor_left(self) -> Scrollable<'a, Message, W, Theme>
Anchors the horizontal Scrollable direction to the left.
Sourcepub fn anchor_right(self) -> Scrollable<'a, Message, W, Theme>
pub fn anchor_right(self) -> Scrollable<'a, Message, W, Theme>
Anchors the horizontal Scrollable direction to the right.
Sourcepub fn anchor_x(self, alignment: Anchor) -> Scrollable<'a, Message, W, Theme>
pub fn anchor_x(self, alignment: Anchor) -> Scrollable<'a, Message, W, Theme>
Sets the Anchor of the horizontal direction of the Scrollable, if applicable.
Sourcepub fn anchor_y(self, alignment: Anchor) -> Scrollable<'a, Message, W, Theme>
pub fn anchor_y(self, alignment: Anchor) -> Scrollable<'a, Message, W, Theme>
Sets the Anchor of the vertical direction of the Scrollable, if applicable.
Sourcepub fn spacing(
self,
new_spacing: impl Into<Pixels>,
) -> Scrollable<'a, Message, W, Theme>
pub fn spacing( self, new_spacing: impl Into<Pixels>, ) -> Scrollable<'a, Message, W, Theme>
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>,
) -> Scrollable<'a, Message, W, Theme>
pub fn padding( self, new_padding: impl Into<Pixels>, ) -> Scrollable<'a, Message, W, Theme>
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) -> Scrollable<'a, Message, W, Theme>
pub fn auto_scroll(self, auto_scroll: bool) -> Scrollable<'a, Message, W, Theme>
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,
) -> Scrollable<'a, Message, W, Theme>
pub fn smooth_scroll( self, smooth_scroll: bool, ) -> Scrollable<'a, Message, W, Theme>
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,
) -> Scrollable<'a, Message, W, Theme>
pub fn click_to_scroll( self, click_to_scroll: bool, ) -> Scrollable<'a, Message, W, Theme>
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,
) -> Scrollable<'a, Message, W, Theme>
pub fn style( self, style: impl Fn(&Theme, Status) -> Style + 'a, ) -> Scrollable<'a, Message, W, Theme>
Sets the style of this Scrollable.
Sourcepub fn class(
self,
class: impl Into<<Theme as Catalog>::Class<'a>>,
) -> Scrollable<'a, Message, W, Theme>
Available on crate feature advanced only.
pub fn class( self, class: impl Into<<Theme as Catalog>::Class<'a>>, ) -> Scrollable<'a, Message, W, Theme>
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>
impl<Message, W, Theme, Renderer> Widget<Message, Theme, Renderer> for Scrollable<'_, Message, W, Theme>
Source§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, )
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<State, Message> IntoBoot<State, Message> for State
impl<State, Message> IntoBoot<State, Message> for State
Source§fn into_boot(self) -> (State, Task<Message>)
fn into_boot(self) -> (State, Task<Message>)
Application.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