@@ -11,13 +11,12 @@ impl Val {
1111 Val :: Auto => Val :: Auto ,
1212 Val :: Percent ( value) => Val :: Percent ( value) ,
1313 Val :: Px ( value) => Val :: Px ( ( scale_factor * value as f64 ) as f32 ) ,
14- Val :: Undefined => Val :: Undefined ,
1514 }
1615 }
1716
1817 fn to_inset ( self ) -> LengthPercentageAuto {
1918 match self {
20- Val :: Auto | Val :: Undefined => taffy:: style:: LengthPercentageAuto :: Auto ,
19+ Val :: Auto => taffy:: style:: LengthPercentageAuto :: Auto ,
2120 Val :: Percent ( value) => taffy:: style:: LengthPercentageAuto :: Percent ( value / 100.0 ) ,
2221 Val :: Px ( value) => taffy:: style:: LengthPercentageAuto :: Points ( value) ,
2322 }
@@ -67,7 +66,7 @@ impl<T: From<Val>> From<Size> for taffy::prelude::Size<T> {
6766impl From < Val > for taffy:: style:: Dimension {
6867 fn from ( value : Val ) -> Self {
6968 match value {
70- Val :: Auto | Val :: Undefined => taffy:: style:: Dimension :: Auto ,
69+ Val :: Auto => taffy:: style:: Dimension :: Auto ,
7170 Val :: Percent ( value) => taffy:: style:: Dimension :: Percent ( value / 100.0 ) ,
7271 Val :: Px ( value) => taffy:: style:: Dimension :: Points ( value) ,
7372 }
@@ -77,7 +76,7 @@ impl From<Val> for taffy::style::Dimension {
7776impl From < Val > for taffy:: style:: LengthPercentage {
7877 fn from ( value : Val ) -> Self {
7978 match value {
80- Val :: Auto | Val :: Undefined => taffy:: style:: LengthPercentage :: Points ( 0.0 ) ,
79+ Val :: Auto => taffy:: style:: LengthPercentage :: Points ( 0.0 ) ,
8180 Val :: Percent ( value) => taffy:: style:: LengthPercentage :: Percent ( value / 100.0 ) ,
8281 Val :: Px ( value) => taffy:: style:: LengthPercentage :: Points ( value) ,
8382 }
@@ -90,7 +89,6 @@ impl From<Val> for taffy::style::LengthPercentageAuto {
9089 Val :: Auto => taffy:: style:: LengthPercentageAuto :: Auto ,
9190 Val :: Percent ( value) => taffy:: style:: LengthPercentageAuto :: Percent ( value / 100.0 ) ,
9291 Val :: Px ( value) => taffy:: style:: LengthPercentageAuto :: Points ( value) ,
93- Val :: Undefined => taffy:: style:: LengthPercentageAuto :: Points ( 0. ) ,
9492 }
9593 }
9694}
@@ -106,10 +104,10 @@ pub fn from_style(scale_factor: f64, style: &Style) -> taffy::style::Style {
106104 align_content : Some ( style. align_content . into ( ) ) ,
107105 justify_content : Some ( style. justify_content . into ( ) ) ,
108106 inset : taffy:: prelude:: Rect {
109- left : style. position . left . scaled ( scale_factor) . to_inset ( ) ,
110- right : style. position . right . scaled ( scale_factor) . to_inset ( ) ,
111- top : style. position . top . scaled ( scale_factor) . to_inset ( ) ,
112- bottom : style. position . bottom . scaled ( scale_factor) . to_inset ( ) ,
107+ left : style. left . scaled ( scale_factor) . to_inset ( ) ,
108+ right : style. right . scaled ( scale_factor) . to_inset ( ) ,
109+ top : style. top . scaled ( scale_factor) . to_inset ( ) ,
110+ bottom : style. bottom . scaled ( scale_factor) . to_inset ( ) ,
113111 } ,
114112 margin : style. margin . scaled ( scale_factor) . into ( ) ,
115113 padding : style. padding . scaled ( scale_factor) . into ( ) ,
@@ -224,3 +222,190 @@ impl From<FlexWrap> for taffy::style::FlexWrap {
224222 }
225223 }
226224}
225+
226+ #[ cfg( test) ]
227+ mod tests {
228+ use super :: * ;
229+
230+ #[ test]
231+ fn test_convert_from ( ) {
232+ let bevy_style = crate :: Style {
233+ display : Display :: Flex ,
234+ position_type : PositionType :: Absolute ,
235+ left : Val :: Px ( 0. ) ,
236+ right : Val :: Percent ( 0. ) ,
237+ top : Val :: Auto ,
238+ bottom : Val :: Auto ,
239+ direction : crate :: Direction :: Inherit ,
240+ flex_direction : FlexDirection :: ColumnReverse ,
241+ flex_wrap : FlexWrap :: WrapReverse ,
242+ align_items : AlignItems :: Baseline ,
243+ align_self : AlignSelf :: Start ,
244+ align_content : AlignContent :: SpaceAround ,
245+ justify_content : JustifyContent :: SpaceEvenly ,
246+ margin : UiRect {
247+ left : Val :: Percent ( 0. ) ,
248+ right : Val :: Px ( 0. ) ,
249+ top : Val :: Auto ,
250+ bottom : Val :: Auto ,
251+ } ,
252+ padding : UiRect {
253+ left : Val :: Percent ( 0. ) ,
254+ right : Val :: Px ( 0. ) ,
255+ top : Val :: Percent ( 0. ) ,
256+ bottom : Val :: Percent ( 0. ) ,
257+ } ,
258+ border : UiRect {
259+ left : Val :: Px ( 0. ) ,
260+ right : Val :: Px ( 0. ) ,
261+ top : Val :: Auto ,
262+ bottom : Val :: Px ( 0. ) ,
263+ } ,
264+ flex_grow : 1. ,
265+ flex_shrink : 0. ,
266+ flex_basis : Val :: Px ( 0. ) ,
267+ size : Size {
268+ width : Val :: Px ( 0. ) ,
269+ height : Val :: Auto ,
270+ } ,
271+ min_size : Size {
272+ width : Val :: Px ( 0. ) ,
273+ height : Val :: Percent ( 0. ) ,
274+ } ,
275+ max_size : Size {
276+ width : Val :: Auto ,
277+ height : Val :: Px ( 0. ) ,
278+ } ,
279+ aspect_ratio : None ,
280+ overflow : crate :: Overflow :: Hidden ,
281+ gap : Size {
282+ width : Val :: Px ( 0. ) ,
283+ height : Val :: Percent ( 0. ) ,
284+ } ,
285+ } ;
286+ let taffy_style = from_style ( 1.0 , & bevy_style) ;
287+ assert_eq ! ( taffy_style. display, taffy:: style:: Display :: Flex ) ;
288+ assert_eq ! ( taffy_style. position, taffy:: style:: Position :: Absolute ) ;
289+ assert ! ( matches!(
290+ taffy_style. inset. left,
291+ taffy:: style:: LengthPercentageAuto :: Points ( _)
292+ ) ) ;
293+ assert ! ( matches!(
294+ taffy_style. inset. right,
295+ taffy:: style:: LengthPercentageAuto :: Percent ( _)
296+ ) ) ;
297+ assert ! ( matches!(
298+ taffy_style. inset. top,
299+ taffy:: style:: LengthPercentageAuto :: Auto
300+ ) ) ;
301+ assert ! ( matches!(
302+ taffy_style. inset. bottom,
303+ taffy:: style:: LengthPercentageAuto :: Auto
304+ ) ) ;
305+ assert_eq ! (
306+ taffy_style. flex_direction,
307+ taffy:: style:: FlexDirection :: ColumnReverse
308+ ) ;
309+ assert_eq ! ( taffy_style. flex_wrap, taffy:: style:: FlexWrap :: WrapReverse ) ;
310+ assert_eq ! (
311+ taffy_style. align_items,
312+ Some ( taffy:: style:: AlignItems :: Baseline )
313+ ) ;
314+ assert_eq ! ( taffy_style. align_self, Some ( taffy:: style:: AlignSelf :: Start ) ) ;
315+ assert_eq ! (
316+ taffy_style. align_content,
317+ Some ( taffy:: style:: AlignContent :: SpaceAround )
318+ ) ;
319+ assert_eq ! (
320+ taffy_style. justify_content,
321+ Some ( taffy:: style:: JustifyContent :: SpaceEvenly )
322+ ) ;
323+ assert ! ( matches!(
324+ taffy_style. margin. left,
325+ taffy:: style:: LengthPercentageAuto :: Percent ( _)
326+ ) ) ;
327+ assert ! ( matches!(
328+ taffy_style. margin. right,
329+ taffy:: style:: LengthPercentageAuto :: Points ( _)
330+ ) ) ;
331+ assert ! ( matches!(
332+ taffy_style. margin. top,
333+ taffy:: style:: LengthPercentageAuto :: Auto
334+ ) ) ;
335+ assert ! ( matches!(
336+ taffy_style. margin. bottom,
337+ taffy:: style:: LengthPercentageAuto :: Auto
338+ ) ) ;
339+ assert ! ( matches!(
340+ taffy_style. padding. left,
341+ taffy:: style:: LengthPercentage :: Percent ( _)
342+ ) ) ;
343+ assert ! ( matches!(
344+ taffy_style. padding. right,
345+ taffy:: style:: LengthPercentage :: Points ( _)
346+ ) ) ;
347+ assert ! ( matches!(
348+ taffy_style. padding. top,
349+ taffy:: style:: LengthPercentage :: Percent ( _)
350+ ) ) ;
351+ assert ! ( matches!(
352+ taffy_style. padding. bottom,
353+ taffy:: style:: LengthPercentage :: Percent ( _)
354+ ) ) ;
355+ assert ! ( matches!(
356+ taffy_style. border. left,
357+ taffy:: style:: LengthPercentage :: Points ( _)
358+ ) ) ;
359+ assert ! ( matches!(
360+ taffy_style. border. right,
361+ taffy:: style:: LengthPercentage :: Points ( _)
362+ ) ) ;
363+ assert ! ( matches!(
364+ taffy_style. border. top,
365+ taffy:: style:: LengthPercentage :: Points ( _)
366+ ) ) ;
367+ assert ! ( matches!(
368+ taffy_style. border. bottom,
369+ taffy:: style:: LengthPercentage :: Points ( _)
370+ ) ) ;
371+ assert_eq ! ( taffy_style. flex_grow, 1. ) ;
372+ assert_eq ! ( taffy_style. flex_shrink, 0. ) ;
373+ assert ! ( matches!(
374+ taffy_style. flex_basis,
375+ taffy:: style:: Dimension :: Points ( _)
376+ ) ) ;
377+ assert ! ( matches!(
378+ taffy_style. size. width,
379+ taffy:: style:: Dimension :: Points ( _)
380+ ) ) ;
381+ assert ! ( matches!(
382+ taffy_style. size. height,
383+ taffy:: style:: Dimension :: Auto
384+ ) ) ;
385+ assert ! ( matches!(
386+ taffy_style. min_size. width,
387+ taffy:: style:: Dimension :: Points ( _)
388+ ) ) ;
389+ assert ! ( matches!(
390+ taffy_style. min_size. height,
391+ taffy:: style:: Dimension :: Percent ( _)
392+ ) ) ;
393+ assert ! ( matches!(
394+ taffy_style. max_size. width,
395+ taffy:: style:: Dimension :: Auto
396+ ) ) ;
397+ assert ! ( matches!(
398+ taffy_style. max_size. height,
399+ taffy:: style:: Dimension :: Points ( _)
400+ ) ) ;
401+ assert_eq ! ( taffy_style. aspect_ratio, None ) ;
402+ assert_eq ! (
403+ taffy_style. gap. width,
404+ taffy:: style:: LengthPercentage :: Points ( 0. )
405+ ) ;
406+ assert_eq ! (
407+ taffy_style. gap. height,
408+ taffy:: style:: LengthPercentage :: Percent ( 0. )
409+ ) ;
410+ }
411+ }
0 commit comments