@@ -5,17 +5,17 @@ use crate::style::AvailableSpace;
5
5
#[ cfg( any( feature = "std" , feature = "alloc" ) ) ]
6
6
use crate :: util:: sys:: Box ;
7
7
8
- /// A function type that can be used in a [`MeasureFunc`]
8
+ /// Represents a node that can be sized A function type that can be used in a [`MeasureFunc`]
9
9
///
10
- /// This trait is automatically implemented for all types (including closures) that define a function with the appropriate type signature.
10
+ /// This trait is automatically implemented for `FnMut` closures that define a function with the appropriate type signature.
11
11
pub trait Measurable {
12
12
/// A user-defined context which is passed to taffy when the `compute_layout` function is called, and which Taffy then passes
13
13
/// into measure functions when it calls them
14
14
type Context ;
15
15
16
16
/// Measure node
17
17
fn measure (
18
- & self ,
18
+ & mut self ,
19
19
known_dimensions : Size < Option < f32 > > ,
20
20
available_space : Size < AvailableSpace > ,
21
21
context : & mut Self :: Context ,
@@ -26,20 +26,31 @@ pub trait Measurable {
26
26
pub enum MeasureFunc < Context = ( ) > {
27
27
/// Stores an unboxed function
28
28
#[ allow( clippy:: type_complexity) ]
29
- Raw ( fn ( Size < Option < f32 > > , Size < AvailableSpace > , context : & mut Context ) -> Size < f32 > ) ,
29
+ Raw ( fn ( Size < Option < f32 > > , Size < AvailableSpace > , & mut Context ) -> Size < f32 > ) ,
30
30
31
31
/// Stores a boxed function
32
32
#[ cfg( any( feature = "std" , feature = "alloc" ) ) ]
33
33
Boxed ( Box < dyn Measurable < Context = Context > > ) ,
34
34
}
35
35
36
+ /// A function that can be used to compute the intrinsic size of a node
37
+ pub enum SyncMeasureFunc < Context = ( ) > {
38
+ /// Stores an unboxed function
39
+ #[ allow( clippy:: type_complexity) ]
40
+ Raw ( fn ( Size < Option < f32 > > , Size < AvailableSpace > , & mut Context ) -> Size < f32 > ) ,
41
+
42
+ /// Stores a boxed function
43
+ #[ cfg( any( feature = "std" , feature = "alloc" ) ) ]
44
+ Boxed ( Box < dyn Measurable < Context = Context > + Send + Sync > ) ,
45
+ }
46
+
36
47
impl < Context > Measurable for MeasureFunc < Context > {
37
48
type Context = Context ;
38
49
39
50
/// Call the measure function to measure the node
40
51
#[ inline( always) ]
41
52
fn measure (
42
- & self ,
53
+ & mut self ,
43
54
known_dimensions : Size < Option < f32 > > ,
44
55
available_space : Size < AvailableSpace > ,
45
56
context : & mut Context ,
@@ -52,24 +63,13 @@ impl<Context> Measurable for MeasureFunc<Context> {
52
63
}
53
64
}
54
65
55
- /// A function that can be used to compute the intrinsic size of a node
56
- pub enum SyncMeasureFunc < Context = ( ) > {
57
- /// Stores an unboxed function
58
- #[ allow( clippy:: type_complexity) ]
59
- Raw ( fn ( Size < Option < f32 > > , Size < AvailableSpace > , context : & mut Context ) -> Size < f32 > ) ,
60
-
61
- /// Stores a boxed function
62
- #[ cfg( any( feature = "std" , feature = "alloc" ) ) ]
63
- Boxed ( Box < dyn Measurable < Context = Context > + Send + Sync > ) ,
64
- }
65
-
66
66
impl < Context > Measurable for SyncMeasureFunc < Context > {
67
67
type Context = Context ;
68
68
69
69
/// Call the measure function to measure the node
70
70
#[ inline( always) ]
71
71
fn measure (
72
- & self ,
72
+ & mut self ,
73
73
known_dimensions : Size < Option < f32 > > ,
74
74
available_space : Size < AvailableSpace > ,
75
75
context : & mut Context ,
0 commit comments