@@ -3,8 +3,8 @@ use taffy::style_helpers;
3
3
use crate :: {
4
4
AlignContent , AlignItems , AlignSelf , Display , FlexDirection , FlexWrap , GridAutoFlow ,
5
5
GridPlacement , GridTrack , GridTrackRepetition , JustifyContent , JustifyItems , JustifySelf ,
6
- MaxTrackSizingFunction , MinTrackSizingFunction , PositionType , RepeatedGridTrack , Style , UiRect ,
7
- Val ,
6
+ MaxTrackSizingFunction , MinTrackSizingFunction , OverflowAxis , PositionType , RepeatedGridTrack ,
7
+ Style , UiRect , Val ,
8
8
} ;
9
9
10
10
use super :: LayoutContext ;
@@ -18,31 +18,31 @@ impl Val {
18
18
Val :: Auto => taffy:: style:: LengthPercentageAuto :: Auto ,
19
19
Val :: Percent ( value) => taffy:: style:: LengthPercentageAuto :: Percent ( value / 100. ) ,
20
20
Val :: Px ( value) => {
21
- taffy:: style:: LengthPercentageAuto :: Points ( context. scale_factor * value)
21
+ taffy:: style:: LengthPercentageAuto :: Length ( context. scale_factor * value)
22
22
}
23
23
Val :: VMin ( value) => {
24
- taffy:: style:: LengthPercentageAuto :: Points ( context. min_size * value / 100. )
24
+ taffy:: style:: LengthPercentageAuto :: Length ( context. min_size * value / 100. )
25
25
}
26
26
Val :: VMax ( value) => {
27
- taffy:: style:: LengthPercentageAuto :: Points ( context. max_size * value / 100. )
27
+ taffy:: style:: LengthPercentageAuto :: Length ( context. max_size * value / 100. )
28
28
}
29
29
Val :: Vw ( value) => {
30
- taffy:: style:: LengthPercentageAuto :: Points ( context. physical_size . x * value / 100. )
30
+ taffy:: style:: LengthPercentageAuto :: Length ( context. physical_size . x * value / 100. )
31
31
}
32
32
Val :: Vh ( value) => {
33
- taffy:: style:: LengthPercentageAuto :: Points ( context. physical_size . y * value / 100. )
33
+ taffy:: style:: LengthPercentageAuto :: Length ( context. physical_size . y * value / 100. )
34
34
}
35
35
}
36
36
}
37
37
38
38
fn into_length_percentage ( self , context : & LayoutContext ) -> taffy:: style:: LengthPercentage {
39
39
match self . into_length_percentage_auto ( context) {
40
- taffy:: style:: LengthPercentageAuto :: Auto => taffy:: style:: LengthPercentage :: Points ( 0.0 ) ,
40
+ taffy:: style:: LengthPercentageAuto :: Auto => taffy:: style:: LengthPercentage :: Length ( 0.0 ) ,
41
41
taffy:: style:: LengthPercentageAuto :: Percent ( value) => {
42
42
taffy:: style:: LengthPercentage :: Percent ( value)
43
43
}
44
- taffy:: style:: LengthPercentageAuto :: Points ( value) => {
45
- taffy:: style:: LengthPercentage :: Points ( value)
44
+ taffy:: style:: LengthPercentageAuto :: Length ( value) => {
45
+ taffy:: style:: LengthPercentage :: Length ( value)
46
46
}
47
47
}
48
48
}
@@ -63,9 +63,18 @@ impl UiRect {
63
63
}
64
64
}
65
65
66
- pub fn from_style ( context : & LayoutContext , style : & Style ) -> taffy:: style:: Style {
66
+ pub fn from_style (
67
+ context : & LayoutContext ,
68
+ style : & Style ,
69
+ ignore_padding_and_border : bool ,
70
+ ) -> taffy:: style:: Style {
67
71
taffy:: style:: Style {
68
72
display : style. display . into ( ) ,
73
+ overflow : taffy:: Point {
74
+ x : style. overflow . x . into ( ) ,
75
+ y : style. overflow . y . into ( ) ,
76
+ } ,
77
+ scrollbar_width : 0.0 ,
69
78
position : style. position_type . into ( ) ,
70
79
flex_direction : style. flex_direction . into ( ) ,
71
80
flex_wrap : style. flex_wrap . into ( ) ,
@@ -75,7 +84,7 @@ pub fn from_style(context: &LayoutContext, style: &Style) -> taffy::style::Style
75
84
justify_self : style. justify_self . into ( ) ,
76
85
align_content : style. align_content . into ( ) ,
77
86
justify_content : style. justify_content . into ( ) ,
78
- inset : taffy:: prelude :: Rect {
87
+ inset : taffy:: Rect {
79
88
left : style. left . into_length_percentage_auto ( context) ,
80
89
right : style. right . into_length_percentage_auto ( context) ,
81
90
top : style. top . into_length_percentage_auto ( context) ,
@@ -84,29 +93,41 @@ pub fn from_style(context: &LayoutContext, style: &Style) -> taffy::style::Style
84
93
margin : style
85
94
. margin
86
95
. map_to_taffy_rect ( |m| m. into_length_percentage_auto ( context) ) ,
87
- padding : style
88
- . padding
89
- . map_to_taffy_rect ( |m| m. into_length_percentage ( context) ) ,
90
- border : style
91
- . border
92
- . map_to_taffy_rect ( |m| m. into_length_percentage ( context) ) ,
96
+ // Ignore padding for leaf nodes as it isn't implemented in the rendering engine.
97
+ // TODO: Implement rendering of padding for leaf nodes
98
+ padding : if ignore_padding_and_border {
99
+ taffy:: Rect :: zero ( )
100
+ } else {
101
+ style
102
+ . padding
103
+ . map_to_taffy_rect ( |m| m. into_length_percentage ( context) )
104
+ } ,
105
+ // Ignore border for leaf nodes as it isn't implemented in the rendering engine.
106
+ // TODO: Implement rendering of border for leaf nodes
107
+ border : if ignore_padding_and_border {
108
+ taffy:: Rect :: zero ( )
109
+ } else {
110
+ style
111
+ . border
112
+ . map_to_taffy_rect ( |m| m. into_length_percentage ( context) )
113
+ } ,
93
114
flex_grow : style. flex_grow ,
94
115
flex_shrink : style. flex_shrink ,
95
116
flex_basis : style. flex_basis . into_dimension ( context) ,
96
- size : taffy:: prelude :: Size {
117
+ size : taffy:: Size {
97
118
width : style. width . into_dimension ( context) ,
98
119
height : style. height . into_dimension ( context) ,
99
120
} ,
100
- min_size : taffy:: prelude :: Size {
121
+ min_size : taffy:: Size {
101
122
width : style. min_width . into_dimension ( context) ,
102
123
height : style. min_height . into_dimension ( context) ,
103
124
} ,
104
- max_size : taffy:: prelude :: Size {
125
+ max_size : taffy:: Size {
105
126
width : style. max_width . into_dimension ( context) ,
106
127
height : style. max_height . into_dimension ( context) ,
107
128
} ,
108
129
aspect_ratio : style. aspect_ratio ,
109
- gap : taffy:: prelude :: Size {
130
+ gap : taffy:: Size {
110
131
width : style. column_gap . into_length_percentage ( context) ,
111
132
height : style. row_gap . into_length_percentage ( context) ,
112
133
} ,
@@ -231,11 +252,22 @@ impl From<Display> for taffy::style::Display {
231
252
match value {
232
253
Display :: Flex => taffy:: style:: Display :: Flex ,
233
254
Display :: Grid => taffy:: style:: Display :: Grid ,
255
+ Display :: Block => taffy:: style:: Display :: Block ,
234
256
Display :: None => taffy:: style:: Display :: None ,
235
257
}
236
258
}
237
259
}
238
260
261
+ impl From < OverflowAxis > for taffy:: style:: Overflow {
262
+ fn from ( value : OverflowAxis ) -> Self {
263
+ match value {
264
+ OverflowAxis :: Visible => taffy:: style:: Overflow :: Visible ,
265
+ OverflowAxis :: Clip => taffy:: style:: Overflow :: Clip ,
266
+ OverflowAxis :: Hidden => taffy:: style:: Overflow :: Hidden ,
267
+ }
268
+ }
269
+ }
270
+
239
271
impl From < FlexDirection > for taffy:: style:: FlexDirection {
240
272
fn from ( value : FlexDirection ) -> Self {
241
273
match value {
@@ -489,7 +521,7 @@ mod tests {
489
521
grid_row : GridPlacement :: span ( 3 ) ,
490
522
} ;
491
523
let viewport_values = LayoutContext :: new ( 1.0 , bevy_math:: Vec2 :: new ( 800. , 600. ) ) ;
492
- let taffy_style = from_style ( & viewport_values, & bevy_style) ;
524
+ let taffy_style = from_style ( & viewport_values, & bevy_style, false ) ;
493
525
assert_eq ! ( taffy_style. display, taffy:: style:: Display :: Flex ) ;
494
526
assert_eq ! ( taffy_style. position, taffy:: style:: Position :: Absolute ) ;
495
527
assert_eq ! (
@@ -502,7 +534,7 @@ mod tests {
502
534
) ;
503
535
assert_eq ! (
504
536
taffy_style. inset. top,
505
- taffy:: style:: LengthPercentageAuto :: Points ( 12. )
537
+ taffy:: style:: LengthPercentageAuto :: Length ( 12. )
506
538
) ;
507
539
assert_eq ! (
508
540
taffy_style. inset. bottom,
@@ -537,7 +569,7 @@ mod tests {
537
569
) ;
538
570
assert_eq ! (
539
571
taffy_style. margin. right,
540
- taffy:: style:: LengthPercentageAuto :: Points ( 10. )
572
+ taffy:: style:: LengthPercentageAuto :: Length ( 10. )
541
573
) ;
542
574
assert_eq ! (
543
575
taffy_style. margin. top,
@@ -553,7 +585,7 @@ mod tests {
553
585
) ;
554
586
assert_eq ! (
555
587
taffy_style. padding. right,
556
- taffy:: style:: LengthPercentage :: Points ( 21. )
588
+ taffy:: style:: LengthPercentage :: Length ( 21. )
557
589
) ;
558
590
assert_eq ! (
559
591
taffy_style. padding. top,
@@ -565,7 +597,7 @@ mod tests {
565
597
) ;
566
598
assert_eq ! (
567
599
taffy_style. border. left,
568
- taffy:: style:: LengthPercentage :: Points ( 14. )
600
+ taffy:: style:: LengthPercentage :: Length ( 14. )
569
601
) ;
570
602
assert_eq ! (
571
603
taffy_style. border. right,
@@ -594,18 +626,18 @@ mod tests {
594
626
) ;
595
627
assert_eq ! (
596
628
taffy_style. grid_template_rows,
597
- vec![ sh:: points ( 10.0 ) , sh:: percent( 0.5 ) , sh:: fr( 1.0 ) ]
629
+ vec![ sh:: length ( 10.0 ) , sh:: percent( 0.5 ) , sh:: fr( 1.0 ) ]
598
630
) ;
599
631
assert_eq ! (
600
632
taffy_style. grid_template_columns,
601
- vec![ sh:: repeat( 5 , vec![ sh:: points ( 10.0 ) ] ) ]
633
+ vec![ sh:: repeat( 5 , vec![ sh:: length ( 10.0 ) ] ) ]
602
634
) ;
603
635
assert_eq ! (
604
636
taffy_style. grid_auto_rows,
605
637
vec![
606
- sh:: fit_content( taffy:: style:: LengthPercentage :: Points ( 10.0 ) ) ,
638
+ sh:: fit_content( taffy:: style:: LengthPercentage :: Length ( 10.0 ) ) ,
607
639
sh:: fit_content( taffy:: style:: LengthPercentage :: Percent ( 0.25 ) ) ,
608
- sh:: minmax( sh:: points ( 0.0 ) , sh:: fr( 2.0 ) ) ,
640
+ sh:: minmax( sh:: length ( 0.0 ) , sh:: fr( 2.0 ) ) ,
609
641
]
610
642
) ;
611
643
assert_eq ! (
@@ -627,17 +659,17 @@ mod tests {
627
659
use taffy:: style:: LengthPercentage ;
628
660
let context = LayoutContext :: new ( 2.0 , bevy_math:: Vec2 :: new ( 800. , 600. ) ) ;
629
661
let cases = [
630
- ( Val :: Auto , LengthPercentage :: Points ( 0. ) ) ,
662
+ ( Val :: Auto , LengthPercentage :: Length ( 0. ) ) ,
631
663
( Val :: Percent ( 1. ) , LengthPercentage :: Percent ( 0.01 ) ) ,
632
- ( Val :: Px ( 1. ) , LengthPercentage :: Points ( 2. ) ) ,
633
- ( Val :: Vw ( 1. ) , LengthPercentage :: Points ( 8. ) ) ,
634
- ( Val :: Vh ( 1. ) , LengthPercentage :: Points ( 6. ) ) ,
635
- ( Val :: VMin ( 2. ) , LengthPercentage :: Points ( 12. ) ) ,
636
- ( Val :: VMax ( 2. ) , LengthPercentage :: Points ( 16. ) ) ,
664
+ ( Val :: Px ( 1. ) , LengthPercentage :: Length ( 2. ) ) ,
665
+ ( Val :: Vw ( 1. ) , LengthPercentage :: Length ( 8. ) ) ,
666
+ ( Val :: Vh ( 1. ) , LengthPercentage :: Length ( 6. ) ) ,
667
+ ( Val :: VMin ( 2. ) , LengthPercentage :: Length ( 12. ) ) ,
668
+ ( Val :: VMax ( 2. ) , LengthPercentage :: Length ( 16. ) ) ,
637
669
] ;
638
670
for ( val, length) in cases {
639
671
assert ! ( match ( val. into_length_percentage( & context) , length) {
640
- ( LengthPercentage :: Points ( a) , LengthPercentage :: Points ( b) )
672
+ ( LengthPercentage :: Length ( a) , LengthPercentage :: Length ( b) )
641
673
| ( LengthPercentage :: Percent ( a) , LengthPercentage :: Percent ( b) ) =>
642
674
( a - b) . abs( ) < 0.0001 ,
643
675
_ => false ,
0 commit comments