[−][src]Trait kas::WidgetChildren
Listing of a widget's children
This trait is part of the Widget
family and is derived by
derive(Widget)
unless #[widget(children = noauto)]
is used.
Dynamic widgets must implement this trait manually, since derive(Widget)
cannot currently handle fields like Vec<SomeWidget>
.
Whenever the number of child widgets changes or child widgets are replaced,
one must send TkAction::Reconfigure
.
(TODO: this is slow. Find an option for partial reconfigures. This requires
better widget identifiers; see #91.)
Required methods
fn len(&self) -> usize
Get the number of child widgets
fn get(&self, index: usize) -> Option<&dyn WidgetConfig>
Get a reference to a child widget by index, or None
if the index is
out of bounds.
For convenience, Index<usize>
is implemented via this method.
Required: index < self.len()
.
fn get_mut(&mut self, index: usize) -> Option<&mut dyn WidgetConfig>
Mutable variant of get
Warning: directly adjusting a widget without requiring reconfigure or
redraw may break the UI. If a widget is replaced, a reconfigure must
be requested. This can be done via Manager::send_action
.
This method may be removed in the future.
Provided methods
fn is_ancestor_of(&self, id: WidgetId) -> bool
Check whether id
is a descendant
This function assumes that id
is a valid widget.
fn find(&self, id: WidgetId) -> Option<&dyn WidgetConfig>
Find a child widget by identifier
This requires that the widget tree has already been configured by
event::ManagerState::configure
.
If the widget is disabled, this returns None
without recursing children.
fn find_mut(&mut self, id: WidgetId) -> Option<&mut dyn WidgetConfig>
Find a child widget by identifier
This requires that the widget tree has already been configured by
ManagerState::configure
.
fn walk(&self, f: &mut dyn FnMut(&dyn WidgetConfig))
Walk through all widgets, calling f
once on each.
This walk is iterative (nonconcurrent), depth-first, and always calls
f
on self after walking through all children.
fn walk_mut(&mut self, f: &mut dyn FnMut(&mut dyn WidgetConfig))
Walk through all widgets, calling f
once on each.
This walk is iterative (nonconcurrent), depth-first, and always calls
f
on self after walking through all children.