Struct kas_widgets::List
source · pub struct List<W: Widget, D: Directional> { /* private fields */ }
Expand description
A generic row/column widget
This type is roughly Vec
but for widgets. Generics:
W:
Widget
— type of widgetD:
Directional
— fixed or run-time direction of layout
Alternatives
Some more specific type-defs are available:
Row
andColumn
fix the directionD
BoxList
fixes the widget type toBox<dyn Widget<Data = Data>>
BoxRow
andBoxColumn
fix both type parameters
Performance
Configuring and resizing elements is O(n) in the number of children. Drawing and event handling is O(log n) in the number of children (assuming only a small number are visible at any one time).
Messages
If a handler is specified via Self::on_messages
then this handler is
called when a child pushes a message. This allows associating the
child’s index with a message.
Implementations§
source§impl<W: Widget, D> List<W, D>where
D: Default + Directional,
impl<W: Widget, D> List<W, D>where
D: Default + Directional,
sourcepub fn new(widgets: impl Into<Vec<W>>) -> Self
pub fn new(widgets: impl Into<Vec<W>>) -> Self
Construct a new instance
This constructor is available where the direction is determined by the
type: for D: Directional + Default
. In other cases, use
Self::new_dir
.
source§impl<W: Widget> List<W, Direction>
impl<W: Widget> List<W, Direction>
sourcepub fn set_direction(&mut self, direction: Direction) -> Action
pub fn set_direction(&mut self, direction: Direction) -> Action
Set the direction of contents
source§impl<W: Widget, D: Directional> List<W, D>
impl<W: Widget, D: Directional> List<W, D>
sourcepub fn new_dir(widgets: impl Into<Vec<W>>, direction: D) -> Self
pub fn new_dir(widgets: impl Into<Vec<W>>, direction: D) -> Self
Construct a new instance with explicit direction
sourcepub fn map_message<M, N, H>(self, handler: H) -> Self
pub fn map_message<M, N, H>(self, handler: H) -> Self
Add a child handler to map messages of type M
to N
Example
use kas::messages::Select;
use kas_widgets::{Row, Tab};
#[derive(Clone, Debug)]
struct MsgSelectIndex(usize);
let tabs: Row<Tab> = Row::new([]).map_message(|index, Select| MsgSelectIndex(index));
sourcepub fn on_message<M, H>(self, handler: H) -> Self
pub fn on_message<M, H>(self, handler: H) -> Self
Add a child handler for messages of type M
Where multiple message types must be handled or access to the
AdaptEventCx
is required, use Self::on_messages
instead.
sourcepub fn on_messages<H>(self, handler: H) -> Self
pub fn on_messages<H>(self, handler: H) -> Self
Add a child message handler (inline style)
This handler is called when a child pushes a message:
f(cx, index)
, where index
is the child’s index.
sourcepub fn edit<F: FnOnce(&mut Vec<W>)>(&mut self, f: F) -> Action
pub fn edit<F: FnOnce(&mut Vec<W>)>(&mut self, f: F) -> Action
Edit the list of children directly
This may be used to edit children before window construction. It may
also be used from a running UI, but in this case a full reconfigure
of the window’s widgets is required (triggered by the the return
value, Action::RECONFIGURE
).
sourcepub fn layout_storage(&mut self) -> &mut impl RowStorage
pub fn layout_storage(&mut self) -> &mut impl RowStorage
Access layout storage
The number of columns/rows is [Self.len
].
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 child, 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 child widget
The new child is configured immediately. Action::RESIZE
is
triggered.
Returns the new element’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
Triggers Action::RESIZE
.
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 new child is configured immediately. Triggers Action::RESIZE
.
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.
Triggers Action::RESIZE
.
sourcepub fn replace(
&mut self,
cx: &mut ConfigCx<'_>,
data: &W::Data,
index: usize,
w: W
) -> W
pub fn replace( &mut self, cx: &mut ConfigCx<'_>, data: &W::Data, index: usize, w: W ) -> W
Replace the child at index
Panics if index
is out of bounds.
The new child is configured immediately. Triggers Action::RESIZE
.
sourcepub fn extend<T>(&mut self, cx: &mut ConfigCx<'_>, data: &W::Data, iter: T)where
T: IntoIterator<Item = W>,
pub fn extend<T>(&mut self, cx: &mut ConfigCx<'_>, data: &W::Data, iter: T)where
T: IntoIterator<Item = W>,
Append child widgets from an iterator
New children are configured immediately. Triggers Action::RESIZE
.
sourcepub fn resize_with<F>(
&mut self,
cx: &mut ConfigCx<'_>,
data: &W::Data,
len: usize,
f: F
)
pub fn resize_with<F>( &mut self, cx: &mut ConfigCx<'_>, data: &W::Data, len: usize, f: F )
Resize, using the given closure to construct new widgets
New children are configured immediately. Triggers Action::RESIZE
.
Trait Implementations§
source§impl<W: Widget, D: Directional> AutoLayout for List<W, D>
impl<W: Widget, D: Directional> AutoLayout for List<W, D>
source§impl<W: Widget, D: Directional> Events for List<W, D>
impl<W: Widget, D: Directional> Events for List<W, D>
source§fn make_child_id(&mut self, index: usize) -> Id
fn make_child_id(&mut self, index: usize) -> Id
Make a fresh id based on self.next
then insert into self.id_map
source§fn handle_messages(&mut self, cx: &mut EventCx<'_>, data: &Self::Data)
fn handle_messages(&mut self, cx: &mut EventCx<'_>, 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 configure_recurse(&mut self, cx: &mut ConfigCx<'_>, data: &Self::Data)
fn configure_recurse(&mut self, cx: &mut ConfigCx<'_>, data: &Self::Data)
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<W: Widget, D: Directional + Default> FromIterator<W> for List<W, D>
impl<W: Widget, D: Directional + Default> FromIterator<W> for List<W, D>
source§fn from_iter<T>(iter: T) -> Selfwhere
T: IntoIterator<Item = W>,
fn from_iter<T>(iter: T) -> Selfwhere
T: IntoIterator<Item = W>,
source§impl<W: Widget, D: Directional> Layout for List<W, D>
impl<W: Widget, D: Directional> Layout for List<W, D>
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 widget_name(&self) -> &'static str
fn widget_name(&self) -> &'static str
source§fn size_rules(&mut self, sizer: SizeCx<'_>, axis: AxisInfo) -> SizeRules
fn size_rules(&mut self, sizer: SizeCx<'_>, axis: AxisInfo) -> SizeRules
source§fn translation(&self) -> Offset
fn translation(&self) -> Offset
Auto Trait Implementations§
impl<W, D> !RefUnwindSafe for List<W, D>
impl<W, D> !Send for List<W, D>
impl<W, D> !Sync for List<W, D>
impl<W, D> Unpin for List<W, D>
impl<W, D> !UnwindSafe for List<W, D>
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