Skip to content

Commit 4e122b1

Browse files
committed
Use TaffyStyleConstRef and TaffyStyleMutRef types
1 parent 52c2072 commit 4e122b1

File tree

3 files changed

+116
-102
lines changed

3 files changed

+116
-102
lines changed

ctaffy/src/lib.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,19 @@ mod style;
33
mod style_enums;
44
mod value;
55

6+
pub struct Taffy;
7+
pub type TaffyMutRef = *mut Taffy;
8+
pub type TaffyConstRef = *const Taffy;
9+
10+
pub struct TaffyNodeId;
11+
12+
pub struct TaffyStyle;
13+
pub type TaffyStyleMutRef = *mut TaffyStyle;
14+
pub type TaffyStyleConstRef = *const TaffyStyle;
15+
16+
pub struct TaffyLayout;
17+
pub type TaffyLayoutConstRef = *const TaffyLayout;
18+
619
pub use error::*;
720
pub use style::*;
821
pub use style_enums::*;

ctaffy/src/style.rs

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,6 @@ use super::{
88
use std::ffi::c_void;
99
use taffy::prelude as core;
1010

11-
pub struct TaffyStyle;
12-
pub type TaffyStyleRef = *mut TaffyStyle;
13-
1411
/// Return [`ReturnCode::NullStylePointer`] if the passed pointer is null
1512
macro_rules! assert_style_pointer_is_non_null {
1613
($raw_style_ptr:expr) => {{
@@ -72,7 +69,7 @@ macro_rules! try_from_raw {
7269
macro_rules! enum_prop_getter {
7370
($func_name:ident; $($props:ident).+) => {
7471
#[no_mangle]
75-
pub unsafe extern "C" fn $func_name(raw_style: *const TaffyStyle) -> IntResult {
72+
pub unsafe extern "C" fn $func_name(raw_style: TaffyStyleConstRef) -> IntResult {
7673
get_style!(raw_style, style, style.$($props).* as i32)
7774
}
7875
};
@@ -81,7 +78,7 @@ macro_rules! enum_prop_getter {
8178
macro_rules! option_enum_prop_getter {
8279
($func_name:ident; $($props:ident).+) => {
8380
#[no_mangle]
84-
pub unsafe extern "C" fn $func_name(raw_style: *const TaffyStyle) -> IntResult {
81+
pub unsafe extern "C" fn $func_name(raw_style: TaffyStyleConstRef) -> IntResult {
8582
get_style!(raw_style, style, style.$($props).*.map(|v| v as i32).unwrap_or(0))
8683
}
8784
};
@@ -91,7 +88,7 @@ macro_rules! option_enum_prop_getter {
9188
macro_rules! enum_prop_setter {
9289
($func_name:ident; $($props:ident).+; $enum:ident) => {
9390
#[no_mangle]
94-
pub unsafe extern "C" fn $func_name(raw_style: *mut TaffyStyle, value: $enum) -> ReturnCode {
91+
pub unsafe extern "C" fn $func_name(raw_style: TaffyStyleMutRef, value: $enum) -> ReturnCode {
9592
with_style_mut!(raw_style, style, style.$($props).* = value.into())
9693
}
9794
};
@@ -141,7 +138,7 @@ enum_prop_setter!(TaffyStyle_SetGridAutoFlow; grid_auto_flow; TaffyGridAutoFlow)
141138
macro_rules! style_value_prop_getter {
142139
($func_name:ident; $($props:ident).+) => {
143140
#[no_mangle]
144-
pub unsafe extern "C" fn $func_name(raw_style: *const TaffyStyle) -> StyleValueResult {
141+
pub unsafe extern "C" fn $func_name(raw_style: TaffyStyleConstRef) -> StyleValueResult {
145142
get_style!(raw_style, style, style.$($props).*)
146143
}
147144
};
@@ -151,7 +148,7 @@ macro_rules! style_value_prop_getter {
151148
macro_rules! style_value_prop_setter {
152149
($func_name:ident; $($props:ident).+) => {
153150
#[no_mangle]
154-
pub unsafe extern "C" fn $func_name(raw_style: *mut TaffyStyle, value: f32, unit: StyleValueUnit) -> ReturnCode {
151+
pub unsafe extern "C" fn $func_name(raw_style: TaffyStyleMutRef, value: f32, unit: StyleValueUnit) -> ReturnCode {
155152
with_style_mut!(raw_style, style, style.$($props).* = try_from_raw!(unit, value))
156153
}
157154
};
@@ -223,11 +220,11 @@ style_value_prop_setter!(TaffyStyle_SetRowGap; gap.height);
223220

224221
// Aspect ratio
225222
#[no_mangle]
226-
pub unsafe extern "C" fn TaffyStyle_GetAspectRatio(raw_style: *const TaffyStyle) -> FloatResult {
223+
pub unsafe extern "C" fn TaffyStyle_GetAspectRatio(raw_style: TaffyStyleConstRef) -> FloatResult {
227224
get_style!(raw_style, style, style.aspect_ratio.unwrap_or(f32::NAN))
228225
}
229226
#[no_mangle]
230-
pub unsafe extern "C" fn TaffyStyle_SetAspectRatio(raw_style: *mut TaffyStyle, value: f32) -> ReturnCode {
227+
pub unsafe extern "C" fn TaffyStyle_SetAspectRatio(raw_style: TaffyStyleMutRef, value: f32) -> ReturnCode {
231228
with_style_mut!(raw_style, style, {
232229
if value.is_finite() && value > 0.0 {
233230
style.aspect_ratio = Some(value)
@@ -241,7 +238,7 @@ pub unsafe extern "C" fn TaffyStyle_SetAspectRatio(raw_style: *mut TaffyStyle, v
241238
macro_rules! float_prop_getter {
242239
($func_name:ident; $($props:ident).+) => {
243240
#[no_mangle]
244-
pub unsafe extern "C" fn $func_name(raw_style: *const TaffyStyle) -> FloatResult {
241+
pub unsafe extern "C" fn $func_name(raw_style: TaffyStyleConstRef) -> FloatResult {
245242
get_style!(raw_style, style, style.$($props).*)
246243
}
247244
};
@@ -251,7 +248,7 @@ macro_rules! float_prop_getter {
251248
macro_rules! float_prop_setter {
252249
($func_name:ident; $($props:ident).+) => {
253250
#[no_mangle]
254-
pub unsafe extern "C" fn $func_name(raw_style: *mut TaffyStyle, value: f32) -> ReturnCode {
251+
pub unsafe extern "C" fn $func_name(raw_style: TaffyStyleMutRef, value: f32) -> ReturnCode {
255252
with_style_mut!(raw_style, style, style.$($props).* = value)
256253
}
257254
};
@@ -272,7 +269,7 @@ float_prop_setter!(TaffyStyle_SetFlexShrink; flex_shrink);
272269
/// Function to set all the value of margin
273270
#[no_mangle]
274271
pub unsafe extern "C" fn TaffyStyle_SetMargin(
275-
raw_style: *mut TaffyStyle,
272+
raw_style: TaffyStyleMutRef,
276273
edge: TaffyEdge,
277274
value: StyleValue,
278275
) -> ReturnCode {
@@ -305,12 +302,12 @@ pub unsafe extern "C" fn TaffyStyle_SetMargin(
305302

306303
/// Get grid item's column placement
307304
#[no_mangle]
308-
pub unsafe extern "C" fn TaffyStyleGetGridColumn(raw_style: *mut TaffyStyle) -> GridPlacementResult {
305+
pub unsafe extern "C" fn TaffyStyleGetGridColumn(raw_style: TaffyStyleMutRef) -> GridPlacementResult {
309306
get_style!(raw_style, style, style.grid_column)
310307
}
311308

312309
/// Set grid item's column placement
313310
#[no_mangle]
314-
pub unsafe extern "C" fn TaffyStyleSetGridColumn(raw_style: *mut TaffyStyle, placement: GridPlacement) -> ReturnCode {
311+
pub unsafe extern "C" fn TaffyStyleSetGridColumn(raw_style: TaffyStyleMutRef, placement: GridPlacement) -> ReturnCode {
315312
with_style_mut!(raw_style, style, style.grid_column = placement.into())
316313
}

0 commit comments

Comments
 (0)