use crate::widget::Widget;
pub(super) fn collect_focusable(
widget: &dyn Widget,
current_path: &mut Vec<usize>,
out: &mut Vec<Vec<usize>>,
) {
if widget.is_focusable() {
out.push(current_path.clone());
}
for (i, child) in widget.children().iter().enumerate() {
current_path.push(i);
collect_focusable(child.as_ref(), current_path, out);
current_path.pop();
}
}
pub(super) fn widget_at_path<'a>(
root: &'a mut Box<dyn Widget>,
path: &[usize],
) -> &'a mut dyn Widget {
if path.is_empty() {
return root.as_mut();
}
let idx = path[0];
widget_at_path(&mut root.children_mut()[idx], &path[1..])
}
pub(super) fn widget_at_path_ref<'a>(root: &'a dyn Widget, path: &[usize]) -> &'a dyn Widget {
if path.is_empty() {
return root;
}
let idx = path[0];
widget_at_path_ref(root.children()[idx].as_ref(), &path[1..])
}