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>
impl<S, M> ScrollArea<S, M>
Sourcepub fn scroll(
self,
read: impl Fn(&S) -> u16 + 'static,
on_change: impl Fn(u16) -> M + 'static,
) -> Self
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.
Sourcepub fn content(
self,
content: impl FnOnce(&mut DeclareCtx<'_, S, M>) + 'static,
) -> Self
pub fn content( self, content: impl FnOnce(&mut DeclareCtx<'_, S, M>) + 'static, ) -> Self
Declare the viewport’s descendants in their full logical content area.
Sourcepub fn style(self, style: impl Fn(&Theme) -> ScrollAreaStyle + 'static) -> Self
pub fn style(self, style: impl Fn(&Theme) -> ScrollAreaStyle + 'static) -> Self
Replace the theme-derived scrollbar style.
Sourcepub const fn hover_focus(self) -> Self
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>
impl<S: 'static, M: 'static> Component<S, M> for ScrollArea<S, M>
Source§fn declare(&mut self, ctx: &mut DeclareCtx<'_, S, M>)
fn declare(&mut self, ctx: &mut DeclareCtx<'_, S, M>)
handle_event will need to read
back. Read moreSource§fn handle_event(
&mut self,
event: &Event,
state: &S,
ctx: &mut EventCtx<'_>,
) -> EventResult<M>
fn handle_event( &mut self, event: &Event, state: &S, ctx: &mut EventCtx<'_>, ) -> EventResult<M>
Source§fn scope_options(&self) -> ScopeOptions
fn scope_options(&self) -> ScopeOptions
declare, so it cannot depend on paint.Source§fn prepare(&mut self, _state: &State)
fn prepare(&mut self, _state: &State)
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>
impl<S, M> Unpin for ScrollArea<S, M>
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> 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> 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