pub struct List<C, D>where
C: Collection,
D: Directional,{ /* private fields */ }
Expand description
A generic row/column widget
A linear widget over a Collection
of widgets.
When the collection uses Vec
, various methods to insert/remove
elements are available.
The layout direction D
may be compile-time fixed (e.g. Right
) or
run-time mutable (Direction
); in the latter case
set_direction
is available.
§See also
Row
and Column
are type-defs to List
which fix the direction D
.
The macros row!
and column!
also create row/column
layouts, but are not fully equivalent:
row!
andcolumn!
generate anonymous layout widgets (or objects). These do not have aset_direction
method or support adding or removing elements.row!
andcolumn!
generate layout objects which, when used within a custom widget, may refer to that widget’s fields.
§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).
§Example
use kas::collection;
let list = List::right(collection![
"A checkbox",
CheckBox::new(|_, state: &bool| *state),
]);
Implementations§
Source§impl<C, D> List<C, D>
impl<C, D> List<C, D>
Sourcepub fn new(widgets: C) -> List<C, D>
pub fn new(widgets: C) -> List<C, D>
Construct a new instance with default-constructed direction
This constructor is available where the direction is determined by the
type: for D: Directional + Default
. In other cases, use
Self::new_dir
.
§Examples
Where widgets have the same type and the length is fixed, an array may be used:
use kas_widgets::{Label, Row};
let _ = Row::new([Label::new("left"), Label::new("right")]);
To support run-time insertion/deletion, use Vec
:
use kas_widgets::{AdaptWidget, Button, Row};
#[derive(Clone, Debug)]
enum Msg {
Add,
Remove,
}
let _ = Row::new(vec![Button::label_msg("Add", Msg::Add)])
.on_messages(|cx, row, data| {
if let Some(msg) = cx.try_pop() {
match msg {
Msg::Add => {
let button = if row.len() % 2 == 0 {
Button::label_msg("Add", Msg::Add)
} else {
Button::label_msg("Remove", Msg::Remove)
};
row.push(&mut cx.config_cx(), data, button);
}
Msg::Remove => {
let _ = row.pop(&mut cx.config_cx());
}
}
}
});
Source§impl<C> List<C, Left>where
C: Collection,
impl<C> List<C, Left>where
C: Collection,
Source§impl<C> List<C, Right>where
C: Collection,
impl<C> List<C, Right>where
C: Collection,
Source§impl<C> List<C, Up>where
C: Collection,
impl<C> List<C, Up>where
C: Collection,
Source§impl<C> List<C, Down>where
C: Collection,
impl<C> List<C, Down>where
C: Collection,
Source§impl<C> List<C, Direction>where
C: Collection,
impl<C> List<C, Direction>where
C: Collection,
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<C, D> List<C, D>where
C: Collection,
D: Directional,
impl<C, D> List<C, D>where
C: Collection,
D: Directional,
Sourcepub fn new_dir(widgets: C, direction: D) -> List<C, D>
pub fn new_dir(widgets: C, direction: D) -> List<C, D>
Construct a new instance with explicit direction
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
].
Source§impl<W, D> List<Vec<W>, D>where
W: Widget,
D: Directional,
impl<W, D> List<Vec<W>, D>where
W: Widget,
D: Directional,
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 edit<F>(&mut self, f: F) -> Action
pub fn edit<F>(&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 push(
&mut self,
cx: &mut ConfigCx<'_>,
data: &<W as Widget>::Data,
widget: W,
) -> usize
pub fn push( &mut self, cx: &mut ConfigCx<'_>, data: &<W as Widget>::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 as Widget>::Data,
index: usize,
widget: W,
)
pub fn insert( &mut self, cx: &mut ConfigCx<'_>, data: &<W as Widget>::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 as Widget>::Data,
index: usize,
w: W,
) -> W
pub fn replace( &mut self, cx: &mut ConfigCx<'_>, data: &<W as Widget>::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 as Widget>::Data,
iter: T,
)where
T: IntoIterator<Item = W>,
pub fn extend<T>(
&mut self,
cx: &mut ConfigCx<'_>,
data: &<W as Widget>::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 as Widget>::Data,
len: usize,
f: F,
)
pub fn resize_with<F>( &mut self, cx: &mut ConfigCx<'_>, data: &<W as Widget>::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<C, D> Events for List<C, D>where
C: Collection,
D: Directional,
impl<C, D> Events for List<C, D>where
C: Collection,
D: Directional,
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_event(
&mut self,
_: &mut EventCx<'_>,
_: &<List<C, D> as Widget>::Data,
_: Event,
) -> IsUsed
fn handle_event( &mut self, _: &mut EventCx<'_>, _: &<List<C, D> as Widget>::Data, _: 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<C, D> Layout for List<C, D>where
C: Collection,
D: Directional,
impl<C, D> Layout for List<C, D>where
C: Collection,
D: Directional,
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 set_rect(&mut self, cx: &mut ConfigCx<'_>, rect: Rect, hints: AlignHints)
fn set_rect(&mut self, cx: &mut ConfigCx<'_>, rect: Rect, hints: AlignHints)
Source§fn widget_name(&self) -> &'static str
fn widget_name(&self) -> &'static str
Source§fn translation(&self) -> Offset
fn translation(&self) -> Offset
Source§impl<C, D> Widget for List<C, D>where
C: Collection,
D: Directional,
impl<C, D> Widget for List<C, D>where
C: Collection,
D: Directional,
Source§fn for_child_node(
&mut self,
data: &<C as Collection>::Data,
index: usize,
closure: Box<dyn FnOnce(Node<'_>) + '_>,
)
fn for_child_node( &mut self, data: &<C as Collection>::Data, index: usize, closure: Box<dyn FnOnce(Node<'_>) + '_>, )
Auto Trait Implementations§
impl<C, D> Freeze for List<C, D>
impl<C, D> RefUnwindSafe for List<C, D>where
C: RefUnwindSafe,
D: RefUnwindSafe,
impl<C, D> !Send for List<C, D>
impl<C, D> !Sync for List<C, D>
impl<C, D> Unpin for List<C, D>
impl<C, D> UnwindSafe for List<C, D>where
C: UnwindSafe,
D: UnwindSafe,
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<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 moreSource§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 moreSource§fn for_children(&self, f: impl FnMut(&dyn Layout))
fn for_children(&self, f: impl FnMut(&dyn Layout))
Source§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<R, P> ReadPrimitive<R> for P
impl<R, P> ReadPrimitive<R> for P
Source§fn read_from_little_endian(read: &mut R) -> Result<Self, Error>
fn read_from_little_endian(read: &mut R) -> Result<Self, Error>
ReadEndian::read_from_little_endian()
.