Skip to main content

ScrollView

Struct ScrollView 

Source
pub struct ScrollView { /* private fields */ }
Expand description

Scrollable area with bidirectional support and scrollbars.

It renders all of its children and scrolls over them, which makes it a good fit for small or medium amounts of content. For large data sets prefer VirtualScrollView, which only renders the visible items. It scrolls vertically by default, use direction for a horizontal layout. To drive the scroll position from code, build it with new_controlled and a ScrollController.

§Example

fn app() -> impl IntoElement {
    ScrollView::new()
        .child("Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vestibulum laoreet tristique diam, ut gravida enim. Phasellus viverra vitae risus sit amet iaculis. Morbi porttitor quis nisl eu vulputate. Etiam vitae ligula a purus suscipit iaculis non ac risus. Suspendisse potenti. Aenean orci massa, ornare ut elit id, tristique commodo dui. Vestibulum laoreet tristique diam, ut gravida enim. Phasellus viverra vitae risus sit amet iaculis. Vestibulum laoreet tristique diam, ut gravida enim. Phasellus viverra vitae risus sit amet iaculis. Vestibulum laoreet tristique diam, ut gravida enim. Phasellus viverra vitae risus sit amet iaculis.")
}

§Preview

ScrollView Preview

Implementations§

Source§

impl ScrollView

Source

pub fn new() -> Self

Creates an uncontrolled scroll view that manages its own scroll position.

Source

pub fn new_controlled(scroll_controller: ScrollController) -> Self

Creates a scroll view driven by the given ScrollController.

Source

pub fn show_scrollbar(self, show_scrollbar: bool) -> Self

Toggles whether the scrollbars are shown when the content overflows.

Source

pub fn direction(self, direction: Direction) -> Self

Sets the layout direction the children flow and scroll in.

Source

pub fn spacing(self, spacing: impl Into<f32>) -> Self

Sets the gap between children along the scroll direction.

Source

pub fn scroll_with_arrows(self, scroll_with_arrows: impl Into<bool>) -> Self

Toggles whether the arrow keys scroll the view while it is focused.

Source

pub fn invert_scroll_wheel(self, invert_scroll_wheel: impl Into<bool>) -> Self

Inverts the direction of the mouse wheel relative to the content.

Source

pub fn drag_scrolling(self, drag_scrolling: bool) -> Self

Toggles scrolling by dragging the content, useful mainly for touch input.

Source

pub fn max_width(self, max_width: impl Into<Size>) -> Self

Caps the width of the scroll view.

Source

pub fn max_height(self, max_height: impl Into<Size>) -> Self

Caps the height of the scroll view.

Trait Implementations§

Source§

impl ChildrenExt for ScrollView

Source§

fn get_children(&mut self) -> &mut Vec<Element>

Returns a mutable reference to the internal children vector. Read more
§

fn children(self, children: impl IntoIterator<Item = Element>) -> Self

Extends the children with an iterable of [Element]s. Read more
§

fn maybe_child<C>(self, child: Option<C>) -> Self
where C: IntoElement,

Appends a child only when the Option is Some. Read more
§

fn child<C>(self, child: C) -> Self
where C: IntoElement,

Appends a single child element. Read more
Source§

impl Clone for ScrollView

Source§

fn clone(&self) -> ScrollView

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Component for ScrollView

Source§

fn render(self: &ScrollView) -> impl IntoElement

Source§

fn render_key(&self) -> DiffKey

Source§

impl ContainerPositionExt for ScrollView

§

fn position(self, position: impl Into<Position>) -> Self

Set how the element is placed relative to its parent or the window. See [Position].
Source§

impl ContainerSizeExt for ScrollView

§

fn width(self, width: impl Into<Size>) -> Self

Set the element’s width. See [Size].
§

fn height(self, height: impl Into<Size>) -> Self

Set the element’s height. See [Size].
§

fn expanded(self) -> Self

Expand both width and height using [Size::fill()].
Source§

impl Default for ScrollView

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl KeyExt for ScrollView

Source§

fn write_key(&mut self) -> &mut DiffKey

Returns a mutable reference to the element’s diff key.
§

fn key(self, key: impl Hash) -> Self

Assign a key derived from any hashable value, used to reconcile elements in dynamic lists.
Source§

impl LayoutExt for ScrollView

Source§

fn get_layout(&mut self) -> &mut LayoutData

Returns a mutable reference to the element’s layout data.
§

fn layout(self, layout: LayoutData) -> Self

Replace all of the element’s layout data at once. See [LayoutData].
Source§

impl PartialEq for ScrollView

Source§

fn eq(&self, other: &ScrollView) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl StructuralPartialEq for ScrollView

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
§

impl<T> ComponentKey for T
where T: Component,

§

fn default_key(&self) -> DiffKey

§

impl<T> ComponentProps for T
where T: Any + PartialEq,

§

fn changed(&self, other: &(dyn ComponentProps + 'static)) -> bool

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
§

impl<T> IntoElement for T
where T: Into<Element>,

§

fn into_element(self) -> Element

§

impl<T> IntoReadable<T> for T
where T: 'static + PartialEq,

§

fn into_readable(self) -> Readable<T>

§

impl<T> MaybeExt for T
where T: Component,

§

fn maybe(self, bool: impl Into<bool>, then: impl FnOnce(Self) -> Self) -> Self

Apply then to the element only when the condition is true.
§

fn map<T>(self, data: Option<T>, then: impl FnOnce(Self, T) -> Self) -> Self

Apply then to the element only when the Option is Some, passing the inner value.
§

impl<T> PolicyExt for T
where T: ?Sized,

§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns [Action::Follow] only if self and other return Action::Follow. Read more
§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns [Action::Follow] if either self or other returns Action::Follow. Read more
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more
Source§

impl<T> AutoreleaseSafe for T
where T: ?Sized,

Source§

impl<T> AutoreleaseSafe for T
where T: ?Sized,