Skip to main content

ScrollArea

Struct ScrollArea 

Source
pub struct ScrollArea<S, M> { /* private fields */ }
Expand description

A vertical viewport that hosts arbitrary interactive ratcn descendants.

One column is reserved at the right for the scrollbar. The content closure receives the remaining width and exactly content_height logical rows, however many of them are visible. The scrollbar is an indicator of where the view sits.

The offset is the area’s own until scroll binds it. Wheel, Page Up, Page Down, Home, and End reach descendants first; what none of them handles scrolls the area. An event that leaves the offset where it is — every one of these keys at an edge, and a horizontal wheel — bubbles on to the app, which keeps app hotkeys on those keys alive. The area is a fallback focus stop while it holds no focusable descendant, so keyboard scrolling works for paint-only content.

Focus moving to a descendant the viewport clips scrolls that descendant into view.

§Panics

A ScrollArea inside another ScrollArea panics, as does content larger than 262,144 cells, as does a single paint inside one covering more than that.

ctx.component(
    "settings",
    ScrollArea::new(40).content(|ctx| {
        ctx.component(
            "save",
            Button::new("Save").on_press(|| Msg::Saved),
            Rect::new(0, 0, 10, 3),
        );
    }),
    Rect::new(0, 0, 30, 10),
);

Implementations§

Source§

impl<S, M> ScrollArea<S, M>

Source

pub fn new(content_height: u16) -> Self

A viewport over content_height logical rows.

Source

pub fn scroll( self, read: impl Fn(&S) -> u16 + 'static, on_change: impl Fn(u16) -> M + 'static, ) -> Self

Bind the first visible content row to app state.

read is consulted for every event, so repeated wheel or page events compose before a redraw, and on_change carries each new offset to the app’s update. Left unbound, the area keeps the offset itself and emits nothing.

A reveal moves the view on its own, without a message; the next offset the area emits starts from where the reveal left it.

Source

pub fn content( self, content: impl FnOnce(&mut DeclareCtx<'_, S, M>) + 'static, ) -> Self

Declare the viewport’s descendants in their full logical content area.

Source

pub fn style(self, style: impl Fn(&Theme) -> ScrollAreaStyle + 'static) -> Self

Replace the theme-derived scrollbar style.

Source

pub const fn hover_focus(self) -> Self

Make pointer motion choose between the content’s direct child scopes.

This is opt-in so ordinary scrollable forms leave keyboard focus alone when the pointer drifts. It suits a scrollable pane or tile grid whose direct children are the regions focus should follow.

Trait Implementations§

Source§

impl<S: 'static, M: 'static> Component<S, M> for ScrollArea<S, M>

Source§

fn declare(&mut self, ctx: &mut DeclareCtx<'_, S, M>)

Declare the component: lay out its area, declare its descendants, and record whatever handle_event will need to read back. Read more
Source§

fn handle_event( &mut self, event: &Event, state: &S, ctx: &mut EventCtx<'_>, ) -> EventResult<M>

Offer this component an event. Read more
Source§

fn reveal_in_viewport( &mut self, target: Rect, state: &S, ctx: &mut EventCtx<'_>, )

Bring target into view inside this component’s viewport. Read more
Source§

fn scope_options(&self) -> ScopeOptions

The scope this component opens around its descendants. Read once, before declare, so it cannot depend on paint.
Source§

fn prepare(&mut self, _state: &State)

Prepare this component from the state it is being declared with. Read more
Source§

fn interaction_area(&self, area: Rect) -> Rect

Return the area used for focus, hit-testing, and event routing. Read more
Source§

fn paint(&mut self, _ctx: &mut PaintCtx<'_, State>)

Paint the component. ctx carries the paint surface, area, app state, theme, and interaction state. Read more
Source§

impl<S, M> Debug for ScrollArea<S, M>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<S, M> !RefUnwindSafe for ScrollArea<S, M>

§

impl<S, M> !Send for ScrollArea<S, M>

§

impl<S, M> !Sync for ScrollArea<S, M>

§

impl<S, M> !UnwindSafe for ScrollArea<S, M>

§

impl<S, M> Freeze for ScrollArea<S, M>
where Option<Box<dyn Fn(&S) -> u16>>: Freeze, Option<Box<dyn Fn(u16) -> M>>: Freeze, Option<Box<dyn FnOnce(&mut DeclareCtx<'_, S, M>)>>: Freeze,

§

impl<S, M> Unpin for ScrollArea<S, M>
where Option<Box<dyn Fn(&S) -> u16>>: Unpin, Option<Box<dyn Fn(u16) -> M>>: Unpin, Option<Box<dyn FnOnce(&mut DeclareCtx<'_, S, M>)>>: Unpin,

§

impl<S, M> UnsafeUnpin for ScrollArea<S, M>
where Option<Box<dyn Fn(&S) -> u16>>: UnsafeUnpin, Option<Box<dyn Fn(u16) -> M>>: UnsafeUnpin, Option<Box<dyn FnOnce(&mut DeclareCtx<'_, S, M>)>>: UnsafeUnpin,

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> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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

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

Source§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

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.