sixtyfps_compilerlib/llr/
item_tree.rs1use super::Expression;
5use crate::langtype::{NativeClass, Type};
6use std::collections::{BTreeMap, HashMap};
7use std::num::NonZeroUsize;
8use std::rc::Rc;
9
10pub type PropertyIndex = usize;
12
13#[derive(Debug, Clone)]
14pub enum Animation {
15 Static(Expression),
17 Transition(Expression),
18}
19
20#[derive(Debug, Clone)]
21pub struct BindingExpression {
22 pub expression: Expression,
23 pub animation: Option<Animation>,
24 pub is_constant: bool,
26}
27
28#[derive(Debug)]
29pub struct GlobalComponent {
30 pub name: String,
31 pub properties: Vec<Property>,
32 pub init_values: Vec<Option<BindingExpression>>,
34 pub const_properties: Vec<bool>,
35 pub public_properties: PublicProperties,
36 pub exported: bool,
38 pub aliases: Vec<String>,
41 pub is_builtin: bool,
43}
44
45#[derive(Clone, Debug, Hash, PartialEq, Eq)]
47pub enum PropertyReference {
48 Local { sub_component_path: Vec<usize>, property_index: PropertyIndex },
50 InNativeItem { sub_component_path: Vec<usize>, item_index: usize, prop_name: String },
52 InParent { level: NonZeroUsize, parent_reference: Box<PropertyReference> },
54 Global { global_index: usize, property_index: usize },
56}
57
58#[derive(Debug)]
59pub struct Property {
60 pub name: String,
61 pub ty: Type,
62}
63
64#[derive(Debug, Clone)]
65pub struct ListViewInfo {
68 pub viewport_y: PropertyReference,
69 pub viewport_height: PropertyReference,
70 pub viewport_width: PropertyReference,
71 pub listview_height: PropertyReference,
73 pub listview_width: PropertyReference,
75
76 pub prop_y: PropertyReference,
78 pub prop_width: PropertyReference,
80 pub prop_height: PropertyReference,
82}
83
84#[derive(Debug)]
85pub struct RepeatedElement {
86 pub model: Expression,
87 pub index_prop: Option<PropertyIndex>,
89 pub data_prop: Option<PropertyIndex>,
91 pub sub_tree: ItemTree,
92 pub index_in_tree: usize,
94
95 pub listview: Option<ListViewInfo>,
96}
97
98pub struct Item {
99 pub ty: Rc<NativeClass>,
100 pub name: String,
101 pub index_in_tree: usize,
103 pub is_flickable_viewport: bool,
107}
108
109impl std::fmt::Debug for Item {
110 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
111 f.debug_struct("Item")
112 .field("ty", &self.ty.class_name)
113 .field("name", &self.name)
114 .field("index_in_tree", &self.index_in_tree)
115 .field("is_flickable_viewport", &self.is_flickable_viewport)
116 .finish()
117 }
118}
119
120#[derive(Debug)]
121pub struct TreeNode {
122 pub sub_component_path: Vec<usize>,
123 pub item_index: usize,
125 pub repeated: bool,
126 pub children: Vec<TreeNode>,
127}
128
129impl TreeNode {
130 fn children_count(&self) -> usize {
131 let mut count = self.children.len();
132 for c in &self.children {
133 count += c.children_count();
134 }
135 count
136 }
137
138 pub fn visit_in_array(
141 &self,
142 visitor: &mut dyn FnMut(
143 &TreeNode,
144 usize,
145 usize,
146 ),
147 ) {
148 visitor(self, 1, 0);
149 visit_in_array_recursive(self, 1, 0, visitor);
150
151 fn visit_in_array_recursive(
152 node: &TreeNode,
153 children_offset: usize,
154 current_index: usize,
155 visitor: &mut dyn FnMut(&TreeNode, usize, usize),
156 ) {
157 let mut offset = children_offset + node.children.len();
158 for c in &node.children {
159 visitor(c, offset, current_index);
160 offset += c.children_count();
161 }
162
163 let mut offset = children_offset + node.children.len();
164 for (i, c) in node.children.iter().enumerate() {
165 visit_in_array_recursive(c, offset, children_offset + i, visitor);
166 offset += c.children_count();
167 }
168 }
169 }
170}
171
172#[derive(Debug)]
173pub struct SubComponent {
174 pub name: String,
175 pub properties: Vec<Property>,
176 pub items: Vec<Item>,
177 pub repeated: Vec<RepeatedElement>,
178 pub popup_windows: Vec<ItemTree>,
179 pub sub_components: Vec<SubComponentInstance>,
180 pub property_init: Vec<(PropertyReference, BindingExpression)>,
183 pub animations: HashMap<PropertyReference, Expression>,
185 pub two_way_bindings: Vec<(PropertyReference, PropertyReference)>,
186 pub const_properties: Vec<PropertyReference>,
187 pub init_code: Vec<Expression>,
189
190 pub layout_info_h: Expression,
191 pub layout_info_v: Expression,
192}
193
194impl SubComponent {
195 pub fn repeater_count(&self) -> usize {
197 let mut count = self.repeated.len();
198 for x in self.sub_components.iter() {
199 count += x.ty.repeater_count();
200 }
201 count
202 }
203}
204
205pub struct SubComponentInstance {
206 pub ty: Rc<SubComponent>,
207 pub name: String,
208 pub index_in_tree: usize,
209 pub index_of_first_child_in_tree: usize,
210 pub repeater_offset: usize,
211}
212
213impl std::fmt::Debug for SubComponentInstance {
214 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
215 f.debug_struct("SubComponentInstance")
216 .field("ty", &self.ty.name)
218 .field("name", &self.name)
219 .field("index_in_tree", &self.index_in_tree)
220 .field("index_of_first_child_in_tree", &self.index_of_first_child_in_tree)
221 .field("repeater_offset", &self.repeater_offset)
222 .finish()
223 }
224}
225
226#[derive(Debug)]
227pub struct ItemTree {
228 pub root: SubComponent,
229 pub tree: TreeNode,
230 pub parent_context: Option<String>,
234}
235
236#[derive(Debug)]
237pub struct PublicComponent {
238 pub public_properties: PublicProperties,
239 pub item_tree: ItemTree,
240 pub sub_components: Vec<Rc<SubComponent>>,
241 pub globals: Vec<GlobalComponent>,
242}
243
244pub type PublicProperties = BTreeMap<String, (Type, PropertyReference)>;