Trait kas::WidgetChildren [−][src]
pub trait WidgetChildren: WidgetCore {
fn first_id(&self) -> WidgetId;
fn num_children(&self) -> usize;
fn get_child(&self, index: usize) -> Option<&(dyn WidgetConfig + 'static)>;
fn get_child_mut(
&mut self,
index: usize
) -> Option<&mut (dyn WidgetConfig + 'static)>;
fn record_first_id(&mut self, _id: WidgetId) { ... }
fn is_ancestor_of(&self, id: WidgetId) -> bool { ... }
fn find_child(&self, id: WidgetId) -> Option<usize> { ... }
fn find_leaf(&self, id: WidgetId) -> Option<&(dyn WidgetConfig + 'static)> { ... }
fn find_leaf_mut(
&mut self,
id: WidgetId
) -> Option<&mut (dyn WidgetConfig + 'static)> { ... }
fn walk_children<F>(&self, f: F)
where
F: FnMut(&(dyn WidgetConfig + 'static)),
{ ... }
fn walk_children_mut<F>(&mut self, f: F)
where
F: FnMut(&mut (dyn WidgetConfig + 'static)),
{ ... }
}
Expand description
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
Get the first identifier of self or any children
Widget identifiers are assigned sequentially by depth-first-search,
children before parents. Any widget thus has a range of identifiers,
from the first assigned to any descendent (or self) to its own
(WidgetCore::id
). This method must return the first identifier.
fn num_children(&self) -> usize
fn num_children(&self) -> usize
Get the number of child widgets
fn get_child(&self, index: usize) -> Option<&(dyn WidgetConfig + 'static)>
fn get_child(&self, index: usize) -> Option<&(dyn WidgetConfig + 'static)>
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_child_mut(
&mut self,
index: usize
) -> Option<&mut (dyn WidgetConfig + 'static)>
fn get_child_mut(
&mut self,
index: usize
) -> Option<&mut (dyn WidgetConfig + 'static)>
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 record_first_id(&mut self, _id: WidgetId)
fn record_first_id(&mut self, _id: WidgetId)
Record first identifier
This is called during WidgetConfig::configure_recurse
with the first
identifier. This may be used to implement WidgetChildren::first_id
,
although in many cases the first identifier can be read directly from
the first child. This method has a default implementation doing nothing.
This method should only be called from configure_recurse
.
fn is_ancestor_of(&self, id: WidgetId) -> bool
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_child(&self, id: WidgetId) -> Option<usize>
fn find_child(&self, id: WidgetId) -> Option<usize>
Find the child which is an ancestor of this id
, if any
This child may then be accessed via Self::get_child
or
Self::get_child_mut
.
This requires that the widget tree has already been configured by
event::ManagerState::configure
.
fn find_leaf(&self, id: WidgetId) -> Option<&(dyn WidgetConfig + 'static)>
fn find_leaf(&self, id: WidgetId) -> Option<&(dyn WidgetConfig + 'static)>
Find the leaf (lowest descendant) with this id
, if any
This requires that the widget tree has already been configured by
event::ManagerState::configure
.
fn find_leaf_mut(
&mut self,
id: WidgetId
) -> Option<&mut (dyn WidgetConfig + 'static)>
fn find_leaf_mut(
&mut self,
id: WidgetId
) -> Option<&mut (dyn WidgetConfig + 'static)>
Find the leaf (lowest descendant) with this id
, if any
This requires that the widget tree has already been configured by
ManagerState::configure
.
fn walk_children<F>(&self, f: F) where
F: FnMut(&(dyn WidgetConfig + 'static)),
fn walk_children<F>(&self, f: F) where
F: FnMut(&(dyn WidgetConfig + 'static)),
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_children_mut<F>(&mut self, f: F) where
F: FnMut(&mut (dyn WidgetConfig + 'static)),
fn walk_children_mut<F>(&mut self, f: F) where
F: FnMut(&mut (dyn WidgetConfig + 'static)),
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.