Struct kas_widgets::Stack
source · pub struct Stack<W: Widget> { /* 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
.
This may only be parametrised with a single widget type, thus usually
it will be necessary to box children (this is what BoxStack
is).
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
.
Implementations§
source§impl<W: Widget> Stack<W>
impl<W: Widget> Stack<W>
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 sizing happens afterwards.
sourcepub fn set_active(
&mut self,
cx: &mut ConfigCx<'_>,
data: &W::Data,
index: usize
)
pub fn set_active( &mut self, cx: &mut ConfigCx<'_>, data: &W::Data, index: usize )
Set the active page
sourcepub fn get_active(&self) -> Option<&W>
pub fn get_active(&self) -> Option<&W>
Get a direct reference to the active child widget, if any
sourcepub fn get_mut(&mut self, index: usize) -> Option<&mut W>
pub fn get_mut(&mut self, index: usize) -> Option<&mut W>
Returns a mutable reference to the page, if any
sourcepub fn push(
&mut self,
cx: &mut ConfigCx<'_>,
data: &W::Data,
widget: W
) -> usize
pub fn push( &mut self, cx: &mut ConfigCx<'_>, data: &W::Data, widget: W ) -> 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<W>
pub fn pop(&mut self, cx: &mut EventState) -> Option<W>
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: &W::Data,
index: usize,
widget: W
)
pub fn insert( &mut self, cx: &mut ConfigCx<'_>, data: &W::Data, index: usize, widget: W )
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) -> W
pub fn remove(&mut self, cx: &mut EventState, index: usize) -> W
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: &W::Data,
index: usize,
widget: W
) -> W
pub fn replace( &mut self, cx: &mut ConfigCx<'_>, data: &W::Data, index: usize, widget: W ) -> W
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 = W>>(
&mut self,
cx: &mut ConfigCx<'_>,
data: &W::Data,
iter: T
)
pub fn extend<T: IntoIterator<Item = W>>( &mut self, cx: &mut ConfigCx<'_>, data: &W::Data, 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) -> W>(
&mut self,
cx: &mut ConfigCx<'_>,
data: &W::Data,
len: usize,
f: F
)
pub fn resize_with<F: Fn(usize) -> W>( &mut self, cx: &mut ConfigCx<'_>, data: &W::Data, 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<W: Widget> Events for Stack<W>
impl<W: Widget> Events for Stack<W>
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 update_recurse(&mut self, cx: &mut ConfigCx<'_>, data: &Self::Data)
fn update_recurse(&mut self, cx: &mut ConfigCx<'_>, data: &Self::Data)
source§fn steal_event(
&mut self,
_: &mut EventCx<'_>,
_: &Self::Data,
_: &Id,
_: &Event
) -> IsUsed
fn steal_event( &mut self, _: &mut EventCx<'_>, _: &Self::Data, _: &Id, _: &Event ) -> IsUsed
source§fn update(&mut self, cx: &mut ConfigCx<'_>, data: &Self::Data)
fn update(&mut self, cx: &mut ConfigCx<'_>, data: &Self::Data)
source§fn handle_hover(&mut self, cx: &mut EventCx<'_>, state: bool) -> IsUsed
fn handle_hover(&mut self, cx: &mut EventCx<'_>, state: bool) -> IsUsed
source§impl<W: Widget> Layout for Stack<W>
impl<W: Widget> Layout for Stack<W>
source§fn num_children(&self) -> usize
fn num_children(&self) -> usize
source§fn get_child(&self, index: usize) -> Option<&dyn Layout>
fn get_child(&self, index: usize) -> Option<&dyn Layout>
dyn Layout
Read moresource§fn find_child_index(&self, id: &Id) -> Option<usize>
fn find_child_index(&self, id: &Id) -> Option<usize>
id
, if any Read moresource§fn size_rules(&mut self, sizer: SizeCx<'_>, axis: AxisInfo) -> SizeRules
fn size_rules(&mut self, sizer: SizeCx<'_>, axis: AxisInfo) -> SizeRules
source§fn widget_name(&self) -> &'static str
fn widget_name(&self) -> &'static str
source§fn translation(&self) -> Offset
fn translation(&self) -> Offset
Auto Trait Implementations§
impl<W> RefUnwindSafe for Stack<W>where
W: RefUnwindSafe,
impl<W> !Send for Stack<W>
impl<W> !Sync for Stack<W>
impl<W> Unpin for Stack<W>where
W: Unpin,
impl<W> UnwindSafe for Stack<W>where
W: UnwindSafe,
Blanket Implementations§
source§impl<W> AdaptWidget for Wwhere
W: Widget,
impl<W> AdaptWidget for Wwhere
W: Widget,
source§fn on_configure<F>(self, f: F) -> AdaptEvents<Self>
fn on_configure<F>(self, f: F) -> AdaptEvents<Self>
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 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
§impl<S, T> Cast<T> for Swhere
T: Conv<S>,
impl<S, T> Cast<T> for Swhere
T: Conv<S>,
§impl<S, T> CastApprox<T> for Swhere
T: ConvApprox<S>,
impl<S, T> CastApprox<T> for Swhere
T: ConvApprox<S>,
§fn try_cast_approx(self) -> Result<T, Error>
fn try_cast_approx(self) -> Result<T, Error>
§fn cast_approx(self) -> T
fn cast_approx(self) -> T
§impl<S, T> CastFloat<T> for Swhere
T: ConvFloat<S>,
impl<S, T> CastFloat<T> for Swhere
T: ConvFloat<S>,
§fn cast_trunc(self) -> T
fn cast_trunc(self) -> T
§fn cast_nearest(self) -> T
fn cast_nearest(self) -> T
§fn cast_floor(self) -> T
fn cast_floor(self) -> T
§fn try_cast_trunc(self) -> Result<T, Error>
fn try_cast_trunc(self) -> Result<T, Error>
§fn try_cast_nearest(self) -> Result<T, Error>
fn try_cast_nearest(self) -> Result<T, Error>
§fn try_cast_floor(self) -> Result<T, Error>
fn try_cast_floor(self) -> Result<T, Error>
§fn try_cast_ceil(self) -> Result<T, Error>
fn try_cast_ceil(self) -> Result<T, Error>
§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<W> LayoutExt for W
impl<W> LayoutExt for W
source§fn identify(&self) -> IdentifyWidget<'_>
fn identify(&self) -> IdentifyWidget<'_>
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