1
1
use super :: {
2
- bail, bail_if_null, ok, try_or, TaffyFFIDefault , TaffyFFIResult , TaffyResult , TaffyReturnCode , TaffyStyleMutRef ,
2
+ bail, bail_if_null, ok, try_or, TaffyFFIDefault , TaffyFFIResult , TaffyLayout , TaffyResult , TaffyReturnCode ,
3
+ TaffyStyleMutRef ,
3
4
} ;
4
5
use taffy:: prelude as core;
5
6
use taffy:: Taffy as CoreTaffy ;
@@ -55,6 +56,10 @@ fn available_space_from_f32(input: f32) -> core::AvailableSpace {
55
56
}
56
57
}
57
58
59
+ // -------------------------------------------------
60
+ // Create and Free
61
+ // -------------------------------------------------
62
+
58
63
/// Create a TaffyTree instance
59
64
#[ no_mangle]
60
65
#[ allow( clippy:: missing_safety_doc) ]
@@ -71,6 +76,43 @@ pub unsafe extern "C" fn TaffyTree_Free(raw_tree: TaffyTreeOwnedRef) -> TaffyRet
71
76
TaffyReturnCode :: Ok
72
77
}
73
78
79
+ // -------------------------------------------------
80
+ // Compute and Print
81
+ // -------------------------------------------------
82
+
83
+ /// Create a new Node in the TaffyTree. Returns a NodeId handle to the node.
84
+ #[ no_mangle]
85
+ #[ allow( clippy:: missing_safety_doc) ]
86
+ pub unsafe extern "C" fn TaffyTree_ComputeLayout (
87
+ raw_tree : TaffyTreeMutRef ,
88
+ node_id : TaffyNodeId ,
89
+ available_width : f32 ,
90
+ available_height : f32 ,
91
+ ) -> TaffyReturnCode {
92
+ with_tree_mut ! ( raw_tree, tree, {
93
+ let available_space = core:: Size {
94
+ width: available_space_from_f32( available_width) ,
95
+ height: available_space_from_f32( available_height) ,
96
+ } ;
97
+ try_or!( InvalidNodeId , tree. inner. compute_layout( node_id. into( ) , available_space) ) ;
98
+ TaffyReturnCode :: Ok
99
+ } )
100
+ }
101
+
102
+ /// Create a new Node in the TaffyTree. Returns a NodeId handle to the node.
103
+ #[ no_mangle]
104
+ #[ allow( clippy:: missing_safety_doc) ]
105
+ pub unsafe extern "C" fn TaffyTree_PrintTree ( raw_tree : TaffyTreeConstRef , node_id : TaffyNodeId ) -> TaffyReturnCode {
106
+ with_tree ! ( raw_tree, tree, {
107
+ taffy:: util:: print_tree( & tree. inner, node_id. into( ) ) ;
108
+ TaffyReturnCode :: Ok
109
+ } )
110
+ }
111
+
112
+ // -------------------------------------------------
113
+ // Tree manipulation
114
+ // -------------------------------------------------
115
+
74
116
/// Create a new Node in the TaffyTree. Returns a NodeId handle to the node.
75
117
#[ no_mangle]
76
118
#[ allow( clippy:: missing_safety_doc) ]
@@ -106,10 +148,14 @@ pub unsafe extern "C" fn TaffyTree_AppendChild(
106
148
} )
107
149
}
108
150
151
+ // -------------------------------------------------
152
+ // Style and Layout access
153
+ // -------------------------------------------------
154
+
109
155
/// Create a new Node in the TaffyTree. Returns a NodeId handle to the node.
110
156
#[ no_mangle]
111
157
#[ allow( clippy:: missing_safety_doc) ]
112
- pub unsafe extern "C" fn TaffyTree_GetStyleMutRef (
158
+ pub unsafe extern "C" fn TaffyTree_GetStyleMut (
113
159
raw_tree : TaffyTreeMutRef ,
114
160
node_id : TaffyNodeId ,
115
161
) -> TaffyResult < TaffyStyleMutRef > {
@@ -122,28 +168,17 @@ pub unsafe extern "C" fn TaffyTree_GetStyleMutRef(
122
168
/// Create a new Node in the TaffyTree. Returns a NodeId handle to the node.
123
169
#[ no_mangle]
124
170
#[ allow( clippy:: missing_safety_doc) ]
125
- pub unsafe extern "C" fn TaffyTree_ComputeLayout (
126
- raw_tree : TaffyTreeMutRef ,
171
+ pub unsafe extern "C" fn TaffyTree_GetLayout (
172
+ raw_tree : TaffyTreeConstRef ,
127
173
node_id : TaffyNodeId ,
128
- available_width : f32 ,
129
- available_height : f32 ,
130
- ) -> TaffyReturnCode {
131
- with_tree_mut ! ( raw_tree, tree, {
132
- let available_space = core:: Size {
133
- width: available_space_from_f32( available_width) ,
134
- height: available_space_from_f32( available_height) ,
135
- } ;
136
- try_or!( InvalidNodeId , tree. inner. compute_layout( node_id. into( ) , available_space) ) ;
137
- TaffyReturnCode :: Ok
138
- } )
139
- }
140
-
141
- /// Create a new Node in the TaffyTree. Returns a NodeId handle to the node.
142
- #[ no_mangle]
143
- #[ allow( clippy:: missing_safety_doc) ]
144
- pub unsafe extern "C" fn TaffyTree_PrintTree ( raw_tree : TaffyTreeConstRef , node_id : TaffyNodeId ) -> TaffyReturnCode {
174
+ ) -> TaffyResult < TaffyLayout > {
145
175
with_tree ! ( raw_tree, tree, {
146
- taffy:: util:: print_tree( & tree. inner, node_id. into( ) ) ;
147
- TaffyReturnCode :: Ok
176
+ let layout = try_or!( InvalidNodeId , tree. inner. layout( node_id. into( ) ) ) ;
177
+ ok!( TaffyLayout {
178
+ x: layout. location. x,
179
+ y: layout. location. y,
180
+ width: layout. size. width,
181
+ height: layout. size. height
182
+ } ) ;
148
183
} )
149
184
}
0 commit comments