i_slint_compiler/passes/lower_repeated_rows.rs
1// Copyright © Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com, author David Faure <david.faure@kdab.com>
2// SPDX-License-Identifier: GPL-3.0-only OR LicenseRef-Slint-Royalty-free-2.0 OR LicenseRef-Slint-Software-3.0
3
4//! This pass turns the repeated Row elements (of grid layouts) to Empty elements
5//! Non-repeated rows were already removed in lower_layout.rs
6//! But repeated rows have to be kept (as a component, not as Empty elements) longer,
7//! they're the enclosing component for their children.
8
9use crate::object_tree::{self, Component};
10use crate::typeregister::TypeRegister;
11use std::rc::Rc;
12
13pub(crate) fn lower_repeated_rows(component: &Rc<Component>, type_register: &TypeRegister) {
14 object_tree::recurse_elem_including_sub_components_no_borrow(component, &(), &mut |elem, _| {
15 let is_repeated_row = {
16 if let Some(cell) = elem.borrow().grid_layout_cell.as_ref() {
17 cell.borrow().child_items.is_some()
18 } else {
19 false
20 }
21 };
22
23 if is_repeated_row {
24 // Repeated Row in a grid layout
25 elem.borrow_mut().base_type = type_register.empty_type();
26 }
27 });
28}