diff --git a/src/lib.rs b/src/lib.rs index 81506ab..65a3fe2 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,4 +1,6 @@ mod safe; +pub mod macros; + use safe::ffi; use cxx::UniquePtr; diff --git a/src/macros.rs b/src/macros.rs new file mode 100644 index 0000000..616452a --- /dev/null +++ b/src/macros.rs @@ -0,0 +1,18 @@ +#[macro_export] +macro_rules! layout { + ($a:expr, $b:expr, $c:expr, $d:expr) => { + do_layout($a, $b, $c, $d) + }; + + ($a:expr, $b:expr, $c:expr) => { + do_layout($a, $b, $c, Direction::LTR) + }; + + ($a:expr, $b:expr) => { + do_layout($a, $b, std::f64::NAN, Direction::LTR) + }; + + ($a:expr) => { + do_layout($a, std::f64::NAN, std::f64::NAN, Direction::LTR) + }; +} \ No newline at end of file diff --git a/tests/taitank_flex_test.rs b/tests/taitank_flex_test.rs index fa9bb7c..5d4b7da 100644 --- a/tests/taitank_flex_test.rs +++ b/tests/taitank_flex_test.rs @@ -9,7 +9,7 @@ mod tests { set_width(&node, 100.0); set_height(&node, 100.0); set_direction(&node, Direction::LTR); - do_layout(&node, std::f64::NAN, std::f64::NAN, Direction::LTR); + layout!(&node); assert_eq!(get_left(&node), 0.0); assert_eq!(get_top(&node), 0.0); @@ -47,7 +47,7 @@ mod tests { assert_eq!(100.0, get_width(&root_child1)); assert_eq!(25.0, get_height(&root_child1)); - do_layout(&root, std::f64::NAN, std::f64::NAN, Direction::LTR); + layout!(&root); assert_eq!(0.0, get_left(&root)); assert_eq!(0.0, get_top(&root)); @@ -80,7 +80,7 @@ mod tests { let root_child1 = node_create(); set_flex_grow(&root_child1, 1.0); insert_child(&root, &root_child1, 1); - do_layout(&root, std::f64::NAN, std::f64::NAN, Direction::LTR); + layout!(&root); assert_eq!(0.0, get_left(&root)); assert_eq!(0.0, get_top(&root)); @@ -131,7 +131,7 @@ mod tests { set_flex_basis(&root_child1, 50.0); insert_child(&root, &root_child1, 1); - do_layout(&root, std::f64::NAN, std::f64::NAN, Direction::LTR); + layout!(&root); assert_eq!(0.0, get_left(&root)); assert_eq!(0.0, get_top(&root)); @@ -182,7 +182,7 @@ mod tests { set_flex_basis(&root_child1, 50.0); insert_child(&root, &root_child1, 1); - do_layout(&root, std::f64::NAN, std::f64::NAN, Direction::LTR); + layout!(&root); assert_eq!(0.0, get_left(&root)); assert_eq!(0.0, get_top(&root)); @@ -239,7 +239,7 @@ mod tests { set_height(&root_child2, 50.0); insert_child(&root, &root_child2, 2); - do_layout(&root, std::f64::NAN, std::f64::NAN, Direction::LTR); + layout!(&root); assert_eq!(0.0, get_left(&root)); assert_eq!(0.0, get_top(&root)); @@ -307,7 +307,7 @@ mod tests { set_height(&root_child2, 10.0); insert_child(&root, &root_child2, 2); - do_layout(&root, std::f64::NAN, std::f64::NAN, Direction::LTR); + layout!(&root); assert_eq!(0.0, get_left(&root)); assert_eq!(0.0, get_top(&root)); @@ -366,7 +366,7 @@ mod tests { set_flex_shrink(&root_child0_child0, 1.0); insert_child(&root_child0, &root_child0_child0, 0); - do_layout(&root, std::f64::NAN, std::f64::NAN, Direction::LTR); + layout!(&root); assert_eq!(0.0, get_left(&root)); assert_eq!(0.0, get_top(&root)); @@ -420,7 +420,7 @@ mod tests { set_flex_grow(&root_child2, 0.4); insert_child(&root, &root_child2, 2); - do_layout(&root, std::f64::NAN, std::f64::NAN, Direction::LTR); + layout!(&root); assert_eq!(0.0, get_left(&root)); assert_eq!(0.0, get_top(&root));