pub struct List<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: Collection, D> List<C, D>where
D: Default + Directional,
impl<C: Collection, D> List<C, D>where
D: Default + Directional,
Sourcepub fn new(widgets: C) -> Self
pub fn new(widgets: C) -> Self
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: Collection> List<C, Left>
impl<C: Collection> List<C, Left>
Source§impl<C: Collection> List<C, Right>
impl<C: Collection> List<C, Right>
Source§impl<C: Collection> List<C, Up>
impl<C: Collection> List<C, Up>
Source§impl<C: Collection> List<C, Down>
impl<C: Collection> List<C, Down>
Source§impl<C: Collection, D: Directional + Eq> List<C, D>
impl<C: Collection, D: Directional + Eq> List<C, D>
Sourcepub fn set_direction(&mut self, cx: &mut EventState, direction: D)
pub fn set_direction(&mut self, cx: &mut EventState, direction: D)
Set the direction of contents
Source§impl<C: Collection, D: Directional> List<C, D>
impl<C: Collection, D: Directional> List<C, D>
Sourcepub fn new_dir(widgets: C, direction: D) -> Self
pub fn new_dir(widgets: C, direction: D) -> Self
Construct a new instance with explicit direction
Sourcepub fn with_direction(self, direction: D) -> Self
pub fn with_direction(self, direction: D) -> Self
Set the direction of contents (inline)
Sourcepub fn layout_storage(&mut self) -> &mut (impl RowStorage + use<C, D>)
pub fn layout_storage(&mut self) -> &mut (impl RowStorage + use<C, D>)
Access layout storage
The number of columns/rows is Self::len
.
Source§impl<W: Widget, D: Directional> List<Vec<W>, D>
impl<W: Widget, D: Directional> List<Vec<W>, D>
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<C: Collection, D: Directional> Events for List<C, D>
impl<C: Collection, D: Directional> Events for List<C, 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§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 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§fn handle_mouse_over(&mut self, cx: &mut EventCx<'_>, state: bool)
fn handle_mouse_over(&mut self, cx: &mut EventCx<'_>, state: bool)
Source§impl<C: Collection, D: Directional> Layout for List<C, D>
impl<C: Collection, D: Directional> Layout for List<C, D>
Source§impl<C: Collection, D: Directional> Tile for List<C, D>
impl<C: Collection, D: Directional> Tile for List<C, D>
Source§fn find_child_index(&self, id: &Id) -> Option<usize>
fn find_child_index(&self, id: &Id) -> Option<usize>
id
, if any Read moreSource§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 child_indices(&self) -> ChildIndices
fn child_indices(&self) -> ChildIndices
Source§impl<C: Collection, D: Directional> Widget for List<C, D>
impl<C: Collection, D: Directional> Widget for List<C, D>
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<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