mirror of
https://github.com/slint-ui/slint.git
synced 2025-10-02 06:41:14 +00:00
Replace two uses of build_array_helper with a new recurse_elem variant
For the item index generation and the member population for the C++ structs, a level-order variant of `recurse_elem` is sufficient - as also indicate by the unused item index parameters.
This commit is contained in:
parent
90abcf3066
commit
cebb415b08
3 changed files with 20 additions and 2 deletions
|
@ -1170,7 +1170,7 @@ fn generate_component(
|
||||||
|
|
||||||
let mut repeater_count = 0;
|
let mut repeater_count = 0;
|
||||||
|
|
||||||
super::build_array_helper(component, |item_rc, _, _| {
|
crate::object_tree::recurse_elem_level_order(&component.root_element, &mut |item_rc| {
|
||||||
let item = item_rc.borrow();
|
let item = item_rc.borrow();
|
||||||
if item.base_type == Type::Void {
|
if item.base_type == Type::Void {
|
||||||
assert!(component.is_global());
|
assert!(component.is_global());
|
||||||
|
|
|
@ -1419,6 +1419,24 @@ pub fn recurse_elem<State>(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Call the visitor for each children of the element recursively, starting with the element itself.
|
||||||
|
/// The traversal happens in level-order, meaning each level of the element tree is visisted before
|
||||||
|
/// going to the next depth.
|
||||||
|
///
|
||||||
|
/// The state returned by the visitor is passed to the children
|
||||||
|
pub fn recurse_elem_level_order(elem: &ElementRc, vis: &mut impl FnMut(&ElementRc)) {
|
||||||
|
vis(elem);
|
||||||
|
visit_children(elem, vis);
|
||||||
|
fn visit_children(elem: &ElementRc, vis: &mut impl FnMut(&ElementRc)) {
|
||||||
|
for child in &elem.borrow().children {
|
||||||
|
vis(child);
|
||||||
|
}
|
||||||
|
for child in &elem.borrow().children {
|
||||||
|
visit_children(child, vis);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// Same as [`recurse_elem`] but include the elements form sub_components
|
/// Same as [`recurse_elem`] but include the elements form sub_components
|
||||||
pub fn recurse_elem_including_sub_components<State>(
|
pub fn recurse_elem_including_sub_components<State>(
|
||||||
component: &Component,
|
component: &Component,
|
||||||
|
|
|
@ -10,7 +10,7 @@ LICENSE END */
|
||||||
//! Assign the Element::item_index on each elements
|
//! Assign the Element::item_index on each elements
|
||||||
pub fn generate_item_indices(component: &std::rc::Rc<crate::object_tree::Component>) {
|
pub fn generate_item_indices(component: &std::rc::Rc<crate::object_tree::Component>) {
|
||||||
let mut current_item_index: usize = 0;
|
let mut current_item_index: usize = 0;
|
||||||
crate::generator::build_array_helper(component, move |item_rc, _, _| {
|
crate::object_tree::recurse_elem_level_order(&component.root_element, &mut |item_rc| {
|
||||||
let item = item_rc.borrow();
|
let item = item_rc.borrow();
|
||||||
if item.base_type == crate::langtype::Type::Void {
|
if item.base_type == crate::langtype::Type::Void {
|
||||||
} else {
|
} else {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue