pub struct Stack<A> { /* private fields */ }
Expand description
A stack of widgets
A stack consists a set of child widgets, “pages”, all of equal size.
Only a single page is visible at a time. The page is “turned” by calling
Self::set_active
.
By default, all pages are configured and sized. To avoid configuring
hidden pages (thus preventing these pages from affecting size)
call Self::set_size_limit
or Self::with_size_limit
.
§Messages
kas::messages::SetIndex
may be used to change the page.
Implementations§
Source§impl<A> Stack<A>
impl<A> Stack<A>
Sourcepub fn new() -> Self
pub fn new() -> Self
Construct a new, empty instance
See also Stack::from
.
Sourcepub fn set_size_limit(&mut self, limit: usize)
pub fn set_size_limit(&mut self, limit: usize)
Limit the number of pages considered and sized
By default, this is usize::MAX
: all pages are configured and affect
the stack’s size requirements.
Set this to 0 to avoid configuring all hidden pages.
Set this to n
to configure the active page and the first n
pages.
Sourcepub fn with_size_limit(self, limit: usize) -> Self
pub fn with_size_limit(self, limit: usize) -> Self
Limit the number of pages configured and sized (inline)
By default, this is usize::MAX
: all pages are configured and affect
the stack’s size requirements.
Set this to 0 to avoid configuring all hidden pages.
Set this to n
to configure the active page and the first n
pages.
Sourcepub fn with_active(self, active: usize) -> Self
pub fn with_active(self, active: usize) -> Self
Set the active widget (inline)
Unlike Self::set_active
, this does not update anything; it is
assumed that this method is only used before the UI is run.
Sourcepub fn set_active(&mut self, cx: &mut ConfigCx<'_>, data: &A, index: usize)
pub fn set_active(&mut self, cx: &mut ConfigCx<'_>, data: &A, index: usize)
Set the active page
Sourcepub fn get_active(&self) -> Option<&Page<A>>
pub fn get_active(&self) -> Option<&Page<A>>
Get a direct reference to the active child page, if any
Sourcepub fn get_mut(&mut self, index: usize) -> Option<&mut Page<A>>
pub fn get_mut(&mut self, index: usize) -> Option<&mut Page<A>>
Returns a mutable reference to the page, if any
Sourcepub fn push(&mut self, cx: &mut ConfigCx<'_>, data: &A, page: Page<A>) -> usize
pub fn push(&mut self, cx: &mut ConfigCx<'_>, data: &A, page: Page<A>) -> usize
Append a page
The new page is not made active (the active index may be changed to
avoid this). Consider calling Self::set_active
.
Returns the new page’s index.
Sourcepub fn pop(&mut self, cx: &mut EventState) -> Option<Page<A>>
pub fn pop(&mut self, cx: &mut EventState) -> Option<Page<A>>
Remove the last child widget (if any) and return
If this page was active then no page will be left active.
Consider also calling Self::set_active
.
Sourcepub fn insert(
&mut self,
cx: &mut ConfigCx<'_>,
data: &A,
index: usize,
page: Page<A>,
)
pub fn insert( &mut self, cx: &mut ConfigCx<'_>, data: &A, index: usize, page: Page<A>, )
Inserts a child widget position index
Panics if index > len
.
The active page does not change (the index of the active page may change instead).
Sourcepub fn remove(&mut self, cx: &mut EventState, index: usize) -> Page<A>
pub fn remove(&mut self, cx: &mut EventState, index: usize) -> Page<A>
Removes the child widget at position index
Panics if index
is out of bounds.
If this page was active then no page will be left active.
Consider also calling Self::set_active
.
Sourcepub fn replace(
&mut self,
cx: &mut ConfigCx<'_>,
data: &A,
index: usize,
page: Page<A>,
) -> Page<A>
pub fn replace( &mut self, cx: &mut ConfigCx<'_>, data: &A, index: usize, page: Page<A>, ) -> Page<A>
Replace the child at index
Panics if index
is out of bounds.
If the new child replaces the active page then Action::RESIZE
is triggered.
Sourcepub fn extend<T: IntoIterator<Item = Page<A>>>(
&mut self,
cx: &mut ConfigCx<'_>,
data: &A,
iter: T,
)
pub fn extend<T: IntoIterator<Item = Page<A>>>( &mut self, cx: &mut ConfigCx<'_>, data: &A, iter: T, )
Append child widgets from an iterator
The new pages are not made active (the active index may be changed to
avoid this). Consider calling Self::set_active
.
Sourcepub fn resize_with<F: Fn(usize) -> Page<A>>(
&mut self,
cx: &mut ConfigCx<'_>,
data: &A,
len: usize,
f: F,
)
pub fn resize_with<F: Fn(usize) -> Page<A>>( &mut self, cx: &mut ConfigCx<'_>, data: &A, len: usize, f: F, )
Resize, using the given closure to construct new widgets
The new pages are not made active (the active index may be changed to
avoid this). Consider calling Self::set_active
.
Trait Implementations§
Source§impl<A> Events for Stack<A>
impl<A> Events for Stack<A>
Source§fn configure_recurse(&mut self, cx: &mut ConfigCx<'_>, data: &Self::Data)
fn configure_recurse(&mut self, cx: &mut ConfigCx<'_>, data: &Self::Data)
Source§fn handle_messages(&mut self, cx: &mut EventCx<'_>, data: &A)
fn handle_messages(&mut self, cx: &mut EventCx<'_>, data: &A)
Source§const REDRAW_ON_MOUSE_OVER: bool = false
const REDRAW_ON_MOUSE_OVER: bool = false
Source§fn mouse_over_icon(&self) -> Option<CursorIcon>
fn mouse_over_icon(&self) -> Option<CursorIcon>
Source§fn update(&mut self, cx: &mut ConfigCx<'_>, data: &Self::Data)
fn update(&mut self, cx: &mut ConfigCx<'_>, data: &Self::Data)
Source§fn update_recurse(&mut self, cx: &mut ConfigCx<'_>, data: &Self::Data)
fn update_recurse(&mut self, cx: &mut ConfigCx<'_>, data: &Self::Data)
Source§impl<A> Layout for Stack<A>
impl<A> Layout for Stack<A>
Source§impl<A> Tile for Stack<A>
impl<A> Tile for Stack<A>
Source§fn child_indices(&self) -> ChildIndices
fn child_indices(&self) -> ChildIndices
Source§fn get_child(&self, index: usize) -> Option<&dyn Tile>
fn get_child(&self, index: usize) -> Option<&dyn Tile>
dyn Tile
, if available Read moreSource§fn find_child_index(&self, id: &Id) -> Option<usize>
fn find_child_index(&self, id: &Id) -> Option<usize>
id
, if any Read moreAuto Trait Implementations§
impl<A> Freeze for Stack<A>
impl<A> !RefUnwindSafe for Stack<A>
impl<A> !Send for Stack<A>
impl<A> !Sync for Stack<A>
impl<A> Unpin for Stack<A>
impl<A> !UnwindSafe for Stack<A>
Blanket Implementations§
Source§impl<W> AdaptWidget for Wwhere
W: Widget,
impl<W> AdaptWidget for Wwhere
W: Widget,
Source§fn pack(self, hints: AlignHints) -> Pack<Self>
fn pack(self, hints: AlignHints) -> Pack<Self>
Source§fn margins(self, dirs: Directions, style: MarginStyle) -> Margins<Self>
fn margins(self, dirs: Directions, style: MarginStyle) -> Margins<Self>
Source§fn on_configure<F>(self, f: F) -> AdaptEvents<Self>where
F: Fn(&mut AdaptConfigCx<'_, '_>, &mut Self) + 'static,
fn on_configure<F>(self, f: F) -> AdaptEvents<Self>where
F: Fn(&mut AdaptConfigCx<'_, '_>, &mut Self) + 'static,
Events::configure
Read moreSource§fn on_update<F>(self, f: F) -> AdaptEvents<Self>
fn on_update<F>(self, f: F) -> AdaptEvents<Self>
Events::update
Read moreSource§fn on_message<M, H>(self, handler: H) -> AdaptEvents<Self>
fn on_message<M, H>(self, handler: H) -> AdaptEvents<Self>
M
Read moreSource§fn map_message<M, N, H>(self, handler: H) -> AdaptEvents<Self>
fn map_message<M, N, H>(self, handler: H) -> AdaptEvents<Self>
Source§fn on_messages<H>(self, handler: H) -> AdaptEvents<Self>
fn on_messages<H>(self, handler: H) -> AdaptEvents<Self>
Source§fn with_min_size_px(self, w: i32, h: i32) -> Reserve<Self>
fn with_min_size_px(self, w: i32, h: i32) -> Reserve<Self>
Source§fn with_min_size_em(self, w: f32, h: f32) -> Reserve<Self>
fn with_min_size_em(self, w: f32, h: f32) -> Reserve<Self>
Source§fn with_label<D, T>(self, direction: D, label: T) -> WithLabel<Self, D>
fn with_label<D, T>(self, direction: D, label: T) -> WithLabel<Self, D>
Source§impl<W> AdaptWidgetAny for W
impl<W> AdaptWidgetAny for W
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<S, T> CastApprox<T> for Swhere
T: ConvApprox<S>,
impl<S, T> CastApprox<T> for Swhere
T: ConvApprox<S>,
Source§fn try_cast_approx(self) -> Result<T, Error>
fn try_cast_approx(self) -> Result<T, Error>
Source§fn cast_approx(self) -> T
fn cast_approx(self) -> T
Source§impl<S, T> CastFloat<T> for Swhere
T: ConvFloat<S>,
impl<S, T> CastFloat<T> for Swhere
T: ConvFloat<S>,
Source§fn cast_trunc(self) -> T
fn cast_trunc(self) -> T
Source§fn cast_nearest(self) -> T
fn cast_nearest(self) -> T
Source§fn cast_floor(self) -> T
fn cast_floor(self) -> T
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§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
.Source§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
.Source§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.Source§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.Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<W> TileExt for W
impl<W> TileExt for W
Source§fn is_strict_ancestor_of(&self, id: &Id) -> bool
fn is_strict_ancestor_of(&self, id: &Id) -> bool
id
is not self and is a descendant Read more