pub struct List<D, W>where
D: Directional,
W: Widget,{ /* private fields */ }
Expand description
A generic row/column widget
This type is roughly Vec
but for widgets. Generics:
D:
Directional
— fixed or run-time direction of layoutW:
Widget
— type of widget
Alternatives
Some more specific type-defs are available:
Row
andColumn
fix the directionD
BoxList
fixes the widget type toBox<dyn Widget>
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_message
then this handler is
called when a child pushes a message. This allows associating the
child’s index with a message.
Implementations§
source§impl<D, W> List<D, W>where
D: Directional + Default,
W: Widget,
impl<D, W> List<D, W>where D: Directional + Default, W: Widget,
sourcepub fn new() -> List<D, W>
pub fn new() -> List<D, W>
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> List<Direction, W>where
W: Widget,
impl<W> List<Direction, W>where W: Widget,
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<D, W> List<D, W>where
D: Directional,
W: Widget,
impl<D, W> List<D, W>where D: Directional, W: Widget,
sourcepub fn new_dir_vec(direction: D, widgets: Vec<W, Global>) -> List<D, W>
pub fn new_dir_vec(direction: D, widgets: Vec<W, Global>) -> List<D, W>
Construct a new instance with explicit direction and vec
sourcepub fn set_on_message(&mut self, f: Option<fn(_: &mut EventMgr<'_>, _: usize)>)
pub fn set_on_message(&mut self, f: Option<fn(_: &mut EventMgr<'_>, _: usize)>)
Assign a child message handler
This handler (if any) is called when a child pushes a message:
f(mgr, index)
, where index
is the child’s index.
sourcepub fn on_message(self, f: fn(_: &mut EventMgr<'_>, _: usize)) -> List<D, W>
pub fn on_message(self, f: fn(_: &mut EventMgr<'_>, _: usize)) -> List<D, W>
Assign a child message handler (inline style)
This handler is called when a child pushes a message:
f(mgr, index)
, where index
is the child’s index.
sourcepub fn edit<F>(&mut self, f: F) -> Actionwhere
F: FnOnce(&mut Vec<W, Global>),
pub fn edit<F>(&mut self, f: F) -> Actionwhere F: FnOnce(&mut Vec<W, Global>),
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, mgr: &mut ConfigMgr<'_>, widget: W) -> usize
pub fn push(&mut self, mgr: &mut ConfigMgr<'_>, 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, mgr: &mut ConfigMgr<'_>) -> Option<W>
pub fn pop(&mut self, mgr: &mut ConfigMgr<'_>) -> Option<W>
Remove the last child widget (if any) and return
Triggers Action::RESIZE
.
sourcepub fn insert(&mut self, mgr: &mut ConfigMgr<'_>, index: usize, widget: W)
pub fn insert(&mut self, mgr: &mut ConfigMgr<'_>, 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, mgr: &mut ConfigMgr<'_>, index: usize) -> W
pub fn remove(&mut self, mgr: &mut ConfigMgr<'_>, 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, mgr: &mut ConfigMgr<'_>, index: usize, w: W) -> W
pub fn replace(&mut self, mgr: &mut ConfigMgr<'_>, 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, mgr: &mut ConfigMgr<'_>, iter: T)where
T: IntoIterator<Item = W>,
pub fn extend<T>(&mut self, mgr: &mut ConfigMgr<'_>, 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, mgr: &mut ConfigMgr<'_>, len: usize, f: F)where
F: Fn(usize) -> W,
pub fn resize_with<F>(&mut self, mgr: &mut ConfigMgr<'_>, len: usize, f: F)where F: Fn(usize) -> W,
Resize, using the given closure to construct new widgets
New children are configured immediately. Triggers Action::RESIZE
.
Trait Implementations§
source§impl<D, W> AutoLayout for List<D, W>where
D: Directional,
W: Widget,
impl<D, W> AutoLayout for List<D, W>where D: Directional, W: Widget,
source§impl<D, W> FromIterator<W> for List<D, W>where
D: Directional + Default,
W: Widget,
impl<D, W> FromIterator<W> for List<D, W>where D: Directional + Default, W: Widget,
source§impl<D, W> Layout for List<D, W>where
D: Directional,
W: Widget,
impl<D, W> Layout for List<D, W>where D: Directional, W: Widget,
source§impl<D, W> Widget for List<D, W>where
D: Directional,
W: Widget,
impl<D, W> Widget for List<D, W>where D: Directional, W: Widget,
source§fn handle_message(&mut self, mgr: &mut EventMgr<'_>)
fn handle_message(&mut self, mgr: &mut EventMgr<'_>)
source§fn translation(&self) -> Offset
fn translation(&self) -> Offset
source§fn steal_event(
&mut self,
mgr: &mut EventMgr<'_>,
id: &WidgetId,
event: &Event
) -> Response
fn steal_event( &mut self, mgr: &mut EventMgr<'_>, id: &WidgetId, event: &Event ) -> Response
source§impl<D, W> WidgetChildren for List<D, W>where
D: Directional,
W: Widget,
impl<D, W> WidgetChildren for List<D, W>where D: Directional, W: Widget,
source§fn num_children(&self) -> usize
fn num_children(&self) -> usize
source§fn get_child(&self, index: usize) -> Option<&dyn Widget>
fn get_child(&self, index: usize) -> Option<&dyn Widget>
None
if the index is
out of bounds. Read moresource§fn get_child_mut(&mut self, index: usize) -> Option<&mut dyn Widget>
fn get_child_mut(&mut self, index: usize) -> Option<&mut dyn Widget>
source§impl<D, W> WidgetCore for List<D, W>where
D: Directional,
W: Widget,
impl<D, W> WidgetCore for List<D, W>where D: Directional, W: Widget,
source§fn widget_name(&self) -> &'static str
fn widget_name(&self) -> &'static str
source§fn as_widget_mut(&mut self) -> &mut dyn Widget
fn as_widget_mut(&mut self) -> &mut dyn Widget
Auto Trait Implementations§
impl<D, W> RefUnwindSafe for List<D, W>where D: RefUnwindSafe, W: RefUnwindSafe,
impl<D, W> !Send for List<D, W>
impl<D, W> !Sync for List<D, W>
impl<D, W> Unpin for List<D, W>where D: Unpin, W: Unpin,
impl<D, W> UnwindSafe for List<D, W>where D: UnwindSafe, W: UnwindSafe,
Blanket Implementations§
source§impl<W> AdaptWidget for Wwhere
W: Widget + ?Sized,
impl<W> AdaptWidget for Wwhere W: Widget + ?Sized,
source§fn map_msg<M, N, F>(self, f: F) -> MapMessage<Self, M, N, F>where
M: Debug,
N: Debug,
Self: Sized,
F: FnMut(M) -> N,
fn map_msg<M, N, F>(self, f: F) -> MapMessage<Self, M, N, F>where M: Debug, N: Debug, Self: Sized, F: FnMut(M) -> N,
source§fn with_reserve<R>(self, r: R) -> Reserve<Self, R>where
R: FnMut(SizeMgr<'_>, AxisInfo) -> SizeRules,
Self: Sized,
fn with_reserve<R>(self, r: R) -> Reserve<Self, R>where R: FnMut(SizeMgr<'_>, AxisInfo) -> SizeRules, Self: Sized,
source§fn with_min_size_px(self, w: i32, h: i32) -> Reserve<Self, WithMinSizePx>where
Self: Sized,
fn with_min_size_px(self, w: i32, h: i32) -> Reserve<Self, WithMinSizePx>where Self: Sized,
source§fn with_min_size_em(self, w: f32, h: f32) -> Reserve<Self, WithMinSizeEm>where
Self: Sized,
fn with_min_size_em(self, w: f32, h: f32) -> Reserve<Self, WithMinSizeEm>where Self: Sized,
source§fn with_label<D, T>(self, direction: D, label: T) -> WithLabel<Self, D>where
D: Directional,
T: Into<AccelString>,
Self: Sized,
fn with_label<D, T>(self, direction: D, label: T) -> WithLabel<Self, D>where D: Directional, T: Into<AccelString>, Self: Sized,
§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>
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>
§impl<T> NoneValue for Twhere
T: Default,
impl<T> NoneValue for Twhere T: Default,
type NoneType = T
§fn null_value() -> T
fn null_value() -> T
§impl<T> Pointable for T
impl<T> Pointable for T
source§impl<R, P> ReadPrimitive<R> for Pwhere
R: Read + ReadEndian<P>,
P: Default,
impl<R, P> ReadPrimitive<R> for Pwhere R: Read + ReadEndian<P>, P: Default,
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()
.source§impl<W> WidgetExt for Wwhere
W: Widget + ?Sized,
impl<W> WidgetExt for Wwhere W: Widget + ?Sized,
source§fn eq_id<T>(&self, rhs: T) -> boolwhere
WidgetId: PartialEq<T>,
fn eq_id<T>(&self, rhs: T) -> boolwhere WidgetId: PartialEq<T>,
source§fn identify(&self) -> IdentifyWidget
fn identify(&self) -> IdentifyWidget
source§fn is_ancestor_of(&self, id: &WidgetId) -> bool
fn is_ancestor_of(&self, id: &WidgetId) -> bool
id
is self or a descendant Read moresource§fn is_strict_ancestor_of(&self, id: &WidgetId) -> bool
fn is_strict_ancestor_of(&self, id: &WidgetId) -> bool
id
is not self and is a descendant Read more