@@ -20,7 +20,7 @@ pub(crate) fn lower_property_to_element(
20
20
component : & Rc < Component > ,
21
21
property_names : impl Iterator < Item = & ' static str > + Clone ,
22
22
extra_properties : impl Iterator < Item = & ' static str > + Clone ,
23
- default_value_for_extra_properties : Option < & dyn Fn ( & ElementRc , & str ) -> Expression > ,
23
+ default_value_for_extra_properties : Option < & dyn Fn ( & ElementRc , & str ) -> Option < Expression > > ,
24
24
element_name : & SmolStr ,
25
25
type_register : & TypeRegister ,
26
26
diag : & mut BuildDiagnostics ,
@@ -95,7 +95,7 @@ pub(crate) fn lower_property_to_element(
95
95
fn create_property_element (
96
96
child : & ElementRc ,
97
97
properties : impl Iterator < Item = & ' static str > ,
98
- default_value_for_extra_properties : Option < & dyn Fn ( & ElementRc , & str ) -> Expression > ,
98
+ default_value_for_extra_properties : Option < & dyn Fn ( & ElementRc , & str ) -> Option < Expression > > ,
99
99
element_name : & SmolStr ,
100
100
type_register : & TypeRegister ,
101
101
) -> ElementRc {
@@ -105,7 +105,9 @@ fn create_property_element(
105
105
BindingExpression :: new_two_way ( NamedReference :: new ( child, property_name. into ( ) ) ) ;
106
106
if let Some ( default_value_for_extra_properties) = default_value_for_extra_properties {
107
107
if !child. borrow ( ) . bindings . contains_key ( property_name) {
108
- bind. expression = default_value_for_extra_properties ( child, property_name)
108
+ if let Some ( e) = default_value_for_extra_properties ( child, property_name) {
109
+ bind. expression = e;
110
+ }
109
111
}
110
112
}
111
113
( property_name. into ( ) , bind. into ( ) )
@@ -121,3 +123,50 @@ fn create_property_element(
121
123
} ;
122
124
element. make_rc ( )
123
125
}
126
+
127
+ /// Wrapper around lower_property_to_element for the Transform element
128
+ pub fn lower_transform_properties (
129
+ component : & Rc < Component > ,
130
+ tr : & TypeRegister ,
131
+ diag : & mut BuildDiagnostics ,
132
+ ) {
133
+ lower_property_to_element (
134
+ component,
135
+ crate :: typeregister:: RESERVED_TRANSFORM_PROPERTIES [ ..4 ]
136
+ . iter ( )
137
+ . map ( |( prop_name, _) | * prop_name) ,
138
+ crate :: typeregister:: RESERVED_TRANSFORM_PROPERTIES [ 4 ..]
139
+ . iter ( )
140
+ . map ( |( prop_name, _) | * prop_name) ,
141
+ Some ( & |e, prop| {
142
+ let prop_div_2 = |prop : & str | {
143
+ Some ( Expression :: BinaryExpression {
144
+ lhs : Expression :: PropertyReference ( NamedReference :: new ( e, prop. into ( ) ) ) . into ( ) ,
145
+ op : '/' ,
146
+ rhs : Expression :: NumberLiteral ( 2. , Default :: default ( ) ) . into ( ) ,
147
+ } )
148
+ } ;
149
+
150
+ match prop {
151
+ "rotation-origin-x" => prop_div_2 ( "width" ) ,
152
+ "rotation-origin-y" => prop_div_2 ( "height" ) ,
153
+ "scale-x" | "scale-y" => {
154
+ if e. borrow ( ) . is_binding_set ( "scale" , true ) {
155
+ Some ( Expression :: PropertyReference ( NamedReference :: new (
156
+ e,
157
+ SmolStr :: new_static ( "scale" ) ,
158
+ ) ) )
159
+ } else {
160
+ Some ( Expression :: NumberLiteral ( 1. , Default :: default ( ) ) )
161
+ }
162
+ }
163
+ "scale" => None ,
164
+ "rotation-angle" => Some ( Expression :: NumberLiteral ( 0. , Default :: default ( ) ) ) ,
165
+ _ => unreachable ! ( ) ,
166
+ }
167
+ } ) ,
168
+ & SmolStr :: new_static ( "Transform" ) ,
169
+ tr,
170
+ diag,
171
+ ) ;
172
+ }
0 commit comments