pub struct Flow<C: Collection, D: Directional> { /* private fields */ }Expand description
Rows or columns of content with line-splitting
This widget is a variant of List, arranging a linear Collection
of children into multiple rows or columns with automatic splitting.
Unlike Grid, items are not aligned across lines.
When the collection uses Vec, various methods to insert/remove
elements are available.
§Layout details
Currently only horizontal lines (rows) which wrap down to the next line are supported.
Width requirements depend on the desired numbers of columns; see
Self::set_num_columns.
Items within each line are stretched (if any has non-zero Stretch
priority) in accordance with SizeRules::solve_widths. It is not
currently possible to adjust this (except by tweaking the stretchiness
of items).
§Performance
Sizing, drawing and event handling are all O(n) where n is the number of children.
§Example
use kas::collection;
let list = Flow::right(collection![
"A checkbox",
CheckBox::new(|_, state: &bool| *state),
]);Implementations§
Source§impl<C: Collection, D> Flow<C, D>where
D: Default + Directional,
impl<C: Collection, D> Flow<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. The wrap direction is down or right.
§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(cx, data, button);
}
Msg::Remove => {
let _ = row.pop(cx);
}
}
}
});Source§impl<C: Collection> Flow<C, Left>
impl<C: Collection> Flow<C, Left>
Source§impl<C: Collection> Flow<C, Right>
impl<C: Collection> Flow<C, Right>
Source§impl<C: Collection, D: Directional> Flow<C, D>
impl<C: Collection, D: Directional> Flow<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 set_num_columns(&mut self, min: i32, ideal: i32)
pub fn set_num_columns(&mut self, min: i32, ideal: i32)
Set the (minimum, ideal) numbers of columns
This affects the final SizeRules for the horizontal axis.
By default, the values 1, 3 are used.
Sourcepub fn with_num_columns(self, min: i32, ideal: i32) -> Self
pub fn with_num_columns(self, min: i32, ideal: i32) -> Self
Set the (minimum, ideal) numbers of columns (inline)
This affects the final SizeRules for the horizontal axis.
By default, the values 1, 3 are used.
Source§impl<W: Widget, D: Directional> Flow<Vec<W>, D>
impl<W: Widget, D: Directional> Flow<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. Triggers a resize.
Returns the new element’s index.
Sourcepub fn pop(&mut self, cx: &mut ConfigCx<'_>) -> Option<W>
pub fn pop(&mut self, cx: &mut ConfigCx<'_>) -> Option<W>
Remove the last child widget (if any) and return
Triggers a 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 a resize.
Sourcepub fn remove(&mut self, cx: &mut ConfigCx<'_>, index: usize) -> W
pub fn remove(&mut self, cx: &mut ConfigCx<'_>, index: usize) -> W
Removes the child widget at position index
Panics if index is out of bounds.
Triggers a resize.
Sourcepub fn truncate(&mut self, cx: &mut ConfigCx<'_>, len: usize)
pub fn truncate(&mut self, cx: &mut ConfigCx<'_>, len: usize)
Removes all children at positions ≥ len
Does nothing if self.len() < len.
Triggers a resize.
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.
The new child is configured immediately. Triggers a 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 a 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 a resize.
Trait Implementations§
Source§impl<C: Collection, D: Directional> Layout for Flow<C, D>
impl<C: Collection, D: Directional> Layout for Flow<C, D>
Source§impl<C: Collection, D: Directional> Tile for Flow<C, D>
impl<C: Collection, D: Directional> Tile for Flow<C, D>
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 moreSource§fn translation(&self, index: usize) -> Offset
fn translation(&self, index: usize) -> Offset
index relative to this widget Read moreSource§fn role_child_properties(&self, cx: &mut dyn RoleCx, index: usize)
fn role_child_properties(&self, cx: &mut dyn RoleCx, index: usize)
index Read moreSource§impl<C: Collection, D: Directional> Widget for Flow<C, D>
impl<C: Collection, D: Directional> Widget for Flow<C, D>
Auto Trait Implementations§
impl<C, D> Freeze for Flow<C, D>
impl<C, D> RefUnwindSafe for Flow<C, D>where
C: RefUnwindSafe,
D: RefUnwindSafe,
impl<C, D> !Send for Flow<C, D>
impl<C, D> !Sync for Flow<C, D>
impl<C, D> Unpin for Flow<C, D>
impl<C, D> UnwindSafe for Flow<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 with_stretch(
self,
horiz: impl Into<Option<Stretch>>,
vert: impl Into<Option<Stretch>>,
) -> WithStretch<Self>
fn with_stretch( self, horiz: impl Into<Option<Stretch>>, vert: impl Into<Option<Stretch>>, ) -> WithStretch<Self>
Source§fn with_margin_style(self, style: MarginStyle) -> WithMarginStyle<Self>
fn with_margin_style(self, style: MarginStyle) -> WithMarginStyle<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_configured(&self) -> bool
fn is_configured(&self) -> bool
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