@@ -3,71 +3,72 @@ use crate::{
3
3
JustifyContent , PositionType , Style , Val ,
4
4
} ;
5
5
use bevy_math:: { Rect , Size } ;
6
- use bevy_reflect:: Reflect ;
7
6
8
- fn from_rect < T , U : Reflect > ( rect : Rect < U > ) -> stretch :: geometry :: Rect < T >
9
- where
10
- T : From < U > ,
11
- {
7
+ pub fn from_rect (
8
+ scale_factor : f64 ,
9
+ rect : Rect < Val > ,
10
+ ) -> stretch :: geometry :: Rect < stretch :: style :: Dimension > {
12
11
stretch:: geometry:: Rect {
13
- start : rect. left . into ( ) ,
14
- end : rect. right . into ( ) ,
12
+ start : from_val ( scale_factor , rect. left ) ,
13
+ end : from_val ( scale_factor , rect. right ) ,
15
14
// NOTE: top and bottom are intentionally flipped. stretch has a flipped y-axis
16
- top : rect. bottom . into ( ) ,
17
- bottom : rect. top . into ( ) ,
15
+ top : from_val ( scale_factor , rect. bottom ) ,
16
+ bottom : from_val ( scale_factor , rect. top ) ,
18
17
}
19
18
}
20
19
21
- fn from_size < T , U > ( size : Size < U > ) -> stretch:: geometry:: Size < T >
22
- where
23
- U : Reflect ,
24
- T : From < U > ,
25
- {
20
+ pub fn from_f32_size ( scale_factor : f64 , size : Size < f32 > ) -> stretch:: geometry:: Size < f32 > {
26
21
stretch:: geometry:: Size {
27
- width : size. width . into ( ) ,
28
- height : size. height . into ( ) ,
22
+ width : ( scale_factor * size. width as f64 ) as f32 ,
23
+ height : ( scale_factor * size. height as f64 ) as f32 ,
29
24
}
30
25
}
31
26
32
- impl From < & Style > for stretch:: style:: Style {
33
- fn from ( value : & Style ) -> Self {
34
- Self {
35
- overflow : stretch:: style:: Overflow :: Visible ,
36
- display : value. display . into ( ) ,
37
- position_type : value. position_type . into ( ) ,
38
- direction : value. direction . into ( ) ,
39
- flex_direction : value. flex_direction . into ( ) ,
40
- flex_wrap : value. flex_wrap . into ( ) ,
41
- align_items : value. align_items . into ( ) ,
42
- align_self : value. align_self . into ( ) ,
43
- align_content : value. align_content . into ( ) ,
44
- justify_content : value. justify_content . into ( ) ,
45
- position : from_rect ( value. position ) ,
46
- margin : from_rect ( value. margin ) ,
47
- padding : from_rect ( value. padding ) ,
48
- border : from_rect ( value. border ) ,
49
- flex_grow : value. flex_grow ,
50
- flex_shrink : value. flex_shrink ,
51
- flex_basis : value. flex_basis . into ( ) ,
52
- size : from_size ( value. size ) ,
53
- min_size : from_size ( value. min_size ) ,
54
- max_size : from_size ( value. max_size ) ,
55
- aspect_ratio : match value. aspect_ratio {
56
- Some ( value) => stretch:: number:: Number :: Defined ( value) ,
57
- None => stretch:: number:: Number :: Undefined ,
58
- } ,
59
- }
27
+ pub fn from_val_size (
28
+ scale_factor : f64 ,
29
+ size : Size < Val > ,
30
+ ) -> stretch:: geometry:: Size < stretch:: style:: Dimension > {
31
+ stretch:: geometry:: Size {
32
+ width : from_val ( scale_factor, size. width ) ,
33
+ height : from_val ( scale_factor, size. height ) ,
60
34
}
61
35
}
62
36
63
- impl From < Val > for stretch:: style:: Dimension {
64
- fn from ( val : Val ) -> Self {
65
- match val {
66
- Val :: Auto => stretch:: style:: Dimension :: Auto ,
67
- Val :: Percent ( value) => stretch:: style:: Dimension :: Percent ( value / 100.0 ) ,
68
- Val :: Px ( value) => stretch:: style:: Dimension :: Points ( value) ,
69
- Val :: Undefined => stretch:: style:: Dimension :: Undefined ,
70
- }
37
+ pub fn from_style ( scale_factor : f64 , value : & Style ) -> stretch:: style:: Style {
38
+ stretch:: style:: Style {
39
+ overflow : stretch:: style:: Overflow :: Visible ,
40
+ display : value. display . into ( ) ,
41
+ position_type : value. position_type . into ( ) ,
42
+ direction : value. direction . into ( ) ,
43
+ flex_direction : value. flex_direction . into ( ) ,
44
+ flex_wrap : value. flex_wrap . into ( ) ,
45
+ align_items : value. align_items . into ( ) ,
46
+ align_self : value. align_self . into ( ) ,
47
+ align_content : value. align_content . into ( ) ,
48
+ justify_content : value. justify_content . into ( ) ,
49
+ position : from_rect ( scale_factor, value. position ) ,
50
+ margin : from_rect ( scale_factor, value. margin ) ,
51
+ padding : from_rect ( scale_factor, value. padding ) ,
52
+ border : from_rect ( scale_factor, value. border ) ,
53
+ flex_grow : value. flex_grow ,
54
+ flex_shrink : value. flex_shrink ,
55
+ flex_basis : from_val ( scale_factor, value. flex_basis ) ,
56
+ size : from_val_size ( scale_factor, value. size ) ,
57
+ min_size : from_val_size ( scale_factor, value. min_size ) ,
58
+ max_size : from_val_size ( scale_factor, value. max_size ) ,
59
+ aspect_ratio : match value. aspect_ratio {
60
+ Some ( value) => stretch:: number:: Number :: Defined ( value) ,
61
+ None => stretch:: number:: Number :: Undefined ,
62
+ } ,
63
+ }
64
+ }
65
+
66
+ pub fn from_val ( scale_factor : f64 , val : Val ) -> stretch:: style:: Dimension {
67
+ match val {
68
+ Val :: Auto => stretch:: style:: Dimension :: Auto ,
69
+ Val :: Percent ( value) => stretch:: style:: Dimension :: Percent ( value / 100.0 ) ,
70
+ Val :: Px ( value) => stretch:: style:: Dimension :: Points ( ( scale_factor * value as f64 ) as f32 ) ,
71
+ Val :: Undefined => stretch:: style:: Dimension :: Undefined ,
71
72
}
72
73
}
73
74
0 commit comments