Skip to content

Commit

Permalink
feat(macro): add layout macro
Browse files Browse the repository at this point in the history
  • Loading branch information
meloalright committed Nov 12, 2024
1 parent b4b23c4 commit faaa199
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 9 deletions.
2 changes: 2 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
mod safe;
pub mod macros;

use safe::ffi;
use cxx::UniquePtr;

Expand Down
18 changes: 18 additions & 0 deletions src/macros.rs
Original file line number Diff line number Diff line change
@@ -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)
};
}
18 changes: 9 additions & 9 deletions tests/taitank_flex_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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));
Expand Down Expand Up @@ -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));
Expand Down Expand Up @@ -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));
Expand Down Expand Up @@ -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));
Expand Down Expand Up @@ -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));
Expand Down Expand Up @@ -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));
Expand Down Expand Up @@ -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));
Expand Down Expand Up @@ -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));
Expand Down

0 comments on commit faaa199

Please sign in to comment.