@@ -14,7 +14,10 @@ use bevy_transform::components::Transform;
14
14
use bevy_utils:: HashMap ;
15
15
use bevy_window:: { Window , WindowId , WindowScaleFactorChanged , Windows } ;
16
16
use std:: fmt;
17
- use taffy:: { number:: Number , Taffy } ;
17
+ use taffy:: {
18
+ prelude:: { AvailableSpace , Size } ,
19
+ Taffy ,
20
+ } ;
18
21
19
22
#[ derive( Resource ) ]
20
23
pub struct FlexSurface {
@@ -63,7 +66,7 @@ impl FlexSurface {
63
66
let taffy_style = convert:: from_style ( scale_factor, style) ;
64
67
let taffy_node = self . entity_to_taffy . entry ( entity) . or_insert_with ( || {
65
68
added = true ;
66
- taffy. new_node ( taffy_style, & Vec :: new ( ) ) . unwrap ( )
69
+ taffy. new_leaf ( taffy_style) . unwrap ( )
67
70
} ) ;
68
71
69
72
if !added {
@@ -81,23 +84,23 @@ impl FlexSurface {
81
84
let taffy = & mut self . taffy ;
82
85
let taffy_style = convert:: from_style ( scale_factor, style) ;
83
86
let measure = taffy:: node:: MeasureFunc :: Boxed ( Box :: new (
84
- move |constraints : taffy :: geometry :: Size < Number > | {
87
+ move |constraints : Size < Option < f32 > > , _available : Size < AvailableSpace > | {
85
88
let mut size = convert:: from_f32_size ( scale_factor, calculated_size. size ) ;
86
89
match ( constraints. width , constraints. height ) {
87
- ( Number :: Undefined , Number :: Undefined ) => { }
88
- ( Number :: Defined ( width) , Number :: Undefined ) => {
90
+ ( None , None ) => { }
91
+ ( Some ( width) , None ) => {
89
92
if calculated_size. preserve_aspect_ratio {
90
93
size. height = width * size. height / size. width ;
91
94
}
92
95
size. width = width;
93
96
}
94
- ( Number :: Undefined , Number :: Defined ( height) ) => {
97
+ ( None , Some ( height) ) => {
95
98
if calculated_size. preserve_aspect_ratio {
96
99
size. width = height * size. width / size. height ;
97
100
}
98
101
size. height = height;
99
102
}
100
- ( Number :: Defined ( width) , Number :: Defined ( height) ) => {
103
+ ( Some ( width) , Some ( height) ) => {
101
104
size. width = width;
102
105
size. height = height;
103
106
}
@@ -110,7 +113,7 @@ impl FlexSurface {
110
113
self . taffy . set_style ( * taffy_node, taffy_style) . unwrap ( ) ;
111
114
self . taffy . set_measure ( * taffy_node, Some ( measure) ) . unwrap ( ) ;
112
115
} else {
113
- let taffy_node = taffy. new_leaf ( taffy_style, measure ) . unwrap ( ) ;
116
+ let taffy_node = taffy. new_leaf ( taffy_style) . unwrap ( ) ;
114
117
self . entity_to_taffy . insert ( entity, taffy_node) ;
115
118
}
116
119
}
@@ -143,11 +146,10 @@ without UI components as a child of an entity with UI components, results may be
143
146
144
147
pub fn update_window ( & mut self , window : & Window ) {
145
148
let taffy = & mut self . taffy ;
146
- let node = self . window_nodes . entry ( window. id ( ) ) . or_insert_with ( || {
147
- taffy
148
- . new_node ( taffy:: style:: Style :: default ( ) , & Vec :: new ( ) )
149
- . unwrap ( )
150
- } ) ;
149
+ let node = self
150
+ . window_nodes
151
+ . entry ( window. id ( ) )
152
+ . or_insert_with ( || taffy. new_leaf ( taffy:: style:: Style :: default ( ) ) . unwrap ( ) ) ;
151
153
152
154
taffy
153
155
. set_style (
@@ -178,7 +180,7 @@ without UI components as a child of an entity with UI components, results may be
178
180
pub fn compute_window_layouts ( & mut self ) {
179
181
for window_node in self . window_nodes . values ( ) {
180
182
self . taffy
181
- . compute_layout ( * window_node, taffy :: geometry :: Size :: undefined ( ) )
183
+ . compute_layout ( * window_node, Size :: MAX_CONTENT )
182
184
. unwrap ( ) ;
183
185
}
184
186
}
@@ -187,7 +189,7 @@ without UI components as a child of an entity with UI components, results may be
187
189
pub fn remove_entities ( & mut self , entities : impl IntoIterator < Item = Entity > ) {
188
190
for entity in entities {
189
191
if let Some ( node) = self . entity_to_taffy . remove ( & entity) {
190
- self . taffy . remove ( node) ;
192
+ self . taffy . remove ( node) . unwrap ( ) ;
191
193
}
192
194
}
193
195
}
@@ -210,7 +212,7 @@ with UI components as a child of an entity without UI components, results may be
210
212
#[ derive( Debug ) ]
211
213
pub enum FlexError {
212
214
InvalidHierarchy ,
213
- TaffyError ( taffy:: Error ) ,
215
+ TaffyError ( taffy:: error :: TaffyError ) ,
214
216
}
215
217
216
218
#[ allow( clippy:: too_many_arguments) ]
0 commit comments