pub trait WidgetChildren: WidgetCore {
    fn num_children(&self) -> usize;
    fn get_child(&self, index: usize) -> Option<&dyn Widget>;
    fn get_child_mut(&mut self, index: usize) -> Option<&mut dyn Widget>;

    fn find_child_index(&self, id: &WidgetId) -> Option<usize> { ... }
    fn make_child_id(&mut self, index: usize) -> WidgetId { ... }
}
Expand description

Listing of a Widget’s children

This trait enumerates child widgets (that is, components of the widget which are themselves widgets).

Enumerated widgets are automatically configured, via recursion, when their parent is. See Widget::configure.

Implementing WidgetChildren

Implementations of this trait are usually generated via macro. See Widget trait documentation.

In a few cases, namely widgets which may add/remove children dynamically, this trait should be implemented directly.

Note that parents are responsible for ensuring that newly added children get configured, either by sending TkAction::RECONFIGURE by calling ConfigMgr::configure.

Required Methods

Get the number of child widgets

Every value in the range 0..self.num_children() is a valid child index.

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().

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 EventState::send_action. This method may be removed in the future.

Provided Methods

Find the child which is an ancestor of this id, if any

If Some(index) is returned, this is probably but not guaranteed to be a valid child index.

The default implementation simply uses WidgetId::next_key_after. Widgets may choose to assign children custom keys by overriding this method and Self::make_child_id.

Make an identifier for a child

Default impl: self.id_ref().make_child(index)

Implementations on Foreign Types

Implementors