extern crate ordered_float;
extern crate yoga;
mod test_utils;
use yoga::*;
#[test]
fn test_column_gap_flexible() {
let mut config = Config::new();
let mut root = Node::new_with_config(&mut config);
root.set_flex_direction(FlexDirection::Row);
root.set_position_type(PositionType::Absolute);
root.set_width(StyleUnit::Point(80_f32.into()));
root.set_height(StyleUnit::Point(100_f32.into()));
root.set_gap(Gutter::Column, StyleUnit::Point(10_f32.into()));
root.set_gap(Gutter::Row, StyleUnit::Point(20_f32.into()));
let mut root_child0 = Node::new_with_config(&mut config);
root_child0.set_flex_grow(1_f32);
root_child0.set_flex_shrink(1_f32);
root_child0.set_flex_basis(StyleUnit::Percent(0_f32.into()));
root.insert_child(&mut root_child0, 0);
let mut root_child1 = Node::new_with_config(&mut config);
root_child1.set_flex_grow(1_f32);
root_child1.set_flex_shrink(1_f32);
root_child1.set_flex_basis(StyleUnit::Percent(0_f32.into()));
root.insert_child(&mut root_child1, 1);
let mut root_child2 = Node::new_with_config(&mut config);
root_child2.set_flex_grow(1_f32);
root_child2.set_flex_shrink(1_f32);
root_child2.set_flex_basis(StyleUnit::Percent(0_f32.into()));
root.insert_child(&mut root_child2, 2);
root.calculate_layout(Undefined, Undefined, Direction::LTR);
assert_eq!(0_f32, root.get_layout_left());
assert_eq!(0_f32, root.get_layout_top());
assert_eq!(80_f32, root.get_layout_width());
assert_eq!(100_f32, root.get_layout_height());
assert_eq!(0_f32, root_child0.get_layout_left());
assert_eq!(0_f32, root_child0.get_layout_top());
assert_eq!(20_f32, root_child0.get_layout_width());
assert_eq!(100_f32, root_child0.get_layout_height());
assert_eq!(30_f32, root_child1.get_layout_left());
assert_eq!(0_f32, root_child1.get_layout_top());
assert_eq!(20_f32, root_child1.get_layout_width());
assert_eq!(100_f32, root_child1.get_layout_height());
assert_eq!(60_f32, root_child2.get_layout_left());
assert_eq!(0_f32, root_child2.get_layout_top());
assert_eq!(20_f32, root_child2.get_layout_width());
assert_eq!(100_f32, root_child2.get_layout_height());
root.calculate_layout(Undefined, Undefined, Direction::RTL);
assert_eq!(0_f32, root.get_layout_left());
assert_eq!(0_f32, root.get_layout_top());
assert_eq!(80_f32, root.get_layout_width());
assert_eq!(100_f32, root.get_layout_height());
assert_eq!(60_f32, root_child0.get_layout_left());
assert_eq!(0_f32, root_child0.get_layout_top());
assert_eq!(20_f32, root_child0.get_layout_width());
assert_eq!(100_f32, root_child0.get_layout_height());
assert_eq!(30_f32, root_child1.get_layout_left());
assert_eq!(0_f32, root_child1.get_layout_top());
assert_eq!(20_f32, root_child1.get_layout_width());
assert_eq!(100_f32, root_child1.get_layout_height());
assert_eq!(0_f32, root_child2.get_layout_left());
assert_eq!(0_f32, root_child2.get_layout_top());
assert_eq!(20_f32, root_child2.get_layout_width());
assert_eq!(100_f32, root_child2.get_layout_height());
}
#[test]
fn test_column_gap_inflexible() {
let mut config = Config::new();
let mut root = Node::new_with_config(&mut config);
root.set_flex_direction(FlexDirection::Row);
root.set_position_type(PositionType::Absolute);
root.set_width(StyleUnit::Point(80_f32.into()));
root.set_height(StyleUnit::Point(100_f32.into()));
root.set_gap(Gutter::Column, StyleUnit::Point(10_f32.into()));
let mut root_child0 = Node::new_with_config(&mut config);
root_child0.set_width(StyleUnit::Point(20_f32.into()));
root.insert_child(&mut root_child0, 0);
let mut root_child1 = Node::new_with_config(&mut config);
root_child1.set_width(StyleUnit::Point(20_f32.into()));
root.insert_child(&mut root_child1, 1);
let mut root_child2 = Node::new_with_config(&mut config);
root_child2.set_width(StyleUnit::Point(20_f32.into()));
root.insert_child(&mut root_child2, 2);
root.calculate_layout(Undefined, Undefined, Direction::LTR);
assert_eq!(0_f32, root.get_layout_left());
assert_eq!(0_f32, root.get_layout_top());
assert_eq!(80_f32, root.get_layout_width());
assert_eq!(100_f32, root.get_layout_height());
assert_eq!(0_f32, root_child0.get_layout_left());
assert_eq!(0_f32, root_child0.get_layout_top());
assert_eq!(20_f32, root_child0.get_layout_width());
assert_eq!(100_f32, root_child0.get_layout_height());
assert_eq!(30_f32, root_child1.get_layout_left());
assert_eq!(0_f32, root_child1.get_layout_top());
assert_eq!(20_f32, root_child1.get_layout_width());
assert_eq!(100_f32, root_child1.get_layout_height());
assert_eq!(60_f32, root_child2.get_layout_left());
assert_eq!(0_f32, root_child2.get_layout_top());
assert_eq!(20_f32, root_child2.get_layout_width());
assert_eq!(100_f32, root_child2.get_layout_height());
root.calculate_layout(Undefined, Undefined, Direction::RTL);
assert_eq!(0_f32, root.get_layout_left());
assert_eq!(0_f32, root.get_layout_top());
assert_eq!(80_f32, root.get_layout_width());
assert_eq!(100_f32, root.get_layout_height());
assert_eq!(60_f32, root_child0.get_layout_left());
assert_eq!(0_f32, root_child0.get_layout_top());
assert_eq!(20_f32, root_child0.get_layout_width());
assert_eq!(100_f32, root_child0.get_layout_height());
assert_eq!(30_f32, root_child1.get_layout_left());
assert_eq!(0_f32, root_child1.get_layout_top());
assert_eq!(20_f32, root_child1.get_layout_width());
assert_eq!(100_f32, root_child1.get_layout_height());
assert_eq!(0_f32, root_child2.get_layout_left());
assert_eq!(0_f32, root_child2.get_layout_top());
assert_eq!(20_f32, root_child2.get_layout_width());
assert_eq!(100_f32, root_child2.get_layout_height());
}
#[test]
fn test_column_gap_mixed_flexible() {
let mut config = Config::new();
let mut root = Node::new_with_config(&mut config);
root.set_flex_direction(FlexDirection::Row);
root.set_position_type(PositionType::Absolute);
root.set_width(StyleUnit::Point(80_f32.into()));
root.set_height(StyleUnit::Point(100_f32.into()));
root.set_gap(Gutter::Column, StyleUnit::Point(10_f32.into()));
let mut root_child0 = Node::new_with_config(&mut config);
root_child0.set_width(StyleUnit::Point(20_f32.into()));
root.insert_child(&mut root_child0, 0);
let mut root_child1 = Node::new_with_config(&mut config);
root_child1.set_flex_grow(1_f32);
root_child1.set_flex_shrink(1_f32);
root_child1.set_flex_basis(StyleUnit::Percent(0_f32.into()));
root.insert_child(&mut root_child1, 1);
let mut root_child2 = Node::new_with_config(&mut config);
root_child2.set_width(StyleUnit::Point(20_f32.into()));
root.insert_child(&mut root_child2, 2);
root.calculate_layout(Undefined, Undefined, Direction::LTR);
assert_eq!(0_f32, root.get_layout_left());
assert_eq!(0_f32, root.get_layout_top());
assert_eq!(80_f32, root.get_layout_width());
assert_eq!(100_f32, root.get_layout_height());
assert_eq!(0_f32, root_child0.get_layout_left());
assert_eq!(0_f32, root_child0.get_layout_top());
assert_eq!(20_f32, root_child0.get_layout_width());
assert_eq!(100_f32, root_child0.get_layout_height());
assert_eq!(30_f32, root_child1.get_layout_left());
assert_eq!(0_f32, root_child1.get_layout_top());
assert_eq!(20_f32, root_child1.get_layout_width());
assert_eq!(100_f32, root_child1.get_layout_height());
assert_eq!(60_f32, root_child2.get_layout_left());
assert_eq!(0_f32, root_child2.get_layout_top());
assert_eq!(20_f32, root_child2.get_layout_width());
assert_eq!(100_f32, root_child2.get_layout_height());
root.calculate_layout(Undefined, Undefined, Direction::RTL);
assert_eq!(0_f32, root.get_layout_left());
assert_eq!(0_f32, root.get_layout_top());
assert_eq!(80_f32, root.get_layout_width());
assert_eq!(100_f32, root.get_layout_height());
assert_eq!(60_f32, root_child0.get_layout_left());
assert_eq!(0_f32, root_child0.get_layout_top());
assert_eq!(20_f32, root_child0.get_layout_width());
assert_eq!(100_f32, root_child0.get_layout_height());
assert_eq!(30_f32, root_child1.get_layout_left());
assert_eq!(0_f32, root_child1.get_layout_top());
assert_eq!(20_f32, root_child1.get_layout_width());
assert_eq!(100_f32, root_child1.get_layout_height());
assert_eq!(0_f32, root_child2.get_layout_left());
assert_eq!(0_f32, root_child2.get_layout_top());
assert_eq!(20_f32, root_child2.get_layout_width());
assert_eq!(100_f32, root_child2.get_layout_height());
}
#[test]
fn test_column_gap_child_margins() {
let mut config = Config::new();
let mut root = Node::new_with_config(&mut config);
root.set_flex_direction(FlexDirection::Row);
root.set_position_type(PositionType::Absolute);
root.set_width(StyleUnit::Point(80_f32.into()));
root.set_height(StyleUnit::Point(100_f32.into()));
root.set_gap(Gutter::Column, StyleUnit::Point(10_f32.into()));
let mut root_child0 = Node::new_with_config(&mut config);
root_child0.set_flex_grow(1_f32);
root_child0.set_flex_shrink(1_f32);
root_child0.set_flex_basis(StyleUnit::Percent(0_f32.into()));
root_child0.set_margin(Edge::Left, StyleUnit::Point(2_f32.into()));
root_child0.set_margin(Edge::Right, StyleUnit::Point(2_f32.into()));
root.insert_child(&mut root_child0, 0);
let mut root_child1 = Node::new_with_config(&mut config);
root_child1.set_flex_grow(1_f32);
root_child1.set_flex_shrink(1_f32);
root_child1.set_flex_basis(StyleUnit::Percent(0_f32.into()));
root_child1.set_margin(Edge::Left, StyleUnit::Point(10_f32.into()));
root_child1.set_margin(Edge::Right, StyleUnit::Point(10_f32.into()));
root.insert_child(&mut root_child1, 1);
let mut root_child2 = Node::new_with_config(&mut config);
root_child2.set_flex_grow(1_f32);
root_child2.set_flex_shrink(1_f32);
root_child2.set_flex_basis(StyleUnit::Percent(0_f32.into()));
root_child2.set_margin(Edge::Left, StyleUnit::Point(15_f32.into()));
root_child2.set_margin(Edge::Right, StyleUnit::Point(15_f32.into()));
root.insert_child(&mut root_child2, 2);
root.calculate_layout(Undefined, Undefined, Direction::LTR);
assert_eq!(0_f32, root.get_layout_left());
assert_eq!(0_f32, root.get_layout_top());
assert_eq!(80_f32, root.get_layout_width());
assert_eq!(100_f32, root.get_layout_height());
assert_eq!(2_f32, root_child0.get_layout_left());
assert_eq!(0_f32, root_child0.get_layout_top());
assert_eq!(2_f32, root_child0.get_layout_width());
assert_eq!(100_f32, root_child0.get_layout_height());
assert_eq!(26_f32, root_child1.get_layout_left());
assert_eq!(0_f32, root_child1.get_layout_top());
assert_eq!(2_f32, root_child1.get_layout_width());
assert_eq!(100_f32, root_child1.get_layout_height());
assert_eq!(63_f32, root_child2.get_layout_left());
assert_eq!(0_f32, root_child2.get_layout_top());
assert_eq!(2_f32, root_child2.get_layout_width());
assert_eq!(100_f32, root_child2.get_layout_height());
root.calculate_layout(Undefined, Undefined, Direction::RTL);
assert_eq!(0_f32, root.get_layout_left());
assert_eq!(0_f32, root.get_layout_top());
assert_eq!(80_f32, root.get_layout_width());
assert_eq!(100_f32, root.get_layout_height());
assert_eq!(76_f32, root_child0.get_layout_left());
assert_eq!(0_f32, root_child0.get_layout_top());
assert_eq!(2_f32, root_child0.get_layout_width());
assert_eq!(100_f32, root_child0.get_layout_height());
assert_eq!(52_f32, root_child1.get_layout_left());
assert_eq!(0_f32, root_child1.get_layout_top());
assert_eq!(2_f32, root_child1.get_layout_width());
assert_eq!(100_f32, root_child1.get_layout_height());
assert_eq!(15_f32, root_child2.get_layout_left());
assert_eq!(0_f32, root_child2.get_layout_top());
assert_eq!(2_f32, root_child2.get_layout_width());
assert_eq!(100_f32, root_child2.get_layout_height());
}
#[test]
fn test_column_row_gap_wrapping() {
let mut config = Config::new();
let mut root = Node::new_with_config(&mut config);
root.set_flex_direction(FlexDirection::Row);
root.set_position_type(PositionType::Absolute);
root.set_flex_wrap(Wrap::Wrap);
root.set_width(StyleUnit::Point(80_f32.into()));
root.set_gap(Gutter::Column, StyleUnit::Point(10_f32.into()));
root.set_gap(Gutter::Row, StyleUnit::Point(20_f32.into()));
let mut root_child0 = Node::new_with_config(&mut config);
root_child0.set_width(StyleUnit::Point(20_f32.into()));
root_child0.set_height(StyleUnit::Point(20_f32.into()));
root.insert_child(&mut root_child0, 0);
let mut root_child1 = Node::new_with_config(&mut config);
root_child1.set_width(StyleUnit::Point(20_f32.into()));
root_child1.set_height(StyleUnit::Point(20_f32.into()));
root.insert_child(&mut root_child1, 1);
let mut root_child2 = Node::new_with_config(&mut config);
root_child2.set_width(StyleUnit::Point(20_f32.into()));
root_child2.set_height(StyleUnit::Point(20_f32.into()));
root.insert_child(&mut root_child2, 2);
let mut root_child3 = Node::new_with_config(&mut config);
root_child3.set_width(StyleUnit::Point(20_f32.into()));
root_child3.set_height(StyleUnit::Point(20_f32.into()));
root.insert_child(&mut root_child3, 3);
let mut root_child4 = Node::new_with_config(&mut config);
root_child4.set_width(StyleUnit::Point(20_f32.into()));
root_child4.set_height(StyleUnit::Point(20_f32.into()));
root.insert_child(&mut root_child4, 4);
let mut root_child5 = Node::new_with_config(&mut config);
root_child5.set_width(StyleUnit::Point(20_f32.into()));
root_child5.set_height(StyleUnit::Point(20_f32.into()));
root.insert_child(&mut root_child5, 5);
let mut root_child6 = Node::new_with_config(&mut config);
root_child6.set_width(StyleUnit::Point(20_f32.into()));
root_child6.set_height(StyleUnit::Point(20_f32.into()));
root.insert_child(&mut root_child6, 6);
let mut root_child7 = Node::new_with_config(&mut config);
root_child7.set_width(StyleUnit::Point(20_f32.into()));
root_child7.set_height(StyleUnit::Point(20_f32.into()));
root.insert_child(&mut root_child7, 7);
let mut root_child8 = Node::new_with_config(&mut config);
root_child8.set_width(StyleUnit::Point(20_f32.into()));
root_child8.set_height(StyleUnit::Point(20_f32.into()));
root.insert_child(&mut root_child8, 8);
root.calculate_layout(Undefined, Undefined, Direction::LTR);
assert_eq!(0_f32, root.get_layout_left());
assert_eq!(0_f32, root.get_layout_top());
assert_eq!(80_f32, root.get_layout_width());
assert_eq!(100_f32, root.get_layout_height());
assert_eq!(0_f32, root_child0.get_layout_left());
assert_eq!(0_f32, root_child0.get_layout_top());
assert_eq!(20_f32, root_child0.get_layout_width());
assert_eq!(20_f32, root_child0.get_layout_height());
assert_eq!(30_f32, root_child1.get_layout_left());
assert_eq!(0_f32, root_child1.get_layout_top());
assert_eq!(20_f32, root_child1.get_layout_width());
assert_eq!(20_f32, root_child1.get_layout_height());
assert_eq!(60_f32, root_child2.get_layout_left());
assert_eq!(0_f32, root_child2.get_layout_top());
assert_eq!(20_f32, root_child2.get_layout_width());
assert_eq!(20_f32, root_child2.get_layout_height());
assert_eq!(0_f32, root_child3.get_layout_left());
assert_eq!(40_f32, root_child3.get_layout_top());
assert_eq!(20_f32, root_child3.get_layout_width());
assert_eq!(20_f32, root_child3.get_layout_height());
assert_eq!(30_f32, root_child4.get_layout_left());
assert_eq!(40_f32, root_child4.get_layout_top());
assert_eq!(20_f32, root_child4.get_layout_width());
assert_eq!(20_f32, root_child4.get_layout_height());
assert_eq!(60_f32, root_child5.get_layout_left());
assert_eq!(40_f32, root_child5.get_layout_top());
assert_eq!(20_f32, root_child5.get_layout_width());
assert_eq!(20_f32, root_child5.get_layout_height());
assert_eq!(0_f32, root_child6.get_layout_left());
assert_eq!(80_f32, root_child6.get_layout_top());
assert_eq!(20_f32, root_child6.get_layout_width());
assert_eq!(20_f32, root_child6.get_layout_height());
assert_eq!(30_f32, root_child7.get_layout_left());
assert_eq!(80_f32, root_child7.get_layout_top());
assert_eq!(20_f32, root_child7.get_layout_width());
assert_eq!(20_f32, root_child7.get_layout_height());
assert_eq!(60_f32, root_child8.get_layout_left());
assert_eq!(80_f32, root_child8.get_layout_top());
assert_eq!(20_f32, root_child8.get_layout_width());
assert_eq!(20_f32, root_child8.get_layout_height());
root.calculate_layout(Undefined, Undefined, Direction::RTL);
assert_eq!(0_f32, root.get_layout_left());
assert_eq!(0_f32, root.get_layout_top());
assert_eq!(80_f32, root.get_layout_width());
assert_eq!(100_f32, root.get_layout_height());
assert_eq!(60_f32, root_child0.get_layout_left());
assert_eq!(0_f32, root_child0.get_layout_top());
assert_eq!(20_f32, root_child0.get_layout_width());
assert_eq!(20_f32, root_child0.get_layout_height());
assert_eq!(30_f32, root_child1.get_layout_left());
assert_eq!(0_f32, root_child1.get_layout_top());
assert_eq!(20_f32, root_child1.get_layout_width());
assert_eq!(20_f32, root_child1.get_layout_height());
assert_eq!(0_f32, root_child2.get_layout_left());
assert_eq!(0_f32, root_child2.get_layout_top());
assert_eq!(20_f32, root_child2.get_layout_width());
assert_eq!(20_f32, root_child2.get_layout_height());
assert_eq!(60_f32, root_child3.get_layout_left());
assert_eq!(40_f32, root_child3.get_layout_top());
assert_eq!(20_f32, root_child3.get_layout_width());
assert_eq!(20_f32, root_child3.get_layout_height());
assert_eq!(30_f32, root_child4.get_layout_left());
assert_eq!(40_f32, root_child4.get_layout_top());
assert_eq!(20_f32, root_child4.get_layout_width());
assert_eq!(20_f32, root_child4.get_layout_height());
assert_eq!(0_f32, root_child5.get_layout_left());
assert_eq!(40_f32, root_child5.get_layout_top());
assert_eq!(20_f32, root_child5.get_layout_width());
assert_eq!(20_f32, root_child5.get_layout_height());
assert_eq!(60_f32, root_child6.get_layout_left());
assert_eq!(80_f32, root_child6.get_layout_top());
assert_eq!(20_f32, root_child6.get_layout_width());
assert_eq!(20_f32, root_child6.get_layout_height());
assert_eq!(30_f32, root_child7.get_layout_left());
assert_eq!(80_f32, root_child7.get_layout_top());
assert_eq!(20_f32, root_child7.get_layout_width());
assert_eq!(20_f32, root_child7.get_layout_height());
assert_eq!(0_f32, root_child8.get_layout_left());
assert_eq!(80_f32, root_child8.get_layout_top());
assert_eq!(20_f32, root_child8.get_layout_width());
assert_eq!(20_f32, root_child8.get_layout_height());
}
#[test]
fn test_column_gap_start_index() {
let mut config = Config::new();
let mut root = Node::new_with_config(&mut config);
root.set_flex_direction(FlexDirection::Row);
root.set_position_type(PositionType::Absolute);
root.set_flex_wrap(Wrap::Wrap);
root.set_width(StyleUnit::Point(80_f32.into()));
root.set_gap(Gutter::Column, StyleUnit::Point(10_f32.into()));
root.set_gap(Gutter::Row, StyleUnit::Point(20_f32.into()));
let mut root_child0 = Node::new_with_config(&mut config);
root_child0.set_position_type(PositionType::Absolute);
root_child0.set_width(StyleUnit::Point(20_f32.into()));
root_child0.set_height(StyleUnit::Point(20_f32.into()));
root.insert_child(&mut root_child0, 0);
let mut root_child1 = Node::new_with_config(&mut config);
root_child1.set_width(StyleUnit::Point(20_f32.into()));
root_child1.set_height(StyleUnit::Point(20_f32.into()));
root.insert_child(&mut root_child1, 1);
let mut root_child2 = Node::new_with_config(&mut config);
root_child2.set_width(StyleUnit::Point(20_f32.into()));
root_child2.set_height(StyleUnit::Point(20_f32.into()));
root.insert_child(&mut root_child2, 2);
let mut root_child3 = Node::new_with_config(&mut config);
root_child3.set_width(StyleUnit::Point(20_f32.into()));
root_child3.set_height(StyleUnit::Point(20_f32.into()));
root.insert_child(&mut root_child3, 3);
root.calculate_layout(Undefined, Undefined, Direction::LTR);
assert_eq!(0_f32, root.get_layout_left());
assert_eq!(0_f32, root.get_layout_top());
assert_eq!(80_f32, root.get_layout_width());
assert_eq!(20_f32, root.get_layout_height());
assert_eq!(0_f32, root_child0.get_layout_left());
assert_eq!(0_f32, root_child0.get_layout_top());
assert_eq!(20_f32, root_child0.get_layout_width());
assert_eq!(20_f32, root_child0.get_layout_height());
assert_eq!(0_f32, root_child1.get_layout_left());
assert_eq!(0_f32, root_child1.get_layout_top());
assert_eq!(20_f32, root_child1.get_layout_width());
assert_eq!(20_f32, root_child1.get_layout_height());
assert_eq!(30_f32, root_child2.get_layout_left());
assert_eq!(0_f32, root_child2.get_layout_top());
assert_eq!(20_f32, root_child2.get_layout_width());
assert_eq!(20_f32, root_child2.get_layout_height());
assert_eq!(60_f32, root_child3.get_layout_left());
assert_eq!(0_f32, root_child3.get_layout_top());
assert_eq!(20_f32, root_child3.get_layout_width());
assert_eq!(20_f32, root_child3.get_layout_height());
root.calculate_layout(Undefined, Undefined, Direction::RTL);
assert_eq!(0_f32, root.get_layout_left());
assert_eq!(0_f32, root.get_layout_top());
assert_eq!(80_f32, root.get_layout_width());
assert_eq!(20_f32, root.get_layout_height());
assert_eq!(60_f32, root_child0.get_layout_left());
assert_eq!(0_f32, root_child0.get_layout_top());
assert_eq!(20_f32, root_child0.get_layout_width());
assert_eq!(20_f32, root_child0.get_layout_height());
assert_eq!(60_f32, root_child1.get_layout_left());
assert_eq!(0_f32, root_child1.get_layout_top());
assert_eq!(20_f32, root_child1.get_layout_width());
assert_eq!(20_f32, root_child1.get_layout_height());
assert_eq!(30_f32, root_child2.get_layout_left());
assert_eq!(0_f32, root_child2.get_layout_top());
assert_eq!(20_f32, root_child2.get_layout_width());
assert_eq!(20_f32, root_child2.get_layout_height());
assert_eq!(0_f32, root_child3.get_layout_left());
assert_eq!(0_f32, root_child3.get_layout_top());
assert_eq!(20_f32, root_child3.get_layout_width());
assert_eq!(20_f32, root_child3.get_layout_height());
}
#[test]
fn test_column_gap_justify_flex_start() {
let mut config = Config::new();
let mut root = Node::new_with_config(&mut config);
root.set_flex_direction(FlexDirection::Row);
root.set_position_type(PositionType::Absolute);
root.set_width(StyleUnit::Point(100_f32.into()));
root.set_height(StyleUnit::Point(100_f32.into()));
root.set_gap(Gutter::Column, StyleUnit::Point(10_f32.into()));
let mut root_child0 = Node::new_with_config(&mut config);
root_child0.set_width(StyleUnit::Point(20_f32.into()));
root.insert_child(&mut root_child0, 0);
let mut root_child1 = Node::new_with_config(&mut config);
root_child1.set_width(StyleUnit::Point(20_f32.into()));
root.insert_child(&mut root_child1, 1);
let mut root_child2 = Node::new_with_config(&mut config);
root_child2.set_width(StyleUnit::Point(20_f32.into()));
root.insert_child(&mut root_child2, 2);
root.calculate_layout(Undefined, Undefined, Direction::LTR);
assert_eq!(0_f32, root.get_layout_left());
assert_eq!(0_f32, root.get_layout_top());
assert_eq!(100_f32, root.get_layout_width());
assert_eq!(100_f32, root.get_layout_height());
assert_eq!(0_f32, root_child0.get_layout_left());
assert_eq!(0_f32, root_child0.get_layout_top());
assert_eq!(20_f32, root_child0.get_layout_width());
assert_eq!(100_f32, root_child0.get_layout_height());
assert_eq!(30_f32, root_child1.get_layout_left());
assert_eq!(0_f32, root_child1.get_layout_top());
assert_eq!(20_f32, root_child1.get_layout_width());
assert_eq!(100_f32, root_child1.get_layout_height());
assert_eq!(60_f32, root_child2.get_layout_left());
assert_eq!(0_f32, root_child2.get_layout_top());
assert_eq!(20_f32, root_child2.get_layout_width());
assert_eq!(100_f32, root_child2.get_layout_height());
root.calculate_layout(Undefined, Undefined, Direction::RTL);
assert_eq!(0_f32, root.get_layout_left());
assert_eq!(0_f32, root.get_layout_top());
assert_eq!(100_f32, root.get_layout_width());
assert_eq!(100_f32, root.get_layout_height());
assert_eq!(80_f32, root_child0.get_layout_left());
assert_eq!(0_f32, root_child0.get_layout_top());
assert_eq!(20_f32, root_child0.get_layout_width());
assert_eq!(100_f32, root_child0.get_layout_height());
assert_eq!(50_f32, root_child1.get_layout_left());
assert_eq!(0_f32, root_child1.get_layout_top());
assert_eq!(20_f32, root_child1.get_layout_width());
assert_eq!(100_f32, root_child1.get_layout_height());
assert_eq!(20_f32, root_child2.get_layout_left());
assert_eq!(0_f32, root_child2.get_layout_top());
assert_eq!(20_f32, root_child2.get_layout_width());
assert_eq!(100_f32, root_child2.get_layout_height());
}
#[test]
fn test_column_gap_justify_center() {
let mut config = Config::new();
let mut root = Node::new_with_config(&mut config);
root.set_flex_direction(FlexDirection::Row);
root.set_justify_content(Justify::Center);
root.set_position_type(PositionType::Absolute);
root.set_width(StyleUnit::Point(100_f32.into()));
root.set_height(StyleUnit::Point(100_f32.into()));
root.set_gap(Gutter::Column, StyleUnit::Point(10_f32.into()));
let mut root_child0 = Node::new_with_config(&mut config);
root_child0.set_width(StyleUnit::Point(20_f32.into()));
root.insert_child(&mut root_child0, 0);
let mut root_child1 = Node::new_with_config(&mut config);
root_child1.set_width(StyleUnit::Point(20_f32.into()));
root.insert_child(&mut root_child1, 1);
let mut root_child2 = Node::new_with_config(&mut config);
root_child2.set_width(StyleUnit::Point(20_f32.into()));
root.insert_child(&mut root_child2, 2);
root.calculate_layout(Undefined, Undefined, Direction::LTR);
assert_eq!(0_f32, root.get_layout_left());
assert_eq!(0_f32, root.get_layout_top());
assert_eq!(100_f32, root.get_layout_width());
assert_eq!(100_f32, root.get_layout_height());
assert_eq!(10_f32, root_child0.get_layout_left());
assert_eq!(0_f32, root_child0.get_layout_top());
assert_eq!(20_f32, root_child0.get_layout_width());
assert_eq!(100_f32, root_child0.get_layout_height());
assert_eq!(40_f32, root_child1.get_layout_left());
assert_eq!(0_f32, root_child1.get_layout_top());
assert_eq!(20_f32, root_child1.get_layout_width());
assert_eq!(100_f32, root_child1.get_layout_height());
assert_eq!(70_f32, root_child2.get_layout_left());
assert_eq!(0_f32, root_child2.get_layout_top());
assert_eq!(20_f32, root_child2.get_layout_width());
assert_eq!(100_f32, root_child2.get_layout_height());
root.calculate_layout(Undefined, Undefined, Direction::RTL);
assert_eq!(0_f32, root.get_layout_left());
assert_eq!(0_f32, root.get_layout_top());
assert_eq!(100_f32, root.get_layout_width());
assert_eq!(100_f32, root.get_layout_height());
assert_eq!(70_f32, root_child0.get_layout_left());
assert_eq!(0_f32, root_child0.get_layout_top());
assert_eq!(20_f32, root_child0.get_layout_width());
assert_eq!(100_f32, root_child0.get_layout_height());
assert_eq!(40_f32, root_child1.get_layout_left());
assert_eq!(0_f32, root_child1.get_layout_top());
assert_eq!(20_f32, root_child1.get_layout_width());
assert_eq!(100_f32, root_child1.get_layout_height());
assert_eq!(10_f32, root_child2.get_layout_left());
assert_eq!(0_f32, root_child2.get_layout_top());
assert_eq!(20_f32, root_child2.get_layout_width());
assert_eq!(100_f32, root_child2.get_layout_height());
}
#[test]
fn test_column_gap_justify_flex_end() {
let mut config = Config::new();
let mut root = Node::new_with_config(&mut config);
root.set_flex_direction(FlexDirection::Row);
root.set_justify_content(Justify::FlexEnd);
root.set_position_type(PositionType::Absolute);
root.set_width(StyleUnit::Point(100_f32.into()));
root.set_height(StyleUnit::Point(100_f32.into()));
root.set_gap(Gutter::Column, StyleUnit::Point(10_f32.into()));
let mut root_child0 = Node::new_with_config(&mut config);
root_child0.set_width(StyleUnit::Point(20_f32.into()));
root.insert_child(&mut root_child0, 0);
let mut root_child1 = Node::new_with_config(&mut config);
root_child1.set_width(StyleUnit::Point(20_f32.into()));
root.insert_child(&mut root_child1, 1);
let mut root_child2 = Node::new_with_config(&mut config);
root_child2.set_width(StyleUnit::Point(20_f32.into()));
root.insert_child(&mut root_child2, 2);
root.calculate_layout(Undefined, Undefined, Direction::LTR);
assert_eq!(0_f32, root.get_layout_left());
assert_eq!(0_f32, root.get_layout_top());
assert_eq!(100_f32, root.get_layout_width());
assert_eq!(100_f32, root.get_layout_height());
assert_eq!(20_f32, root_child0.get_layout_left());
assert_eq!(0_f32, root_child0.get_layout_top());
assert_eq!(20_f32, root_child0.get_layout_width());
assert_eq!(100_f32, root_child0.get_layout_height());
assert_eq!(50_f32, root_child1.get_layout_left());
assert_eq!(0_f32, root_child1.get_layout_top());
assert_eq!(20_f32, root_child1.get_layout_width());
assert_eq!(100_f32, root_child1.get_layout_height());
assert_eq!(80_f32, root_child2.get_layout_left());
assert_eq!(0_f32, root_child2.get_layout_top());
assert_eq!(20_f32, root_child2.get_layout_width());
assert_eq!(100_f32, root_child2.get_layout_height());
root.calculate_layout(Undefined, Undefined, Direction::RTL);
assert_eq!(0_f32, root.get_layout_left());
assert_eq!(0_f32, root.get_layout_top());
assert_eq!(100_f32, root.get_layout_width());
assert_eq!(100_f32, root.get_layout_height());
assert_eq!(60_f32, root_child0.get_layout_left());
assert_eq!(0_f32, root_child0.get_layout_top());
assert_eq!(20_f32, root_child0.get_layout_width());
assert_eq!(100_f32, root_child0.get_layout_height());
assert_eq!(30_f32, root_child1.get_layout_left());
assert_eq!(0_f32, root_child1.get_layout_top());
assert_eq!(20_f32, root_child1.get_layout_width());
assert_eq!(100_f32, root_child1.get_layout_height());
assert_eq!(0_f32, root_child2.get_layout_left());
assert_eq!(0_f32, root_child2.get_layout_top());
assert_eq!(20_f32, root_child2.get_layout_width());
assert_eq!(100_f32, root_child2.get_layout_height());
}
#[test]
fn test_column_gap_justify_space_between() {
let mut config = Config::new();
let mut root = Node::new_with_config(&mut config);
root.set_flex_direction(FlexDirection::Row);
root.set_justify_content(Justify::SpaceBetween);
root.set_position_type(PositionType::Absolute);
root.set_width(StyleUnit::Point(100_f32.into()));
root.set_height(StyleUnit::Point(100_f32.into()));
root.set_gap(Gutter::Column, StyleUnit::Point(10_f32.into()));
let mut root_child0 = Node::new_with_config(&mut config);
root_child0.set_width(StyleUnit::Point(20_f32.into()));
root.insert_child(&mut root_child0, 0);
let mut root_child1 = Node::new_with_config(&mut config);
root_child1.set_width(StyleUnit::Point(20_f32.into()));
root.insert_child(&mut root_child1, 1);
let mut root_child2 = Node::new_with_config(&mut config);
root_child2.set_width(StyleUnit::Point(20_f32.into()));
root.insert_child(&mut root_child2, 2);
root.calculate_layout(Undefined, Undefined, Direction::LTR);
assert_eq!(0_f32, root.get_layout_left());
assert_eq!(0_f32, root.get_layout_top());
assert_eq!(100_f32, root.get_layout_width());
assert_eq!(100_f32, root.get_layout_height());
assert_eq!(0_f32, root_child0.get_layout_left());
assert_eq!(0_f32, root_child0.get_layout_top());
assert_eq!(20_f32, root_child0.get_layout_width());
assert_eq!(100_f32, root_child0.get_layout_height());
assert_eq!(40_f32, root_child1.get_layout_left());
assert_eq!(0_f32, root_child1.get_layout_top());
assert_eq!(20_f32, root_child1.get_layout_width());
assert_eq!(100_f32, root_child1.get_layout_height());
assert_eq!(80_f32, root_child2.get_layout_left());
assert_eq!(0_f32, root_child2.get_layout_top());
assert_eq!(20_f32, root_child2.get_layout_width());
assert_eq!(100_f32, root_child2.get_layout_height());
root.calculate_layout(Undefined, Undefined, Direction::RTL);
assert_eq!(0_f32, root.get_layout_left());
assert_eq!(0_f32, root.get_layout_top());
assert_eq!(100_f32, root.get_layout_width());
assert_eq!(100_f32, root.get_layout_height());
assert_eq!(80_f32, root_child0.get_layout_left());
assert_eq!(0_f32, root_child0.get_layout_top());
assert_eq!(20_f32, root_child0.get_layout_width());
assert_eq!(100_f32, root_child0.get_layout_height());
assert_eq!(40_f32, root_child1.get_layout_left());
assert_eq!(0_f32, root_child1.get_layout_top());
assert_eq!(20_f32, root_child1.get_layout_width());
assert_eq!(100_f32, root_child1.get_layout_height());
assert_eq!(0_f32, root_child2.get_layout_left());
assert_eq!(0_f32, root_child2.get_layout_top());
assert_eq!(20_f32, root_child2.get_layout_width());
assert_eq!(100_f32, root_child2.get_layout_height());
}
#[test]
fn test_column_gap_justify_space_around() {
let mut config = Config::new();
let mut root = Node::new_with_config(&mut config);
root.set_flex_direction(FlexDirection::Row);
root.set_justify_content(Justify::SpaceAround);
root.set_position_type(PositionType::Absolute);
root.set_width(StyleUnit::Point(100_f32.into()));
root.set_height(StyleUnit::Point(100_f32.into()));
root.set_gap(Gutter::Column, StyleUnit::Point(10_f32.into()));
let mut root_child0 = Node::new_with_config(&mut config);
root_child0.set_width(StyleUnit::Point(20_f32.into()));
root.insert_child(&mut root_child0, 0);
let mut root_child1 = Node::new_with_config(&mut config);
root_child1.set_width(StyleUnit::Point(20_f32.into()));
root.insert_child(&mut root_child1, 1);
let mut root_child2 = Node::new_with_config(&mut config);
root_child2.set_width(StyleUnit::Point(20_f32.into()));
root.insert_child(&mut root_child2, 2);
root.calculate_layout(Undefined, Undefined, Direction::LTR);
assert_eq!(0_f32, root.get_layout_left());
assert_eq!(0_f32, root.get_layout_top());
assert_eq!(100_f32, root.get_layout_width());
assert_eq!(100_f32, root.get_layout_height());
assert_eq!(3_f32, root_child0.get_layout_left());
assert_eq!(0_f32, root_child0.get_layout_top());
assert_eq!(20_f32, root_child0.get_layout_width());
assert_eq!(100_f32, root_child0.get_layout_height());
assert_eq!(40_f32, root_child1.get_layout_left());
assert_eq!(0_f32, root_child1.get_layout_top());
assert_eq!(20_f32, root_child1.get_layout_width());
assert_eq!(100_f32, root_child1.get_layout_height());
assert_eq!(77_f32, root_child2.get_layout_left());
assert_eq!(0_f32, root_child2.get_layout_top());
assert_eq!(20_f32, root_child2.get_layout_width());
assert_eq!(100_f32, root_child2.get_layout_height());
root.calculate_layout(Undefined, Undefined, Direction::RTL);
assert_eq!(0_f32, root.get_layout_left());
assert_eq!(0_f32, root.get_layout_top());
assert_eq!(100_f32, root.get_layout_width());
assert_eq!(100_f32, root.get_layout_height());
assert_eq!(77_f32, root_child0.get_layout_left());
assert_eq!(0_f32, root_child0.get_layout_top());
assert_eq!(20_f32, root_child0.get_layout_width());
assert_eq!(100_f32, root_child0.get_layout_height());
assert_eq!(40_f32, root_child1.get_layout_left());
assert_eq!(0_f32, root_child1.get_layout_top());
assert_eq!(20_f32, root_child1.get_layout_width());
assert_eq!(100_f32, root_child1.get_layout_height());
assert_eq!(3_f32, root_child2.get_layout_left());
assert_eq!(0_f32, root_child2.get_layout_top());
assert_eq!(20_f32, root_child2.get_layout_width());
assert_eq!(100_f32, root_child2.get_layout_height());
}
#[test]
fn test_column_gap_justify_space_evenly() {
let mut config = Config::new();
let mut root = Node::new_with_config(&mut config);
root.set_flex_direction(FlexDirection::Row);
root.set_justify_content(Justify::SpaceEvenly);
root.set_position_type(PositionType::Absolute);
root.set_width(StyleUnit::Point(100_f32.into()));
root.set_height(StyleUnit::Point(100_f32.into()));
root.set_gap(Gutter::Column, StyleUnit::Point(10_f32.into()));
let mut root_child0 = Node::new_with_config(&mut config);
root_child0.set_width(StyleUnit::Point(20_f32.into()));
root.insert_child(&mut root_child0, 0);
let mut root_child1 = Node::new_with_config(&mut config);
root_child1.set_width(StyleUnit::Point(20_f32.into()));
root.insert_child(&mut root_child1, 1);
let mut root_child2 = Node::new_with_config(&mut config);
root_child2.set_width(StyleUnit::Point(20_f32.into()));
root.insert_child(&mut root_child2, 2);
root.calculate_layout(Undefined, Undefined, Direction::LTR);
assert_eq!(0_f32, root.get_layout_left());
assert_eq!(0_f32, root.get_layout_top());
assert_eq!(100_f32, root.get_layout_width());
assert_eq!(100_f32, root.get_layout_height());
assert_eq!(5_f32, root_child0.get_layout_left());
assert_eq!(0_f32, root_child0.get_layout_top());
assert_eq!(20_f32, root_child0.get_layout_width());
assert_eq!(100_f32, root_child0.get_layout_height());
assert_eq!(40_f32, root_child1.get_layout_left());
assert_eq!(0_f32, root_child1.get_layout_top());
assert_eq!(20_f32, root_child1.get_layout_width());
assert_eq!(100_f32, root_child1.get_layout_height());
assert_eq!(75_f32, root_child2.get_layout_left());
assert_eq!(0_f32, root_child2.get_layout_top());
assert_eq!(20_f32, root_child2.get_layout_width());
assert_eq!(100_f32, root_child2.get_layout_height());
root.calculate_layout(Undefined, Undefined, Direction::RTL);
assert_eq!(0_f32, root.get_layout_left());
assert_eq!(0_f32, root.get_layout_top());
assert_eq!(100_f32, root.get_layout_width());
assert_eq!(100_f32, root.get_layout_height());
assert_eq!(75_f32, root_child0.get_layout_left());
assert_eq!(0_f32, root_child0.get_layout_top());
assert_eq!(20_f32, root_child0.get_layout_width());
assert_eq!(100_f32, root_child0.get_layout_height());
assert_eq!(40_f32, root_child1.get_layout_left());
assert_eq!(0_f32, root_child1.get_layout_top());
assert_eq!(20_f32, root_child1.get_layout_width());
assert_eq!(100_f32, root_child1.get_layout_height());
assert_eq!(5_f32, root_child2.get_layout_left());
assert_eq!(0_f32, root_child2.get_layout_top());
assert_eq!(20_f32, root_child2.get_layout_width());
assert_eq!(100_f32, root_child2.get_layout_height());
}
#[test]
fn test_column_gap_wrap_align_flex_start() {
let mut config = Config::new();
let mut root = Node::new_with_config(&mut config);
root.set_flex_direction(FlexDirection::Row);
root.set_position_type(PositionType::Absolute);
root.set_flex_wrap(Wrap::Wrap);
root.set_width(StyleUnit::Point(100_f32.into()));
root.set_height(StyleUnit::Point(100_f32.into()));
root.set_gap(Gutter::Column, StyleUnit::Point(10_f32.into()));
root.set_gap(Gutter::Row, StyleUnit::Point(20_f32.into()));
let mut root_child0 = Node::new_with_config(&mut config);
root_child0.set_width(StyleUnit::Point(20_f32.into()));
root_child0.set_height(StyleUnit::Point(20_f32.into()));
root.insert_child(&mut root_child0, 0);
let mut root_child1 = Node::new_with_config(&mut config);
root_child1.set_width(StyleUnit::Point(20_f32.into()));
root_child1.set_height(StyleUnit::Point(20_f32.into()));
root.insert_child(&mut root_child1, 1);
let mut root_child2 = Node::new_with_config(&mut config);
root_child2.set_width(StyleUnit::Point(20_f32.into()));
root_child2.set_height(StyleUnit::Point(20_f32.into()));
root.insert_child(&mut root_child2, 2);
let mut root_child3 = Node::new_with_config(&mut config);
root_child3.set_width(StyleUnit::Point(20_f32.into()));
root_child3.set_height(StyleUnit::Point(20_f32.into()));
root.insert_child(&mut root_child3, 3);
let mut root_child4 = Node::new_with_config(&mut config);
root_child4.set_width(StyleUnit::Point(20_f32.into()));
root_child4.set_height(StyleUnit::Point(20_f32.into()));
root.insert_child(&mut root_child4, 4);
let mut root_child5 = Node::new_with_config(&mut config);
root_child5.set_width(StyleUnit::Point(20_f32.into()));
root_child5.set_height(StyleUnit::Point(20_f32.into()));
root.insert_child(&mut root_child5, 5);
root.calculate_layout(Undefined, Undefined, Direction::LTR);
assert_eq!(0_f32, root.get_layout_left());
assert_eq!(0_f32, root.get_layout_top());
assert_eq!(100_f32, root.get_layout_width());
assert_eq!(100_f32, root.get_layout_height());
assert_eq!(0_f32, root_child0.get_layout_left());
assert_eq!(0_f32, root_child0.get_layout_top());
assert_eq!(20_f32, root_child0.get_layout_width());
assert_eq!(20_f32, root_child0.get_layout_height());
assert_eq!(30_f32, root_child1.get_layout_left());
assert_eq!(0_f32, root_child1.get_layout_top());
assert_eq!(20_f32, root_child1.get_layout_width());
assert_eq!(20_f32, root_child1.get_layout_height());
assert_eq!(60_f32, root_child2.get_layout_left());
assert_eq!(0_f32, root_child2.get_layout_top());
assert_eq!(20_f32, root_child2.get_layout_width());
assert_eq!(20_f32, root_child2.get_layout_height());
assert_eq!(0_f32, root_child3.get_layout_left());
assert_eq!(40_f32, root_child3.get_layout_top());
assert_eq!(20_f32, root_child3.get_layout_width());
assert_eq!(20_f32, root_child3.get_layout_height());
assert_eq!(30_f32, root_child4.get_layout_left());
assert_eq!(40_f32, root_child4.get_layout_top());
assert_eq!(20_f32, root_child4.get_layout_width());
assert_eq!(20_f32, root_child4.get_layout_height());
assert_eq!(60_f32, root_child5.get_layout_left());
assert_eq!(40_f32, root_child5.get_layout_top());
assert_eq!(20_f32, root_child5.get_layout_width());
assert_eq!(20_f32, root_child5.get_layout_height());
root.calculate_layout(Undefined, Undefined, Direction::RTL);
assert_eq!(0_f32, root.get_layout_left());
assert_eq!(0_f32, root.get_layout_top());
assert_eq!(100_f32, root.get_layout_width());
assert_eq!(100_f32, root.get_layout_height());
assert_eq!(80_f32, root_child0.get_layout_left());
assert_eq!(0_f32, root_child0.get_layout_top());
assert_eq!(20_f32, root_child0.get_layout_width());
assert_eq!(20_f32, root_child0.get_layout_height());
assert_eq!(50_f32, root_child1.get_layout_left());
assert_eq!(0_f32, root_child1.get_layout_top());
assert_eq!(20_f32, root_child1.get_layout_width());
assert_eq!(20_f32, root_child1.get_layout_height());
assert_eq!(20_f32, root_child2.get_layout_left());
assert_eq!(0_f32, root_child2.get_layout_top());
assert_eq!(20_f32, root_child2.get_layout_width());
assert_eq!(20_f32, root_child2.get_layout_height());
assert_eq!(80_f32, root_child3.get_layout_left());
assert_eq!(40_f32, root_child3.get_layout_top());
assert_eq!(20_f32, root_child3.get_layout_width());
assert_eq!(20_f32, root_child3.get_layout_height());
assert_eq!(50_f32, root_child4.get_layout_left());
assert_eq!(40_f32, root_child4.get_layout_top());
assert_eq!(20_f32, root_child4.get_layout_width());
assert_eq!(20_f32, root_child4.get_layout_height());
assert_eq!(20_f32, root_child5.get_layout_left());
assert_eq!(40_f32, root_child5.get_layout_top());
assert_eq!(20_f32, root_child5.get_layout_width());
assert_eq!(20_f32, root_child5.get_layout_height());
}
#[test]
fn test_column_gap_wrap_align_center() {
let mut config = Config::new();
let mut root = Node::new_with_config(&mut config);
root.set_flex_direction(FlexDirection::Row);
root.set_align_content(Align::Center);
root.set_position_type(PositionType::Absolute);
root.set_flex_wrap(Wrap::Wrap);
root.set_width(StyleUnit::Point(100_f32.into()));
root.set_height(StyleUnit::Point(100_f32.into()));
root.set_gap(Gutter::Column, StyleUnit::Point(10_f32.into()));
root.set_gap(Gutter::Row, StyleUnit::Point(20_f32.into()));
let mut root_child0 = Node::new_with_config(&mut config);
root_child0.set_width(StyleUnit::Point(20_f32.into()));
root_child0.set_height(StyleUnit::Point(20_f32.into()));
root.insert_child(&mut root_child0, 0);
let mut root_child1 = Node::new_with_config(&mut config);
root_child1.set_width(StyleUnit::Point(20_f32.into()));
root_child1.set_height(StyleUnit::Point(20_f32.into()));
root.insert_child(&mut root_child1, 1);
let mut root_child2 = Node::new_with_config(&mut config);
root_child2.set_width(StyleUnit::Point(20_f32.into()));
root_child2.set_height(StyleUnit::Point(20_f32.into()));
root.insert_child(&mut root_child2, 2);
let mut root_child3 = Node::new_with_config(&mut config);
root_child3.set_width(StyleUnit::Point(20_f32.into()));
root_child3.set_height(StyleUnit::Point(20_f32.into()));
root.insert_child(&mut root_child3, 3);
let mut root_child4 = Node::new_with_config(&mut config);
root_child4.set_width(StyleUnit::Point(20_f32.into()));
root_child4.set_height(StyleUnit::Point(20_f32.into()));
root.insert_child(&mut root_child4, 4);
let mut root_child5 = Node::new_with_config(&mut config);
root_child5.set_width(StyleUnit::Point(20_f32.into()));
root_child5.set_height(StyleUnit::Point(20_f32.into()));
root.insert_child(&mut root_child5, 5);
root.calculate_layout(Undefined, Undefined, Direction::LTR);
assert_eq!(0_f32, root.get_layout_left());
assert_eq!(0_f32, root.get_layout_top());
assert_eq!(100_f32, root.get_layout_width());
assert_eq!(100_f32, root.get_layout_height());
assert_eq!(0_f32, root_child0.get_layout_left());
assert_eq!(20_f32, root_child0.get_layout_top());
assert_eq!(20_f32, root_child0.get_layout_width());
assert_eq!(20_f32, root_child0.get_layout_height());
assert_eq!(30_f32, root_child1.get_layout_left());
assert_eq!(20_f32, root_child1.get_layout_top());
assert_eq!(20_f32, root_child1.get_layout_width());
assert_eq!(20_f32, root_child1.get_layout_height());
assert_eq!(60_f32, root_child2.get_layout_left());
assert_eq!(20_f32, root_child2.get_layout_top());
assert_eq!(20_f32, root_child2.get_layout_width());
assert_eq!(20_f32, root_child2.get_layout_height());
assert_eq!(0_f32, root_child3.get_layout_left());
assert_eq!(60_f32, root_child3.get_layout_top());
assert_eq!(20_f32, root_child3.get_layout_width());
assert_eq!(20_f32, root_child3.get_layout_height());
assert_eq!(30_f32, root_child4.get_layout_left());
assert_eq!(60_f32, root_child4.get_layout_top());
assert_eq!(20_f32, root_child4.get_layout_width());
assert_eq!(20_f32, root_child4.get_layout_height());
assert_eq!(60_f32, root_child5.get_layout_left());
assert_eq!(60_f32, root_child5.get_layout_top());
assert_eq!(20_f32, root_child5.get_layout_width());
assert_eq!(20_f32, root_child5.get_layout_height());
root.calculate_layout(Undefined, Undefined, Direction::RTL);
assert_eq!(0_f32, root.get_layout_left());
assert_eq!(0_f32, root.get_layout_top());
assert_eq!(100_f32, root.get_layout_width());
assert_eq!(100_f32, root.get_layout_height());
assert_eq!(80_f32, root_child0.get_layout_left());
assert_eq!(20_f32, root_child0.get_layout_top());
assert_eq!(20_f32, root_child0.get_layout_width());
assert_eq!(20_f32, root_child0.get_layout_height());
assert_eq!(50_f32, root_child1.get_layout_left());
assert_eq!(20_f32, root_child1.get_layout_top());
assert_eq!(20_f32, root_child1.get_layout_width());
assert_eq!(20_f32, root_child1.get_layout_height());
assert_eq!(20_f32, root_child2.get_layout_left());
assert_eq!(20_f32, root_child2.get_layout_top());
assert_eq!(20_f32, root_child2.get_layout_width());
assert_eq!(20_f32, root_child2.get_layout_height());
assert_eq!(80_f32, root_child3.get_layout_left());
assert_eq!(60_f32, root_child3.get_layout_top());
assert_eq!(20_f32, root_child3.get_layout_width());
assert_eq!(20_f32, root_child3.get_layout_height());
assert_eq!(50_f32, root_child4.get_layout_left());
assert_eq!(60_f32, root_child4.get_layout_top());
assert_eq!(20_f32, root_child4.get_layout_width());
assert_eq!(20_f32, root_child4.get_layout_height());
assert_eq!(20_f32, root_child5.get_layout_left());
assert_eq!(60_f32, root_child5.get_layout_top());
assert_eq!(20_f32, root_child5.get_layout_width());
assert_eq!(20_f32, root_child5.get_layout_height());
}
#[test]
fn test_column_gap_wrap_align_flex_end() {
let mut config = Config::new();
let mut root = Node::new_with_config(&mut config);
root.set_flex_direction(FlexDirection::Row);
root.set_align_content(Align::FlexEnd);
root.set_position_type(PositionType::Absolute);
root.set_flex_wrap(Wrap::Wrap);
root.set_width(StyleUnit::Point(100_f32.into()));
root.set_height(StyleUnit::Point(100_f32.into()));
root.set_gap(Gutter::Column, StyleUnit::Point(10_f32.into()));
root.set_gap(Gutter::Row, StyleUnit::Point(20_f32.into()));
let mut root_child0 = Node::new_with_config(&mut config);
root_child0.set_width(StyleUnit::Point(20_f32.into()));
root_child0.set_height(StyleUnit::Point(20_f32.into()));
root.insert_child(&mut root_child0, 0);
let mut root_child1 = Node::new_with_config(&mut config);
root_child1.set_width(StyleUnit::Point(20_f32.into()));
root_child1.set_height(StyleUnit::Point(20_f32.into()));
root.insert_child(&mut root_child1, 1);
let mut root_child2 = Node::new_with_config(&mut config);
root_child2.set_width(StyleUnit::Point(20_f32.into()));
root_child2.set_height(StyleUnit::Point(20_f32.into()));
root.insert_child(&mut root_child2, 2);
let mut root_child3 = Node::new_with_config(&mut config);
root_child3.set_width(StyleUnit::Point(20_f32.into()));
root_child3.set_height(StyleUnit::Point(20_f32.into()));
root.insert_child(&mut root_child3, 3);
let mut root_child4 = Node::new_with_config(&mut config);
root_child4.set_width(StyleUnit::Point(20_f32.into()));
root_child4.set_height(StyleUnit::Point(20_f32.into()));
root.insert_child(&mut root_child4, 4);
let mut root_child5 = Node::new_with_config(&mut config);
root_child5.set_width(StyleUnit::Point(20_f32.into()));
root_child5.set_height(StyleUnit::Point(20_f32.into()));
root.insert_child(&mut root_child5, 5);
root.calculate_layout(Undefined, Undefined, Direction::LTR);
assert_eq!(0_f32, root.get_layout_left());
assert_eq!(0_f32, root.get_layout_top());
assert_eq!(100_f32, root.get_layout_width());
assert_eq!(100_f32, root.get_layout_height());
assert_eq!(0_f32, root_child0.get_layout_left());
assert_eq!(40_f32, root_child0.get_layout_top());
assert_eq!(20_f32, root_child0.get_layout_width());
assert_eq!(20_f32, root_child0.get_layout_height());
assert_eq!(30_f32, root_child1.get_layout_left());
assert_eq!(40_f32, root_child1.get_layout_top());
assert_eq!(20_f32, root_child1.get_layout_width());
assert_eq!(20_f32, root_child1.get_layout_height());
assert_eq!(60_f32, root_child2.get_layout_left());
assert_eq!(40_f32, root_child2.get_layout_top());
assert_eq!(20_f32, root_child2.get_layout_width());
assert_eq!(20_f32, root_child2.get_layout_height());
assert_eq!(0_f32, root_child3.get_layout_left());
assert_eq!(80_f32, root_child3.get_layout_top());
assert_eq!(20_f32, root_child3.get_layout_width());
assert_eq!(20_f32, root_child3.get_layout_height());
assert_eq!(30_f32, root_child4.get_layout_left());
assert_eq!(80_f32, root_child4.get_layout_top());
assert_eq!(20_f32, root_child4.get_layout_width());
assert_eq!(20_f32, root_child4.get_layout_height());
assert_eq!(60_f32, root_child5.get_layout_left());
assert_eq!(80_f32, root_child5.get_layout_top());
assert_eq!(20_f32, root_child5.get_layout_width());
assert_eq!(20_f32, root_child5.get_layout_height());
root.calculate_layout(Undefined, Undefined, Direction::RTL);
assert_eq!(0_f32, root.get_layout_left());
assert_eq!(0_f32, root.get_layout_top());
assert_eq!(100_f32, root.get_layout_width());
assert_eq!(100_f32, root.get_layout_height());
assert_eq!(80_f32, root_child0.get_layout_left());
assert_eq!(40_f32, root_child0.get_layout_top());
assert_eq!(20_f32, root_child0.get_layout_width());
assert_eq!(20_f32, root_child0.get_layout_height());
assert_eq!(50_f32, root_child1.get_layout_left());
assert_eq!(40_f32, root_child1.get_layout_top());
assert_eq!(20_f32, root_child1.get_layout_width());
assert_eq!(20_f32, root_child1.get_layout_height());
assert_eq!(20_f32, root_child2.get_layout_left());
assert_eq!(40_f32, root_child2.get_layout_top());
assert_eq!(20_f32, root_child2.get_layout_width());
assert_eq!(20_f32, root_child2.get_layout_height());
assert_eq!(80_f32, root_child3.get_layout_left());
assert_eq!(80_f32, root_child3.get_layout_top());
assert_eq!(20_f32, root_child3.get_layout_width());
assert_eq!(20_f32, root_child3.get_layout_height());
assert_eq!(50_f32, root_child4.get_layout_left());
assert_eq!(80_f32, root_child4.get_layout_top());
assert_eq!(20_f32, root_child4.get_layout_width());
assert_eq!(20_f32, root_child4.get_layout_height());
assert_eq!(20_f32, root_child5.get_layout_left());
assert_eq!(80_f32, root_child5.get_layout_top());
assert_eq!(20_f32, root_child5.get_layout_width());
assert_eq!(20_f32, root_child5.get_layout_height());
}
#[test]
fn test_column_gap_wrap_align_space_between() {
let mut config = Config::new();
let mut root = Node::new_with_config(&mut config);
root.set_flex_direction(FlexDirection::Row);
root.set_align_content(Align::SpaceBetween);
root.set_position_type(PositionType::Absolute);
root.set_flex_wrap(Wrap::Wrap);
root.set_width(StyleUnit::Point(100_f32.into()));
root.set_height(StyleUnit::Point(100_f32.into()));
root.set_gap(Gutter::Column, StyleUnit::Point(10_f32.into()));
root.set_gap(Gutter::Row, StyleUnit::Point(20_f32.into()));
let mut root_child0 = Node::new_with_config(&mut config);
root_child0.set_width(StyleUnit::Point(20_f32.into()));
root_child0.set_height(StyleUnit::Point(20_f32.into()));
root.insert_child(&mut root_child0, 0);
let mut root_child1 = Node::new_with_config(&mut config);
root_child1.set_width(StyleUnit::Point(20_f32.into()));
root_child1.set_height(StyleUnit::Point(20_f32.into()));
root.insert_child(&mut root_child1, 1);
let mut root_child2 = Node::new_with_config(&mut config);
root_child2.set_width(StyleUnit::Point(20_f32.into()));
root_child2.set_height(StyleUnit::Point(20_f32.into()));
root.insert_child(&mut root_child2, 2);
let mut root_child3 = Node::new_with_config(&mut config);
root_child3.set_width(StyleUnit::Point(20_f32.into()));
root_child3.set_height(StyleUnit::Point(20_f32.into()));
root.insert_child(&mut root_child3, 3);
let mut root_child4 = Node::new_with_config(&mut config);
root_child4.set_width(StyleUnit::Point(20_f32.into()));
root_child4.set_height(StyleUnit::Point(20_f32.into()));
root.insert_child(&mut root_child4, 4);
let mut root_child5 = Node::new_with_config(&mut config);
root_child5.set_width(StyleUnit::Point(20_f32.into()));
root_child5.set_height(StyleUnit::Point(20_f32.into()));
root.insert_child(&mut root_child5, 5);
root.calculate_layout(Undefined, Undefined, Direction::LTR);
assert_eq!(0_f32, root.get_layout_left());
assert_eq!(0_f32, root.get_layout_top());
assert_eq!(100_f32, root.get_layout_width());
assert_eq!(100_f32, root.get_layout_height());
assert_eq!(0_f32, root_child0.get_layout_left());
assert_eq!(0_f32, root_child0.get_layout_top());
assert_eq!(20_f32, root_child0.get_layout_width());
assert_eq!(20_f32, root_child0.get_layout_height());
assert_eq!(30_f32, root_child1.get_layout_left());
assert_eq!(0_f32, root_child1.get_layout_top());
assert_eq!(20_f32, root_child1.get_layout_width());
assert_eq!(20_f32, root_child1.get_layout_height());
assert_eq!(60_f32, root_child2.get_layout_left());
assert_eq!(0_f32, root_child2.get_layout_top());
assert_eq!(20_f32, root_child2.get_layout_width());
assert_eq!(20_f32, root_child2.get_layout_height());
assert_eq!(0_f32, root_child3.get_layout_left());
assert_eq!(80_f32, root_child3.get_layout_top());
assert_eq!(20_f32, root_child3.get_layout_width());
assert_eq!(20_f32, root_child3.get_layout_height());
assert_eq!(30_f32, root_child4.get_layout_left());
assert_eq!(80_f32, root_child4.get_layout_top());
assert_eq!(20_f32, root_child4.get_layout_width());
assert_eq!(20_f32, root_child4.get_layout_height());
assert_eq!(60_f32, root_child5.get_layout_left());
assert_eq!(80_f32, root_child5.get_layout_top());
assert_eq!(20_f32, root_child5.get_layout_width());
assert_eq!(20_f32, root_child5.get_layout_height());
root.calculate_layout(Undefined, Undefined, Direction::RTL);
assert_eq!(0_f32, root.get_layout_left());
assert_eq!(0_f32, root.get_layout_top());
assert_eq!(100_f32, root.get_layout_width());
assert_eq!(100_f32, root.get_layout_height());
assert_eq!(80_f32, root_child0.get_layout_left());
assert_eq!(0_f32, root_child0.get_layout_top());
assert_eq!(20_f32, root_child0.get_layout_width());
assert_eq!(20_f32, root_child0.get_layout_height());
assert_eq!(50_f32, root_child1.get_layout_left());
assert_eq!(0_f32, root_child1.get_layout_top());
assert_eq!(20_f32, root_child1.get_layout_width());
assert_eq!(20_f32, root_child1.get_layout_height());
assert_eq!(20_f32, root_child2.get_layout_left());
assert_eq!(0_f32, root_child2.get_layout_top());
assert_eq!(20_f32, root_child2.get_layout_width());
assert_eq!(20_f32, root_child2.get_layout_height());
assert_eq!(80_f32, root_child3.get_layout_left());
assert_eq!(80_f32, root_child3.get_layout_top());
assert_eq!(20_f32, root_child3.get_layout_width());
assert_eq!(20_f32, root_child3.get_layout_height());
assert_eq!(50_f32, root_child4.get_layout_left());
assert_eq!(80_f32, root_child4.get_layout_top());
assert_eq!(20_f32, root_child4.get_layout_width());
assert_eq!(20_f32, root_child4.get_layout_height());
assert_eq!(20_f32, root_child5.get_layout_left());
assert_eq!(80_f32, root_child5.get_layout_top());
assert_eq!(20_f32, root_child5.get_layout_width());
assert_eq!(20_f32, root_child5.get_layout_height());
}
#[test]
fn test_column_gap_wrap_align_space_around() {
let mut config = Config::new();
let mut root = Node::new_with_config(&mut config);
root.set_flex_direction(FlexDirection::Row);
root.set_align_content(Align::SpaceAround);
root.set_position_type(PositionType::Absolute);
root.set_flex_wrap(Wrap::Wrap);
root.set_width(StyleUnit::Point(100_f32.into()));
root.set_height(StyleUnit::Point(100_f32.into()));
root.set_gap(Gutter::Column, StyleUnit::Point(10_f32.into()));
root.set_gap(Gutter::Row, StyleUnit::Point(20_f32.into()));
let mut root_child0 = Node::new_with_config(&mut config);
root_child0.set_width(StyleUnit::Point(20_f32.into()));
root_child0.set_height(StyleUnit::Point(20_f32.into()));
root.insert_child(&mut root_child0, 0);
let mut root_child1 = Node::new_with_config(&mut config);
root_child1.set_width(StyleUnit::Point(20_f32.into()));
root_child1.set_height(StyleUnit::Point(20_f32.into()));
root.insert_child(&mut root_child1, 1);
let mut root_child2 = Node::new_with_config(&mut config);
root_child2.set_width(StyleUnit::Point(20_f32.into()));
root_child2.set_height(StyleUnit::Point(20_f32.into()));
root.insert_child(&mut root_child2, 2);
let mut root_child3 = Node::new_with_config(&mut config);
root_child3.set_width(StyleUnit::Point(20_f32.into()));
root_child3.set_height(StyleUnit::Point(20_f32.into()));
root.insert_child(&mut root_child3, 3);
let mut root_child4 = Node::new_with_config(&mut config);
root_child4.set_width(StyleUnit::Point(20_f32.into()));
root_child4.set_height(StyleUnit::Point(20_f32.into()));
root.insert_child(&mut root_child4, 4);
let mut root_child5 = Node::new_with_config(&mut config);
root_child5.set_width(StyleUnit::Point(20_f32.into()));
root_child5.set_height(StyleUnit::Point(20_f32.into()));
root.insert_child(&mut root_child5, 5);
root.calculate_layout(Undefined, Undefined, Direction::LTR);
assert_eq!(0_f32, root.get_layout_left());
assert_eq!(0_f32, root.get_layout_top());
assert_eq!(100_f32, root.get_layout_width());
assert_eq!(100_f32, root.get_layout_height());
assert_eq!(0_f32, root_child0.get_layout_left());
assert_eq!(10_f32, root_child0.get_layout_top());
assert_eq!(20_f32, root_child0.get_layout_width());
assert_eq!(20_f32, root_child0.get_layout_height());
assert_eq!(30_f32, root_child1.get_layout_left());
assert_eq!(10_f32, root_child1.get_layout_top());
assert_eq!(20_f32, root_child1.get_layout_width());
assert_eq!(20_f32, root_child1.get_layout_height());
assert_eq!(60_f32, root_child2.get_layout_left());
assert_eq!(10_f32, root_child2.get_layout_top());
assert_eq!(20_f32, root_child2.get_layout_width());
assert_eq!(20_f32, root_child2.get_layout_height());
assert_eq!(0_f32, root_child3.get_layout_left());
assert_eq!(70_f32, root_child3.get_layout_top());
assert_eq!(20_f32, root_child3.get_layout_width());
assert_eq!(20_f32, root_child3.get_layout_height());
assert_eq!(30_f32, root_child4.get_layout_left());
assert_eq!(70_f32, root_child4.get_layout_top());
assert_eq!(20_f32, root_child4.get_layout_width());
assert_eq!(20_f32, root_child4.get_layout_height());
assert_eq!(60_f32, root_child5.get_layout_left());
assert_eq!(70_f32, root_child5.get_layout_top());
assert_eq!(20_f32, root_child5.get_layout_width());
assert_eq!(20_f32, root_child5.get_layout_height());
root.calculate_layout(Undefined, Undefined, Direction::RTL);
assert_eq!(0_f32, root.get_layout_left());
assert_eq!(0_f32, root.get_layout_top());
assert_eq!(100_f32, root.get_layout_width());
assert_eq!(100_f32, root.get_layout_height());
assert_eq!(80_f32, root_child0.get_layout_left());
assert_eq!(10_f32, root_child0.get_layout_top());
assert_eq!(20_f32, root_child0.get_layout_width());
assert_eq!(20_f32, root_child0.get_layout_height());
assert_eq!(50_f32, root_child1.get_layout_left());
assert_eq!(10_f32, root_child1.get_layout_top());
assert_eq!(20_f32, root_child1.get_layout_width());
assert_eq!(20_f32, root_child1.get_layout_height());
assert_eq!(20_f32, root_child2.get_layout_left());
assert_eq!(10_f32, root_child2.get_layout_top());
assert_eq!(20_f32, root_child2.get_layout_width());
assert_eq!(20_f32, root_child2.get_layout_height());
assert_eq!(80_f32, root_child3.get_layout_left());
assert_eq!(70_f32, root_child3.get_layout_top());
assert_eq!(20_f32, root_child3.get_layout_width());
assert_eq!(20_f32, root_child3.get_layout_height());
assert_eq!(50_f32, root_child4.get_layout_left());
assert_eq!(70_f32, root_child4.get_layout_top());
assert_eq!(20_f32, root_child4.get_layout_width());
assert_eq!(20_f32, root_child4.get_layout_height());
assert_eq!(20_f32, root_child5.get_layout_left());
assert_eq!(70_f32, root_child5.get_layout_top());
assert_eq!(20_f32, root_child5.get_layout_width());
assert_eq!(20_f32, root_child5.get_layout_height());
}
#[test]
fn test_column_gap_wrap_align_stretch() {
let mut config = Config::new();
let mut root = Node::new_with_config(&mut config);
root.set_flex_direction(FlexDirection::Row);
root.set_align_content(Align::Stretch);
root.set_position_type(PositionType::Absolute);
root.set_flex_wrap(Wrap::Wrap);
root.set_width(StyleUnit::Point(300_f32.into()));
root.set_height(StyleUnit::Point(300_f32.into()));
root.set_gap(Gutter::Column, StyleUnit::Point(5_f32.into()));
let mut root_child0 = Node::new_with_config(&mut config);
root_child0.set_flex_grow(1_f32);
root_child0.set_min_width(StyleUnit::Point(60_f32.into()));
root.insert_child(&mut root_child0, 0);
let mut root_child1 = Node::new_with_config(&mut config);
root_child1.set_flex_grow(1_f32);
root_child1.set_min_width(StyleUnit::Point(60_f32.into()));
root.insert_child(&mut root_child1, 1);
let mut root_child2 = Node::new_with_config(&mut config);
root_child2.set_flex_grow(1_f32);
root_child2.set_min_width(StyleUnit::Point(60_f32.into()));
root.insert_child(&mut root_child2, 2);
let mut root_child3 = Node::new_with_config(&mut config);
root_child3.set_flex_grow(1_f32);
root_child3.set_min_width(StyleUnit::Point(60_f32.into()));
root.insert_child(&mut root_child3, 3);
let mut root_child4 = Node::new_with_config(&mut config);
root_child4.set_flex_grow(1_f32);
root_child4.set_min_width(StyleUnit::Point(60_f32.into()));
root.insert_child(&mut root_child4, 4);
root.calculate_layout(Undefined, Undefined, Direction::LTR);
assert_eq!(0_f32, root.get_layout_left());
assert_eq!(0_f32, root.get_layout_top());
assert_eq!(300_f32, root.get_layout_width());
assert_eq!(300_f32, root.get_layout_height());
assert_eq!(0_f32, root_child0.get_layout_left());
assert_eq!(0_f32, root_child0.get_layout_top());
assert_eq!(71_f32, root_child0.get_layout_width());
assert_eq!(150_f32, root_child0.get_layout_height());
assert_eq!(76_f32, root_child1.get_layout_left());
assert_eq!(0_f32, root_child1.get_layout_top());
assert_eq!(72_f32, root_child1.get_layout_width());
assert_eq!(150_f32, root_child1.get_layout_height());
assert_eq!(153_f32, root_child2.get_layout_left());
assert_eq!(0_f32, root_child2.get_layout_top());
assert_eq!(71_f32, root_child2.get_layout_width());
assert_eq!(150_f32, root_child2.get_layout_height());
assert_eq!(229_f32, root_child3.get_layout_left());
assert_eq!(0_f32, root_child3.get_layout_top());
assert_eq!(71_f32, root_child3.get_layout_width());
assert_eq!(150_f32, root_child3.get_layout_height());
assert_eq!(0_f32, root_child4.get_layout_left());
assert_eq!(150_f32, root_child4.get_layout_top());
assert_eq!(300_f32, root_child4.get_layout_width());
assert_eq!(150_f32, root_child4.get_layout_height());
root.calculate_layout(Undefined, Undefined, Direction::RTL);
assert_eq!(0_f32, root.get_layout_left());
assert_eq!(0_f32, root.get_layout_top());
assert_eq!(300_f32, root.get_layout_width());
assert_eq!(300_f32, root.get_layout_height());
assert_eq!(229_f32, root_child0.get_layout_left());
assert_eq!(0_f32, root_child0.get_layout_top());
assert_eq!(71_f32, root_child0.get_layout_width());
assert_eq!(150_f32, root_child0.get_layout_height());
assert_eq!(153_f32, root_child1.get_layout_left());
assert_eq!(0_f32, root_child1.get_layout_top());
assert_eq!(71_f32, root_child1.get_layout_width());
assert_eq!(150_f32, root_child1.get_layout_height());
assert_eq!(76_f32, root_child2.get_layout_left());
assert_eq!(0_f32, root_child2.get_layout_top());
assert_eq!(72_f32, root_child2.get_layout_width());
assert_eq!(150_f32, root_child2.get_layout_height());
assert_eq!(0_f32, root_child3.get_layout_left());
assert_eq!(0_f32, root_child3.get_layout_top());
assert_eq!(71_f32, root_child3.get_layout_width());
assert_eq!(150_f32, root_child3.get_layout_height());
assert_eq!(0_f32, root_child4.get_layout_left());
assert_eq!(150_f32, root_child4.get_layout_top());
assert_eq!(300_f32, root_child4.get_layout_width());
assert_eq!(150_f32, root_child4.get_layout_height());
}
#[test]
fn test_column_gap_determines_parent_width() {
let mut config = Config::new();
let mut root = Node::new_with_config(&mut config);
root.set_flex_direction(FlexDirection::Row);
root.set_position_type(PositionType::Absolute);
root.set_height(StyleUnit::Point(100_f32.into()));
root.set_gap(Gutter::Column, StyleUnit::Point(10_f32.into()));
let mut root_child0 = Node::new_with_config(&mut config);
root_child0.set_width(StyleUnit::Point(10_f32.into()));
root.insert_child(&mut root_child0, 0);
let mut root_child1 = Node::new_with_config(&mut config);
root_child1.set_width(StyleUnit::Point(20_f32.into()));
root.insert_child(&mut root_child1, 1);
let mut root_child2 = Node::new_with_config(&mut config);
root_child2.set_width(StyleUnit::Point(30_f32.into()));
root.insert_child(&mut root_child2, 2);
root.calculate_layout(Undefined, Undefined, Direction::LTR);
assert_eq!(0_f32, root.get_layout_left());
assert_eq!(0_f32, root.get_layout_top());
assert_eq!(80_f32, root.get_layout_width());
assert_eq!(100_f32, root.get_layout_height());
assert_eq!(0_f32, root_child0.get_layout_left());
assert_eq!(0_f32, root_child0.get_layout_top());
assert_eq!(10_f32, root_child0.get_layout_width());
assert_eq!(100_f32, root_child0.get_layout_height());
assert_eq!(20_f32, root_child1.get_layout_left());
assert_eq!(0_f32, root_child1.get_layout_top());
assert_eq!(20_f32, root_child1.get_layout_width());
assert_eq!(100_f32, root_child1.get_layout_height());
assert_eq!(50_f32, root_child2.get_layout_left());
assert_eq!(0_f32, root_child2.get_layout_top());
assert_eq!(30_f32, root_child2.get_layout_width());
assert_eq!(100_f32, root_child2.get_layout_height());
root.calculate_layout(Undefined, Undefined, Direction::RTL);
assert_eq!(0_f32, root.get_layout_left());
assert_eq!(0_f32, root.get_layout_top());
assert_eq!(80_f32, root.get_layout_width());
assert_eq!(100_f32, root.get_layout_height());
assert_eq!(70_f32, root_child0.get_layout_left());
assert_eq!(0_f32, root_child0.get_layout_top());
assert_eq!(10_f32, root_child0.get_layout_width());
assert_eq!(100_f32, root_child0.get_layout_height());
assert_eq!(40_f32, root_child1.get_layout_left());
assert_eq!(0_f32, root_child1.get_layout_top());
assert_eq!(20_f32, root_child1.get_layout_width());
assert_eq!(100_f32, root_child1.get_layout_height());
assert_eq!(0_f32, root_child2.get_layout_left());
assert_eq!(0_f32, root_child2.get_layout_top());
assert_eq!(30_f32, root_child2.get_layout_width());
assert_eq!(100_f32, root_child2.get_layout_height());
}
#[test]
fn test_row_gap_align_items_stretch() {
let mut config = Config::new();
let mut root = Node::new_with_config(&mut config);
root.set_flex_direction(FlexDirection::Row);
root.set_align_content(Align::Stretch);
root.set_position_type(PositionType::Absolute);
root.set_flex_wrap(Wrap::Wrap);
root.set_width(StyleUnit::Point(100_f32.into()));
root.set_height(StyleUnit::Point(200_f32.into()));
root.set_gap(Gutter::Column, StyleUnit::Point(10_f32.into()));
root.set_gap(Gutter::Row, StyleUnit::Point(20_f32.into()));
let mut root_child0 = Node::new_with_config(&mut config);
root_child0.set_width(StyleUnit::Point(20_f32.into()));
root.insert_child(&mut root_child0, 0);
let mut root_child1 = Node::new_with_config(&mut config);
root_child1.set_width(StyleUnit::Point(20_f32.into()));
root.insert_child(&mut root_child1, 1);
let mut root_child2 = Node::new_with_config(&mut config);
root_child2.set_width(StyleUnit::Point(20_f32.into()));
root.insert_child(&mut root_child2, 2);
let mut root_child3 = Node::new_with_config(&mut config);
root_child3.set_width(StyleUnit::Point(20_f32.into()));
root.insert_child(&mut root_child3, 3);
let mut root_child4 = Node::new_with_config(&mut config);
root_child4.set_width(StyleUnit::Point(20_f32.into()));
root.insert_child(&mut root_child4, 4);
let mut root_child5 = Node::new_with_config(&mut config);
root_child5.set_width(StyleUnit::Point(20_f32.into()));
root.insert_child(&mut root_child5, 5);
root.calculate_layout(Undefined, Undefined, Direction::LTR);
assert_eq!(0_f32, root.get_layout_left());
assert_eq!(0_f32, root.get_layout_top());
assert_eq!(100_f32, root.get_layout_width());
assert_eq!(200_f32, root.get_layout_height());
assert_eq!(0_f32, root_child0.get_layout_left());
assert_eq!(0_f32, root_child0.get_layout_top());
assert_eq!(20_f32, root_child0.get_layout_width());
assert_eq!(90_f32, root_child0.get_layout_height());
assert_eq!(30_f32, root_child1.get_layout_left());
assert_eq!(0_f32, root_child1.get_layout_top());
assert_eq!(20_f32, root_child1.get_layout_width());
assert_eq!(90_f32, root_child1.get_layout_height());
assert_eq!(60_f32, root_child2.get_layout_left());
assert_eq!(0_f32, root_child2.get_layout_top());
assert_eq!(20_f32, root_child2.get_layout_width());
assert_eq!(90_f32, root_child2.get_layout_height());
assert_eq!(0_f32, root_child3.get_layout_left());
assert_eq!(110_f32, root_child3.get_layout_top());
assert_eq!(20_f32, root_child3.get_layout_width());
assert_eq!(90_f32, root_child3.get_layout_height());
assert_eq!(30_f32, root_child4.get_layout_left());
assert_eq!(110_f32, root_child4.get_layout_top());
assert_eq!(20_f32, root_child4.get_layout_width());
assert_eq!(90_f32, root_child4.get_layout_height());
assert_eq!(60_f32, root_child5.get_layout_left());
assert_eq!(110_f32, root_child5.get_layout_top());
assert_eq!(20_f32, root_child5.get_layout_width());
assert_eq!(90_f32, root_child5.get_layout_height());
root.calculate_layout(Undefined, Undefined, Direction::RTL);
assert_eq!(0_f32, root.get_layout_left());
assert_eq!(0_f32, root.get_layout_top());
assert_eq!(100_f32, root.get_layout_width());
assert_eq!(200_f32, root.get_layout_height());
assert_eq!(80_f32, root_child0.get_layout_left());
assert_eq!(0_f32, root_child0.get_layout_top());
assert_eq!(20_f32, root_child0.get_layout_width());
assert_eq!(90_f32, root_child0.get_layout_height());
assert_eq!(50_f32, root_child1.get_layout_left());
assert_eq!(0_f32, root_child1.get_layout_top());
assert_eq!(20_f32, root_child1.get_layout_width());
assert_eq!(90_f32, root_child1.get_layout_height());
assert_eq!(20_f32, root_child2.get_layout_left());
assert_eq!(0_f32, root_child2.get_layout_top());
assert_eq!(20_f32, root_child2.get_layout_width());
assert_eq!(90_f32, root_child2.get_layout_height());
assert_eq!(80_f32, root_child3.get_layout_left());
assert_eq!(110_f32, root_child3.get_layout_top());
assert_eq!(20_f32, root_child3.get_layout_width());
assert_eq!(90_f32, root_child3.get_layout_height());
assert_eq!(50_f32, root_child4.get_layout_left());
assert_eq!(110_f32, root_child4.get_layout_top());
assert_eq!(20_f32, root_child4.get_layout_width());
assert_eq!(90_f32, root_child4.get_layout_height());
assert_eq!(20_f32, root_child5.get_layout_left());
assert_eq!(110_f32, root_child5.get_layout_top());
assert_eq!(20_f32, root_child5.get_layout_width());
assert_eq!(90_f32, root_child5.get_layout_height());
}
#[test]
fn test_row_gap_align_items_end() {
let mut config = Config::new();
let mut root = Node::new_with_config(&mut config);
root.set_flex_direction(FlexDirection::Row);
root.set_align_items(Align::FlexEnd);
root.set_position_type(PositionType::Absolute);
root.set_flex_wrap(Wrap::Wrap);
root.set_width(StyleUnit::Point(100_f32.into()));
root.set_height(StyleUnit::Point(200_f32.into()));
root.set_gap(Gutter::Column, StyleUnit::Point(10_f32.into()));
root.set_gap(Gutter::Row, StyleUnit::Point(20_f32.into()));
let mut root_child0 = Node::new_with_config(&mut config);
root_child0.set_width(StyleUnit::Point(20_f32.into()));
root.insert_child(&mut root_child0, 0);
let mut root_child1 = Node::new_with_config(&mut config);
root_child1.set_width(StyleUnit::Point(20_f32.into()));
root.insert_child(&mut root_child1, 1);
let mut root_child2 = Node::new_with_config(&mut config);
root_child2.set_width(StyleUnit::Point(20_f32.into()));
root.insert_child(&mut root_child2, 2);
let mut root_child3 = Node::new_with_config(&mut config);
root_child3.set_width(StyleUnit::Point(20_f32.into()));
root.insert_child(&mut root_child3, 3);
let mut root_child4 = Node::new_with_config(&mut config);
root_child4.set_width(StyleUnit::Point(20_f32.into()));
root.insert_child(&mut root_child4, 4);
let mut root_child5 = Node::new_with_config(&mut config);
root_child5.set_width(StyleUnit::Point(20_f32.into()));
root.insert_child(&mut root_child5, 5);
root.calculate_layout(Undefined, Undefined, Direction::LTR);
assert_eq!(0_f32, root.get_layout_left());
assert_eq!(0_f32, root.get_layout_top());
assert_eq!(100_f32, root.get_layout_width());
assert_eq!(200_f32, root.get_layout_height());
assert_eq!(0_f32, root_child0.get_layout_left());
assert_eq!(0_f32, root_child0.get_layout_top());
assert_eq!(20_f32, root_child0.get_layout_width());
assert_eq!(0_f32, root_child0.get_layout_height());
assert_eq!(30_f32, root_child1.get_layout_left());
assert_eq!(0_f32, root_child1.get_layout_top());
assert_eq!(20_f32, root_child1.get_layout_width());
assert_eq!(0_f32, root_child1.get_layout_height());
assert_eq!(60_f32, root_child2.get_layout_left());
assert_eq!(0_f32, root_child2.get_layout_top());
assert_eq!(20_f32, root_child2.get_layout_width());
assert_eq!(0_f32, root_child2.get_layout_height());
assert_eq!(0_f32, root_child3.get_layout_left());
assert_eq!(20_f32, root_child3.get_layout_top());
assert_eq!(20_f32, root_child3.get_layout_width());
assert_eq!(0_f32, root_child3.get_layout_height());
assert_eq!(30_f32, root_child4.get_layout_left());
assert_eq!(20_f32, root_child4.get_layout_top());
assert_eq!(20_f32, root_child4.get_layout_width());
assert_eq!(0_f32, root_child4.get_layout_height());
assert_eq!(60_f32, root_child5.get_layout_left());
assert_eq!(20_f32, root_child5.get_layout_top());
assert_eq!(20_f32, root_child5.get_layout_width());
assert_eq!(0_f32, root_child5.get_layout_height());
root.calculate_layout(Undefined, Undefined, Direction::RTL);
assert_eq!(0_f32, root.get_layout_left());
assert_eq!(0_f32, root.get_layout_top());
assert_eq!(100_f32, root.get_layout_width());
assert_eq!(200_f32, root.get_layout_height());
assert_eq!(80_f32, root_child0.get_layout_left());
assert_eq!(0_f32, root_child0.get_layout_top());
assert_eq!(20_f32, root_child0.get_layout_width());
assert_eq!(0_f32, root_child0.get_layout_height());
assert_eq!(50_f32, root_child1.get_layout_left());
assert_eq!(0_f32, root_child1.get_layout_top());
assert_eq!(20_f32, root_child1.get_layout_width());
assert_eq!(0_f32, root_child1.get_layout_height());
assert_eq!(20_f32, root_child2.get_layout_left());
assert_eq!(0_f32, root_child2.get_layout_top());
assert_eq!(20_f32, root_child2.get_layout_width());
assert_eq!(0_f32, root_child2.get_layout_height());
assert_eq!(80_f32, root_child3.get_layout_left());
assert_eq!(20_f32, root_child3.get_layout_top());
assert_eq!(20_f32, root_child3.get_layout_width());
assert_eq!(0_f32, root_child3.get_layout_height());
assert_eq!(50_f32, root_child4.get_layout_left());
assert_eq!(20_f32, root_child4.get_layout_top());
assert_eq!(20_f32, root_child4.get_layout_width());
assert_eq!(0_f32, root_child4.get_layout_height());
assert_eq!(20_f32, root_child5.get_layout_left());
assert_eq!(20_f32, root_child5.get_layout_top());
assert_eq!(20_f32, root_child5.get_layout_width());
assert_eq!(0_f32, root_child5.get_layout_height());
}
#[test]
fn test_row_gap_column_child_margins() {
let mut config = Config::new();
let mut root = Node::new_with_config(&mut config);
root.set_position_type(PositionType::Absolute);
root.set_width(StyleUnit::Point(100_f32.into()));
root.set_height(StyleUnit::Point(200_f32.into()));
root.set_gap(Gutter::Row, StyleUnit::Point(10_f32.into()));
let mut root_child0 = Node::new_with_config(&mut config);
root_child0.set_flex_grow(1_f32);
root_child0.set_flex_shrink(1_f32);
root_child0.set_flex_basis(StyleUnit::Percent(0_f32.into()));
root_child0.set_margin(Edge::Top, StyleUnit::Point(2_f32.into()));
root_child0.set_margin(Edge::Bottom, StyleUnit::Point(2_f32.into()));
root.insert_child(&mut root_child0, 0);
let mut root_child1 = Node::new_with_config(&mut config);
root_child1.set_flex_grow(1_f32);
root_child1.set_flex_shrink(1_f32);
root_child1.set_flex_basis(StyleUnit::Percent(0_f32.into()));
root_child1.set_margin(Edge::Top, StyleUnit::Point(10_f32.into()));
root_child1.set_margin(Edge::Bottom, StyleUnit::Point(10_f32.into()));
root.insert_child(&mut root_child1, 1);
let mut root_child2 = Node::new_with_config(&mut config);
root_child2.set_flex_grow(1_f32);
root_child2.set_flex_shrink(1_f32);
root_child2.set_flex_basis(StyleUnit::Percent(0_f32.into()));
root_child2.set_margin(Edge::Top, StyleUnit::Point(15_f32.into()));
root_child2.set_margin(Edge::Bottom, StyleUnit::Point(15_f32.into()));
root.insert_child(&mut root_child2, 2);
root.calculate_layout(Undefined, Undefined, Direction::LTR);
assert_eq!(0_f32, root.get_layout_left());
assert_eq!(0_f32, root.get_layout_top());
assert_eq!(100_f32, root.get_layout_width());
assert_eq!(200_f32, root.get_layout_height());
assert_eq!(0_f32, root_child0.get_layout_left());
assert_eq!(2_f32, root_child0.get_layout_top());
assert_eq!(100_f32, root_child0.get_layout_width());
assert_eq!(42_f32, root_child0.get_layout_height());
assert_eq!(0_f32, root_child1.get_layout_left());
assert_eq!(66_f32, root_child1.get_layout_top());
assert_eq!(100_f32, root_child1.get_layout_width());
assert_eq!(42_f32, root_child1.get_layout_height());
assert_eq!(0_f32, root_child2.get_layout_left());
assert_eq!(143_f32, root_child2.get_layout_top());
assert_eq!(100_f32, root_child2.get_layout_width());
assert_eq!(42_f32, root_child2.get_layout_height());
root.calculate_layout(Undefined, Undefined, Direction::RTL);
assert_eq!(0_f32, root.get_layout_left());
assert_eq!(0_f32, root.get_layout_top());
assert_eq!(100_f32, root.get_layout_width());
assert_eq!(200_f32, root.get_layout_height());
assert_eq!(0_f32, root_child0.get_layout_left());
assert_eq!(2_f32, root_child0.get_layout_top());
assert_eq!(100_f32, root_child0.get_layout_width());
assert_eq!(42_f32, root_child0.get_layout_height());
assert_eq!(0_f32, root_child1.get_layout_left());
assert_eq!(66_f32, root_child1.get_layout_top());
assert_eq!(100_f32, root_child1.get_layout_width());
assert_eq!(42_f32, root_child1.get_layout_height());
assert_eq!(0_f32, root_child2.get_layout_left());
assert_eq!(143_f32, root_child2.get_layout_top());
assert_eq!(100_f32, root_child2.get_layout_width());
assert_eq!(42_f32, root_child2.get_layout_height());
}
#[test]
fn test_row_gap_row_wrap_child_margins() {
let mut config = Config::new();
let mut root = Node::new_with_config(&mut config);
root.set_flex_direction(FlexDirection::Row);
root.set_position_type(PositionType::Absolute);
root.set_flex_wrap(Wrap::Wrap);
root.set_width(StyleUnit::Point(100_f32.into()));
root.set_height(StyleUnit::Point(200_f32.into()));
root.set_gap(Gutter::Row, StyleUnit::Point(10_f32.into()));
let mut root_child0 = Node::new_with_config(&mut config);
root_child0.set_margin(Edge::Top, StyleUnit::Point(2_f32.into()));
root_child0.set_margin(Edge::Bottom, StyleUnit::Point(2_f32.into()));
root_child0.set_width(StyleUnit::Point(60_f32.into()));
root.insert_child(&mut root_child0, 0);
let mut root_child1 = Node::new_with_config(&mut config);
root_child1.set_margin(Edge::Top, StyleUnit::Point(10_f32.into()));
root_child1.set_margin(Edge::Bottom, StyleUnit::Point(10_f32.into()));
root_child1.set_width(StyleUnit::Point(60_f32.into()));
root.insert_child(&mut root_child1, 1);
let mut root_child2 = Node::new_with_config(&mut config);
root_child2.set_margin(Edge::Top, StyleUnit::Point(15_f32.into()));
root_child2.set_margin(Edge::Bottom, StyleUnit::Point(15_f32.into()));
root_child2.set_width(StyleUnit::Point(60_f32.into()));
root.insert_child(&mut root_child2, 2);
root.calculate_layout(Undefined, Undefined, Direction::LTR);
assert_eq!(0_f32, root.get_layout_left());
assert_eq!(0_f32, root.get_layout_top());
assert_eq!(100_f32, root.get_layout_width());
assert_eq!(200_f32, root.get_layout_height());
assert_eq!(0_f32, root_child0.get_layout_left());
assert_eq!(2_f32, root_child0.get_layout_top());
assert_eq!(60_f32, root_child0.get_layout_width());
assert_eq!(0_f32, root_child0.get_layout_height());
assert_eq!(0_f32, root_child1.get_layout_left());
assert_eq!(24_f32, root_child1.get_layout_top());
assert_eq!(60_f32, root_child1.get_layout_width());
assert_eq!(0_f32, root_child1.get_layout_height());
assert_eq!(0_f32, root_child2.get_layout_left());
assert_eq!(59_f32, root_child2.get_layout_top());
assert_eq!(60_f32, root_child2.get_layout_width());
assert_eq!(0_f32, root_child2.get_layout_height());
root.calculate_layout(Undefined, Undefined, Direction::RTL);
assert_eq!(0_f32, root.get_layout_left());
assert_eq!(0_f32, root.get_layout_top());
assert_eq!(100_f32, root.get_layout_width());
assert_eq!(200_f32, root.get_layout_height());
assert_eq!(40_f32, root_child0.get_layout_left());
assert_eq!(2_f32, root_child0.get_layout_top());
assert_eq!(60_f32, root_child0.get_layout_width());
assert_eq!(0_f32, root_child0.get_layout_height());
assert_eq!(40_f32, root_child1.get_layout_left());
assert_eq!(24_f32, root_child1.get_layout_top());
assert_eq!(60_f32, root_child1.get_layout_width());
assert_eq!(0_f32, root_child1.get_layout_height());
assert_eq!(40_f32, root_child2.get_layout_left());
assert_eq!(59_f32, root_child2.get_layout_top());
assert_eq!(60_f32, root_child2.get_layout_width());
assert_eq!(0_f32, root_child2.get_layout_height());
}
#[test]
fn test_row_gap_determines_parent_height() {
let mut config = Config::new();
let mut root = Node::new_with_config(&mut config);
root.set_position_type(PositionType::Absolute);
root.set_width(StyleUnit::Point(100_f32.into()));
root.set_gap(Gutter::Row, StyleUnit::Point(10_f32.into()));
let mut root_child0 = Node::new_with_config(&mut config);
root_child0.set_height(StyleUnit::Point(10_f32.into()));
root.insert_child(&mut root_child0, 0);
let mut root_child1 = Node::new_with_config(&mut config);
root_child1.set_height(StyleUnit::Point(20_f32.into()));
root.insert_child(&mut root_child1, 1);
let mut root_child2 = Node::new_with_config(&mut config);
root_child2.set_height(StyleUnit::Point(30_f32.into()));
root.insert_child(&mut root_child2, 2);
root.calculate_layout(Undefined, Undefined, Direction::LTR);
assert_eq!(0_f32, root.get_layout_left());
assert_eq!(0_f32, root.get_layout_top());
assert_eq!(100_f32, root.get_layout_width());
assert_eq!(80_f32, root.get_layout_height());
assert_eq!(0_f32, root_child0.get_layout_left());
assert_eq!(0_f32, root_child0.get_layout_top());
assert_eq!(100_f32, root_child0.get_layout_width());
assert_eq!(10_f32, root_child0.get_layout_height());
assert_eq!(0_f32, root_child1.get_layout_left());
assert_eq!(20_f32, root_child1.get_layout_top());
assert_eq!(100_f32, root_child1.get_layout_width());
assert_eq!(20_f32, root_child1.get_layout_height());
assert_eq!(0_f32, root_child2.get_layout_left());
assert_eq!(50_f32, root_child2.get_layout_top());
assert_eq!(100_f32, root_child2.get_layout_width());
assert_eq!(30_f32, root_child2.get_layout_height());
root.calculate_layout(Undefined, Undefined, Direction::RTL);
assert_eq!(0_f32, root.get_layout_left());
assert_eq!(0_f32, root.get_layout_top());
assert_eq!(100_f32, root.get_layout_width());
assert_eq!(80_f32, root.get_layout_height());
assert_eq!(0_f32, root_child0.get_layout_left());
assert_eq!(0_f32, root_child0.get_layout_top());
assert_eq!(100_f32, root_child0.get_layout_width());
assert_eq!(10_f32, root_child0.get_layout_height());
assert_eq!(0_f32, root_child1.get_layout_left());
assert_eq!(20_f32, root_child1.get_layout_top());
assert_eq!(100_f32, root_child1.get_layout_width());
assert_eq!(20_f32, root_child1.get_layout_height());
assert_eq!(0_f32, root_child2.get_layout_left());
assert_eq!(50_f32, root_child2.get_layout_top());
assert_eq!(100_f32, root_child2.get_layout_width());
assert_eq!(30_f32, root_child2.get_layout_height());
}
#[test]
fn test_row_gap_percent_wrapping() {
let mut config = Config::new();
let mut root = Node::new_with_config(&mut config);
root.set_flex_direction(FlexDirection::Row);
root.set_position_type(PositionType::Absolute);
root.set_flex_wrap(Wrap::Wrap);
root.set_padding(Edge::Left, StyleUnit::Point(10_f32.into()));
root.set_padding(Edge::Top, StyleUnit::Point(10_f32.into()));
root.set_padding(Edge::Right, StyleUnit::Point(10_f32.into()));
root.set_padding(Edge::Bottom, StyleUnit::Point(10_f32.into()));
root.set_width(StyleUnit::Point(300_f32.into()));
root.set_height(StyleUnit::Point(700_f32.into()));
root.set_gap(Gutter::Column, StyleUnit::Percent(10_f32.into()));
root.set_gap(Gutter::Row, StyleUnit::Percent(10_f32.into()));
let mut root_child0 = Node::new_with_config(&mut config);
root_child0.set_width(StyleUnit::Point(100_f32.into()));
root_child0.set_height(StyleUnit::Point(100_f32.into()));
root.insert_child(&mut root_child0, 0);
let mut root_child1 = Node::new_with_config(&mut config);
root_child1.set_width(StyleUnit::Point(100_f32.into()));
root_child1.set_height(StyleUnit::Point(100_f32.into()));
root.insert_child(&mut root_child1, 1);
let mut root_child2 = Node::new_with_config(&mut config);
root_child2.set_width(StyleUnit::Point(100_f32.into()));
root_child2.set_height(StyleUnit::Point(100_f32.into()));
root.insert_child(&mut root_child2, 2);
let mut root_child3 = Node::new_with_config(&mut config);
root_child3.set_width(StyleUnit::Point(100_f32.into()));
root_child3.set_height(StyleUnit::Point(100_f32.into()));
root.insert_child(&mut root_child3, 3);
let mut root_child4 = Node::new_with_config(&mut config);
root_child4.set_width(StyleUnit::Point(100_f32.into()));
root_child4.set_height(StyleUnit::Point(100_f32.into()));
root.insert_child(&mut root_child4, 4);
root.calculate_layout(Undefined, Undefined, Direction::LTR);
assert_eq!(0_f32, root.get_layout_left());
assert_eq!(0_f32, root.get_layout_top());
assert_eq!(300_f32, root.get_layout_width());
assert_eq!(700_f32, root.get_layout_height());
assert_eq!(10_f32, root_child0.get_layout_left());
assert_eq!(10_f32, root_child0.get_layout_top());
assert_eq!(100_f32, root_child0.get_layout_width());
assert_eq!(100_f32, root_child0.get_layout_height());
assert_eq!(138_f32, root_child1.get_layout_left());
assert_eq!(10_f32, root_child1.get_layout_top());
assert_eq!(100_f32, root_child1.get_layout_width());
assert_eq!(100_f32, root_child1.get_layout_height());
assert_eq!(10_f32, root_child2.get_layout_left());
assert_eq!(178_f32, root_child2.get_layout_top());
assert_eq!(100_f32, root_child2.get_layout_width());
assert_eq!(100_f32, root_child2.get_layout_height());
assert_eq!(138_f32, root_child3.get_layout_left());
assert_eq!(178_f32, root_child3.get_layout_top());
assert_eq!(100_f32, root_child3.get_layout_width());
assert_eq!(100_f32, root_child3.get_layout_height());
assert_eq!(10_f32, root_child4.get_layout_left());
assert_eq!(346_f32, root_child4.get_layout_top());
assert_eq!(100_f32, root_child4.get_layout_width());
assert_eq!(100_f32, root_child4.get_layout_height());
root.calculate_layout(Undefined, Undefined, Direction::RTL);
assert_eq!(0_f32, root.get_layout_left());
assert_eq!(0_f32, root.get_layout_top());
assert_eq!(300_f32, root.get_layout_width());
assert_eq!(700_f32, root.get_layout_height());
assert_eq!(190_f32, root_child0.get_layout_left());
assert_eq!(10_f32, root_child0.get_layout_top());
assert_eq!(100_f32, root_child0.get_layout_width());
assert_eq!(100_f32, root_child0.get_layout_height());
assert_eq!(62_f32, root_child1.get_layout_left());
assert_eq!(10_f32, root_child1.get_layout_top());
assert_eq!(100_f32, root_child1.get_layout_width());
assert_eq!(100_f32, root_child1.get_layout_height());
assert_eq!(190_f32, root_child2.get_layout_left());
assert_eq!(178_f32, root_child2.get_layout_top());
assert_eq!(100_f32, root_child2.get_layout_width());
assert_eq!(100_f32, root_child2.get_layout_height());
assert_eq!(62_f32, root_child3.get_layout_left());
assert_eq!(178_f32, root_child3.get_layout_top());
assert_eq!(100_f32, root_child3.get_layout_width());
assert_eq!(100_f32, root_child3.get_layout_height());
assert_eq!(190_f32, root_child4.get_layout_left());
assert_eq!(346_f32, root_child4.get_layout_top());
assert_eq!(100_f32, root_child4.get_layout_width());
assert_eq!(100_f32, root_child4.get_layout_height());
}
#[test]
fn test_row_gap_percent_determines_parent_height() {
let mut config = Config::new();
let mut root = Node::new_with_config(&mut config);
root.set_flex_direction(FlexDirection::Row);
root.set_position_type(PositionType::Absolute);
root.set_flex_wrap(Wrap::Wrap);
root.set_width(StyleUnit::Point(300_f32.into()));
root.set_gap(Gutter::Column, StyleUnit::Percent(10_f32.into()));
root.set_gap(Gutter::Row, StyleUnit::Percent(10_f32.into()));
let mut root_child0 = Node::new_with_config(&mut config);
root_child0.set_width(StyleUnit::Point(100_f32.into()));
root_child0.set_height(StyleUnit::Point(100_f32.into()));
root.insert_child(&mut root_child0, 0);
let mut root_child1 = Node::new_with_config(&mut config);
root_child1.set_width(StyleUnit::Point(100_f32.into()));
root_child1.set_height(StyleUnit::Point(100_f32.into()));
root.insert_child(&mut root_child1, 1);
let mut root_child2 = Node::new_with_config(&mut config);
root_child2.set_width(StyleUnit::Point(100_f32.into()));
root_child2.set_height(StyleUnit::Point(100_f32.into()));
root.insert_child(&mut root_child2, 2);
let mut root_child3 = Node::new_with_config(&mut config);
root_child3.set_width(StyleUnit::Point(100_f32.into()));
root_child3.set_height(StyleUnit::Point(100_f32.into()));
root.insert_child(&mut root_child3, 3);
let mut root_child4 = Node::new_with_config(&mut config);
root_child4.set_width(StyleUnit::Point(100_f32.into()));
root_child4.set_height(StyleUnit::Point(100_f32.into()));
root.insert_child(&mut root_child4, 4);
root.calculate_layout(Undefined, Undefined, Direction::LTR);
assert_eq!(0_f32, root.get_layout_left());
assert_eq!(0_f32, root.get_layout_top());
assert_eq!(300_f32, root.get_layout_width());
assert_eq!(300_f32, root.get_layout_height());
assert_eq!(0_f32, root_child0.get_layout_left());
assert_eq!(0_f32, root_child0.get_layout_top());
assert_eq!(100_f32, root_child0.get_layout_width());
assert_eq!(100_f32, root_child0.get_layout_height());
assert_eq!(130_f32, root_child1.get_layout_left());
assert_eq!(0_f32, root_child1.get_layout_top());
assert_eq!(100_f32, root_child1.get_layout_width());
assert_eq!(100_f32, root_child1.get_layout_height());
assert_eq!(0_f32, root_child2.get_layout_left());
assert_eq!(100_f32, root_child2.get_layout_top());
assert_eq!(100_f32, root_child2.get_layout_width());
assert_eq!(100_f32, root_child2.get_layout_height());
assert_eq!(130_f32, root_child3.get_layout_left());
assert_eq!(100_f32, root_child3.get_layout_top());
assert_eq!(100_f32, root_child3.get_layout_width());
assert_eq!(100_f32, root_child3.get_layout_height());
assert_eq!(0_f32, root_child4.get_layout_left());
assert_eq!(200_f32, root_child4.get_layout_top());
assert_eq!(100_f32, root_child4.get_layout_width());
assert_eq!(100_f32, root_child4.get_layout_height());
root.calculate_layout(Undefined, Undefined, Direction::RTL);
assert_eq!(0_f32, root.get_layout_left());
assert_eq!(0_f32, root.get_layout_top());
assert_eq!(300_f32, root.get_layout_width());
assert_eq!(300_f32, root.get_layout_height());
assert_eq!(200_f32, root_child0.get_layout_left());
assert_eq!(0_f32, root_child0.get_layout_top());
assert_eq!(100_f32, root_child0.get_layout_width());
assert_eq!(100_f32, root_child0.get_layout_height());
assert_eq!(70_f32, root_child1.get_layout_left());
assert_eq!(0_f32, root_child1.get_layout_top());
assert_eq!(100_f32, root_child1.get_layout_width());
assert_eq!(100_f32, root_child1.get_layout_height());
assert_eq!(200_f32, root_child2.get_layout_left());
assert_eq!(100_f32, root_child2.get_layout_top());
assert_eq!(100_f32, root_child2.get_layout_width());
assert_eq!(100_f32, root_child2.get_layout_height());
assert_eq!(70_f32, root_child3.get_layout_left());
assert_eq!(100_f32, root_child3.get_layout_top());
assert_eq!(100_f32, root_child3.get_layout_width());
assert_eq!(100_f32, root_child3.get_layout_height());
assert_eq!(200_f32, root_child4.get_layout_left());
assert_eq!(200_f32, root_child4.get_layout_top());
assert_eq!(100_f32, root_child4.get_layout_width());
assert_eq!(100_f32, root_child4.get_layout_height());
}
#[test]
fn test_row_gap_percent_wrapping_with_both_content_padding_and_item_padding() {
let mut config = Config::new();
let mut root = Node::new_with_config(&mut config);
root.set_flex_direction(FlexDirection::Row);
root.set_position_type(PositionType::Absolute);
root.set_flex_wrap(Wrap::Wrap);
root.set_padding(Edge::Left, StyleUnit::Point(10_f32.into()));
root.set_padding(Edge::Top, StyleUnit::Point(10_f32.into()));
root.set_padding(Edge::Right, StyleUnit::Point(10_f32.into()));
root.set_padding(Edge::Bottom, StyleUnit::Point(10_f32.into()));
root.set_width(StyleUnit::Point(300_f32.into()));
root.set_height(StyleUnit::Point(700_f32.into()));
root.set_gap(Gutter::Column, StyleUnit::Percent(10_f32.into()));
root.set_gap(Gutter::Row, StyleUnit::Percent(10_f32.into()));
let mut root_child0 = Node::new_with_config(&mut config);
root_child0.set_padding(Edge::Left, StyleUnit::Point(10_f32.into()));
root_child0.set_padding(Edge::Top, StyleUnit::Point(10_f32.into()));
root_child0.set_padding(Edge::Right, StyleUnit::Point(10_f32.into()));
root_child0.set_padding(Edge::Bottom, StyleUnit::Point(10_f32.into()));
root_child0.set_width(StyleUnit::Point(100_f32.into()));
root_child0.set_height(StyleUnit::Point(100_f32.into()));
root.insert_child(&mut root_child0, 0);
let mut root_child1 = Node::new_with_config(&mut config);
root_child1.set_padding(Edge::Left, StyleUnit::Point(10_f32.into()));
root_child1.set_padding(Edge::Top, StyleUnit::Point(10_f32.into()));
root_child1.set_padding(Edge::Right, StyleUnit::Point(10_f32.into()));
root_child1.set_padding(Edge::Bottom, StyleUnit::Point(10_f32.into()));
root_child1.set_width(StyleUnit::Point(100_f32.into()));
root_child1.set_height(StyleUnit::Point(100_f32.into()));
root.insert_child(&mut root_child1, 1);
let mut root_child2 = Node::new_with_config(&mut config);
root_child2.set_padding(Edge::Left, StyleUnit::Point(10_f32.into()));
root_child2.set_padding(Edge::Top, StyleUnit::Point(10_f32.into()));
root_child2.set_padding(Edge::Right, StyleUnit::Point(10_f32.into()));
root_child2.set_padding(Edge::Bottom, StyleUnit::Point(10_f32.into()));
root_child2.set_width(StyleUnit::Point(100_f32.into()));
root_child2.set_height(StyleUnit::Point(100_f32.into()));
root.insert_child(&mut root_child2, 2);
let mut root_child3 = Node::new_with_config(&mut config);
root_child3.set_padding(Edge::Left, StyleUnit::Point(10_f32.into()));
root_child3.set_padding(Edge::Top, StyleUnit::Point(10_f32.into()));
root_child3.set_padding(Edge::Right, StyleUnit::Point(10_f32.into()));
root_child3.set_padding(Edge::Bottom, StyleUnit::Point(10_f32.into()));
root_child3.set_width(StyleUnit::Point(100_f32.into()));
root_child3.set_height(StyleUnit::Point(100_f32.into()));
root.insert_child(&mut root_child3, 3);
let mut root_child4 = Node::new_with_config(&mut config);
root_child4.set_padding(Edge::Left, StyleUnit::Point(10_f32.into()));
root_child4.set_padding(Edge::Top, StyleUnit::Point(10_f32.into()));
root_child4.set_padding(Edge::Right, StyleUnit::Point(10_f32.into()));
root_child4.set_padding(Edge::Bottom, StyleUnit::Point(10_f32.into()));
root_child4.set_width(StyleUnit::Point(100_f32.into()));
root_child4.set_height(StyleUnit::Point(100_f32.into()));
root.insert_child(&mut root_child4, 4);
root.calculate_layout(Undefined, Undefined, Direction::LTR);
assert_eq!(0_f32, root.get_layout_left());
assert_eq!(0_f32, root.get_layout_top());
assert_eq!(300_f32, root.get_layout_width());
assert_eq!(700_f32, root.get_layout_height());
assert_eq!(10_f32, root_child0.get_layout_left());
assert_eq!(10_f32, root_child0.get_layout_top());
assert_eq!(100_f32, root_child0.get_layout_width());
assert_eq!(100_f32, root_child0.get_layout_height());
assert_eq!(138_f32, root_child1.get_layout_left());
assert_eq!(10_f32, root_child1.get_layout_top());
assert_eq!(100_f32, root_child1.get_layout_width());
assert_eq!(100_f32, root_child1.get_layout_height());
assert_eq!(10_f32, root_child2.get_layout_left());
assert_eq!(178_f32, root_child2.get_layout_top());
assert_eq!(100_f32, root_child2.get_layout_width());
assert_eq!(100_f32, root_child2.get_layout_height());
assert_eq!(138_f32, root_child3.get_layout_left());
assert_eq!(178_f32, root_child3.get_layout_top());
assert_eq!(100_f32, root_child3.get_layout_width());
assert_eq!(100_f32, root_child3.get_layout_height());
assert_eq!(10_f32, root_child4.get_layout_left());
assert_eq!(346_f32, root_child4.get_layout_top());
assert_eq!(100_f32, root_child4.get_layout_width());
assert_eq!(100_f32, root_child4.get_layout_height());
root.calculate_layout(Undefined, Undefined, Direction::RTL);
assert_eq!(0_f32, root.get_layout_left());
assert_eq!(0_f32, root.get_layout_top());
assert_eq!(300_f32, root.get_layout_width());
assert_eq!(700_f32, root.get_layout_height());
assert_eq!(190_f32, root_child0.get_layout_left());
assert_eq!(10_f32, root_child0.get_layout_top());
assert_eq!(100_f32, root_child0.get_layout_width());
assert_eq!(100_f32, root_child0.get_layout_height());
assert_eq!(62_f32, root_child1.get_layout_left());
assert_eq!(10_f32, root_child1.get_layout_top());
assert_eq!(100_f32, root_child1.get_layout_width());
assert_eq!(100_f32, root_child1.get_layout_height());
assert_eq!(190_f32, root_child2.get_layout_left());
assert_eq!(178_f32, root_child2.get_layout_top());
assert_eq!(100_f32, root_child2.get_layout_width());
assert_eq!(100_f32, root_child2.get_layout_height());
assert_eq!(62_f32, root_child3.get_layout_left());
assert_eq!(178_f32, root_child3.get_layout_top());
assert_eq!(100_f32, root_child3.get_layout_width());
assert_eq!(100_f32, root_child3.get_layout_height());
assert_eq!(190_f32, root_child4.get_layout_left());
assert_eq!(346_f32, root_child4.get_layout_top());
assert_eq!(100_f32, root_child4.get_layout_width());
assert_eq!(100_f32, root_child4.get_layout_height());
}
#[test]
fn test_row_gap_percent_wrapping_with_both_content_padding() {
let mut config = Config::new();
let mut root = Node::new_with_config(&mut config);
root.set_flex_direction(FlexDirection::Row);
root.set_position_type(PositionType::Absolute);
root.set_flex_wrap(Wrap::Wrap);
root.set_padding(Edge::Left, StyleUnit::Point(10_f32.into()));
root.set_padding(Edge::Top, StyleUnit::Point(10_f32.into()));
root.set_padding(Edge::Right, StyleUnit::Point(10_f32.into()));
root.set_padding(Edge::Bottom, StyleUnit::Point(10_f32.into()));
root.set_width(StyleUnit::Point(300_f32.into()));
root.set_height(StyleUnit::Point(700_f32.into()));
root.set_gap(Gutter::Column, StyleUnit::Percent(10_f32.into()));
root.set_gap(Gutter::Row, StyleUnit::Percent(10_f32.into()));
let mut root_child0 = Node::new_with_config(&mut config);
root_child0.set_width(StyleUnit::Point(100_f32.into()));
root_child0.set_height(StyleUnit::Point(100_f32.into()));
root.insert_child(&mut root_child0, 0);
let mut root_child1 = Node::new_with_config(&mut config);
root_child1.set_width(StyleUnit::Point(100_f32.into()));
root_child1.set_height(StyleUnit::Point(100_f32.into()));
root.insert_child(&mut root_child1, 1);
let mut root_child2 = Node::new_with_config(&mut config);
root_child2.set_width(StyleUnit::Point(100_f32.into()));
root_child2.set_height(StyleUnit::Point(100_f32.into()));
root.insert_child(&mut root_child2, 2);
let mut root_child3 = Node::new_with_config(&mut config);
root_child3.set_width(StyleUnit::Point(100_f32.into()));
root_child3.set_height(StyleUnit::Point(100_f32.into()));
root.insert_child(&mut root_child3, 3);
let mut root_child4 = Node::new_with_config(&mut config);
root_child4.set_width(StyleUnit::Point(100_f32.into()));
root_child4.set_height(StyleUnit::Point(100_f32.into()));
root.insert_child(&mut root_child4, 4);
root.calculate_layout(Undefined, Undefined, Direction::LTR);
assert_eq!(0_f32, root.get_layout_left());
assert_eq!(0_f32, root.get_layout_top());
assert_eq!(300_f32, root.get_layout_width());
assert_eq!(700_f32, root.get_layout_height());
assert_eq!(10_f32, root_child0.get_layout_left());
assert_eq!(10_f32, root_child0.get_layout_top());
assert_eq!(100_f32, root_child0.get_layout_width());
assert_eq!(100_f32, root_child0.get_layout_height());
assert_eq!(138_f32, root_child1.get_layout_left());
assert_eq!(10_f32, root_child1.get_layout_top());
assert_eq!(100_f32, root_child1.get_layout_width());
assert_eq!(100_f32, root_child1.get_layout_height());
assert_eq!(10_f32, root_child2.get_layout_left());
assert_eq!(178_f32, root_child2.get_layout_top());
assert_eq!(100_f32, root_child2.get_layout_width());
assert_eq!(100_f32, root_child2.get_layout_height());
assert_eq!(138_f32, root_child3.get_layout_left());
assert_eq!(178_f32, root_child3.get_layout_top());
assert_eq!(100_f32, root_child3.get_layout_width());
assert_eq!(100_f32, root_child3.get_layout_height());
assert_eq!(10_f32, root_child4.get_layout_left());
assert_eq!(346_f32, root_child4.get_layout_top());
assert_eq!(100_f32, root_child4.get_layout_width());
assert_eq!(100_f32, root_child4.get_layout_height());
root.calculate_layout(Undefined, Undefined, Direction::RTL);
assert_eq!(0_f32, root.get_layout_left());
assert_eq!(0_f32, root.get_layout_top());
assert_eq!(300_f32, root.get_layout_width());
assert_eq!(700_f32, root.get_layout_height());
assert_eq!(190_f32, root_child0.get_layout_left());
assert_eq!(10_f32, root_child0.get_layout_top());
assert_eq!(100_f32, root_child0.get_layout_width());
assert_eq!(100_f32, root_child0.get_layout_height());
assert_eq!(62_f32, root_child1.get_layout_left());
assert_eq!(10_f32, root_child1.get_layout_top());
assert_eq!(100_f32, root_child1.get_layout_width());
assert_eq!(100_f32, root_child1.get_layout_height());
assert_eq!(190_f32, root_child2.get_layout_left());
assert_eq!(178_f32, root_child2.get_layout_top());
assert_eq!(100_f32, root_child2.get_layout_width());
assert_eq!(100_f32, root_child2.get_layout_height());
assert_eq!(62_f32, root_child3.get_layout_left());
assert_eq!(178_f32, root_child3.get_layout_top());
assert_eq!(100_f32, root_child3.get_layout_width());
assert_eq!(100_f32, root_child3.get_layout_height());
assert_eq!(190_f32, root_child4.get_layout_left());
assert_eq!(346_f32, root_child4.get_layout_top());
assert_eq!(100_f32, root_child4.get_layout_width());
assert_eq!(100_f32, root_child4.get_layout_height());
}
#[test]
fn test_row_gap_percent_wrapping_with_content_margin() {
let mut config = Config::new();
let mut root = Node::new_with_config(&mut config);
root.set_flex_direction(FlexDirection::Row);
root.set_position_type(PositionType::Absolute);
root.set_flex_wrap(Wrap::Wrap);
root.set_margin(Edge::Left, StyleUnit::Point(10_f32.into()));
root.set_margin(Edge::Top, StyleUnit::Point(10_f32.into()));
root.set_margin(Edge::Right, StyleUnit::Point(10_f32.into()));
root.set_margin(Edge::Bottom, StyleUnit::Point(10_f32.into()));
root.set_width(StyleUnit::Point(300_f32.into()));
root.set_height(StyleUnit::Point(700_f32.into()));
root.set_gap(Gutter::Column, StyleUnit::Percent(10_f32.into()));
root.set_gap(Gutter::Row, StyleUnit::Percent(10_f32.into()));
let mut root_child0 = Node::new_with_config(&mut config);
root_child0.set_width(StyleUnit::Point(100_f32.into()));
root_child0.set_height(StyleUnit::Point(100_f32.into()));
root.insert_child(&mut root_child0, 0);
let mut root_child1 = Node::new_with_config(&mut config);
root_child1.set_width(StyleUnit::Point(100_f32.into()));
root_child1.set_height(StyleUnit::Point(100_f32.into()));
root.insert_child(&mut root_child1, 1);
let mut root_child2 = Node::new_with_config(&mut config);
root_child2.set_width(StyleUnit::Point(100_f32.into()));
root_child2.set_height(StyleUnit::Point(100_f32.into()));
root.insert_child(&mut root_child2, 2);
let mut root_child3 = Node::new_with_config(&mut config);
root_child3.set_width(StyleUnit::Point(100_f32.into()));
root_child3.set_height(StyleUnit::Point(100_f32.into()));
root.insert_child(&mut root_child3, 3);
let mut root_child4 = Node::new_with_config(&mut config);
root_child4.set_width(StyleUnit::Point(100_f32.into()));
root_child4.set_height(StyleUnit::Point(100_f32.into()));
root.insert_child(&mut root_child4, 4);
root.calculate_layout(Undefined, Undefined, Direction::LTR);
assert_eq!(10_f32, root.get_layout_left());
assert_eq!(10_f32, root.get_layout_top());
assert_eq!(300_f32, root.get_layout_width());
assert_eq!(700_f32, root.get_layout_height());
assert_eq!(0_f32, root_child0.get_layout_left());
assert_eq!(0_f32, root_child0.get_layout_top());
assert_eq!(100_f32, root_child0.get_layout_width());
assert_eq!(100_f32, root_child0.get_layout_height());
assert_eq!(130_f32, root_child1.get_layout_left());
assert_eq!(0_f32, root_child1.get_layout_top());
assert_eq!(100_f32, root_child1.get_layout_width());
assert_eq!(100_f32, root_child1.get_layout_height());
assert_eq!(0_f32, root_child2.get_layout_left());
assert_eq!(170_f32, root_child2.get_layout_top());
assert_eq!(100_f32, root_child2.get_layout_width());
assert_eq!(100_f32, root_child2.get_layout_height());
assert_eq!(130_f32, root_child3.get_layout_left());
assert_eq!(170_f32, root_child3.get_layout_top());
assert_eq!(100_f32, root_child3.get_layout_width());
assert_eq!(100_f32, root_child3.get_layout_height());
assert_eq!(0_f32, root_child4.get_layout_left());
assert_eq!(340_f32, root_child4.get_layout_top());
assert_eq!(100_f32, root_child4.get_layout_width());
assert_eq!(100_f32, root_child4.get_layout_height());
root.calculate_layout(Undefined, Undefined, Direction::RTL);
assert_eq!(10_f32, root.get_layout_left());
assert_eq!(10_f32, root.get_layout_top());
assert_eq!(300_f32, root.get_layout_width());
assert_eq!(700_f32, root.get_layout_height());
assert_eq!(200_f32, root_child0.get_layout_left());
assert_eq!(0_f32, root_child0.get_layout_top());
assert_eq!(100_f32, root_child0.get_layout_width());
assert_eq!(100_f32, root_child0.get_layout_height());
assert_eq!(70_f32, root_child1.get_layout_left());
assert_eq!(0_f32, root_child1.get_layout_top());
assert_eq!(100_f32, root_child1.get_layout_width());
assert_eq!(100_f32, root_child1.get_layout_height());
assert_eq!(200_f32, root_child2.get_layout_left());
assert_eq!(170_f32, root_child2.get_layout_top());
assert_eq!(100_f32, root_child2.get_layout_width());
assert_eq!(100_f32, root_child2.get_layout_height());
assert_eq!(70_f32, root_child3.get_layout_left());
assert_eq!(170_f32, root_child3.get_layout_top());
assert_eq!(100_f32, root_child3.get_layout_width());
assert_eq!(100_f32, root_child3.get_layout_height());
assert_eq!(200_f32, root_child4.get_layout_left());
assert_eq!(340_f32, root_child4.get_layout_top());
assert_eq!(100_f32, root_child4.get_layout_width());
assert_eq!(100_f32, root_child4.get_layout_height());
}
#[test]
fn test_row_gap_percent_wrapping_with_content_margin_and_padding() {
let mut config = Config::new();
let mut root = Node::new_with_config(&mut config);
root.set_flex_direction(FlexDirection::Row);
root.set_position_type(PositionType::Absolute);
root.set_flex_wrap(Wrap::Wrap);
root.set_margin(Edge::Left, StyleUnit::Point(10_f32.into()));
root.set_margin(Edge::Top, StyleUnit::Point(10_f32.into()));
root.set_margin(Edge::Right, StyleUnit::Point(10_f32.into()));
root.set_margin(Edge::Bottom, StyleUnit::Point(10_f32.into()));
root.set_padding(Edge::Left, StyleUnit::Point(10_f32.into()));
root.set_padding(Edge::Top, StyleUnit::Point(10_f32.into()));
root.set_padding(Edge::Right, StyleUnit::Point(10_f32.into()));
root.set_padding(Edge::Bottom, StyleUnit::Point(10_f32.into()));
root.set_width(StyleUnit::Point(300_f32.into()));
root.set_height(StyleUnit::Point(700_f32.into()));
root.set_gap(Gutter::Column, StyleUnit::Percent(10_f32.into()));
root.set_gap(Gutter::Row, StyleUnit::Percent(10_f32.into()));
let mut root_child0 = Node::new_with_config(&mut config);
root_child0.set_width(StyleUnit::Point(100_f32.into()));
root_child0.set_height(StyleUnit::Point(100_f32.into()));
root.insert_child(&mut root_child0, 0);
let mut root_child1 = Node::new_with_config(&mut config);
root_child1.set_width(StyleUnit::Point(100_f32.into()));
root_child1.set_height(StyleUnit::Point(100_f32.into()));
root.insert_child(&mut root_child1, 1);
let mut root_child2 = Node::new_with_config(&mut config);
root_child2.set_width(StyleUnit::Point(100_f32.into()));
root_child2.set_height(StyleUnit::Point(100_f32.into()));
root.insert_child(&mut root_child2, 2);
let mut root_child3 = Node::new_with_config(&mut config);
root_child3.set_width(StyleUnit::Point(100_f32.into()));
root_child3.set_height(StyleUnit::Point(100_f32.into()));
root.insert_child(&mut root_child3, 3);
let mut root_child4 = Node::new_with_config(&mut config);
root_child4.set_width(StyleUnit::Point(100_f32.into()));
root_child4.set_height(StyleUnit::Point(100_f32.into()));
root.insert_child(&mut root_child4, 4);
root.calculate_layout(Undefined, Undefined, Direction::LTR);
assert_eq!(10_f32, root.get_layout_left());
assert_eq!(10_f32, root.get_layout_top());
assert_eq!(300_f32, root.get_layout_width());
assert_eq!(700_f32, root.get_layout_height());
assert_eq!(10_f32, root_child0.get_layout_left());
assert_eq!(10_f32, root_child0.get_layout_top());
assert_eq!(100_f32, root_child0.get_layout_width());
assert_eq!(100_f32, root_child0.get_layout_height());
assert_eq!(138_f32, root_child1.get_layout_left());
assert_eq!(10_f32, root_child1.get_layout_top());
assert_eq!(100_f32, root_child1.get_layout_width());
assert_eq!(100_f32, root_child1.get_layout_height());
assert_eq!(10_f32, root_child2.get_layout_left());
assert_eq!(178_f32, root_child2.get_layout_top());
assert_eq!(100_f32, root_child2.get_layout_width());
assert_eq!(100_f32, root_child2.get_layout_height());
assert_eq!(138_f32, root_child3.get_layout_left());
assert_eq!(178_f32, root_child3.get_layout_top());
assert_eq!(100_f32, root_child3.get_layout_width());
assert_eq!(100_f32, root_child3.get_layout_height());
assert_eq!(10_f32, root_child4.get_layout_left());
assert_eq!(346_f32, root_child4.get_layout_top());
assert_eq!(100_f32, root_child4.get_layout_width());
assert_eq!(100_f32, root_child4.get_layout_height());
root.calculate_layout(Undefined, Undefined, Direction::RTL);
assert_eq!(10_f32, root.get_layout_left());
assert_eq!(10_f32, root.get_layout_top());
assert_eq!(300_f32, root.get_layout_width());
assert_eq!(700_f32, root.get_layout_height());
assert_eq!(190_f32, root_child0.get_layout_left());
assert_eq!(10_f32, root_child0.get_layout_top());
assert_eq!(100_f32, root_child0.get_layout_width());
assert_eq!(100_f32, root_child0.get_layout_height());
assert_eq!(62_f32, root_child1.get_layout_left());
assert_eq!(10_f32, root_child1.get_layout_top());
assert_eq!(100_f32, root_child1.get_layout_width());
assert_eq!(100_f32, root_child1.get_layout_height());
assert_eq!(190_f32, root_child2.get_layout_left());
assert_eq!(178_f32, root_child2.get_layout_top());
assert_eq!(100_f32, root_child2.get_layout_width());
assert_eq!(100_f32, root_child2.get_layout_height());
assert_eq!(62_f32, root_child3.get_layout_left());
assert_eq!(178_f32, root_child3.get_layout_top());
assert_eq!(100_f32, root_child3.get_layout_width());
assert_eq!(100_f32, root_child3.get_layout_height());
assert_eq!(190_f32, root_child4.get_layout_left());
assert_eq!(346_f32, root_child4.get_layout_top());
assert_eq!(100_f32, root_child4.get_layout_width());
assert_eq!(100_f32, root_child4.get_layout_height());
}
#[test]
fn test_row_gap_percent_wrapping_with_flexible_content() {
let mut config = Config::new();
let mut root = Node::new_with_config(&mut config);
root.set_flex_direction(FlexDirection::Row);
root.set_position_type(PositionType::Absolute);
root.set_width(StyleUnit::Point(300_f32.into()));
root.set_height(StyleUnit::Point(300_f32.into()));
root.set_gap(Gutter::Column, StyleUnit::Percent(10_f32.into()));
root.set_gap(Gutter::Row, StyleUnit::Percent(10_f32.into()));
let mut root_child0 = Node::new_with_config(&mut config);
root_child0.set_flex_grow(1_f32);
root_child0.set_flex_shrink(1_f32);
root_child0.set_flex_basis(StyleUnit::Percent(0_f32.into()));
root.insert_child(&mut root_child0, 0);
let mut root_child1 = Node::new_with_config(&mut config);
root_child1.set_flex_grow(1_f32);
root_child1.set_flex_shrink(1_f32);
root_child1.set_flex_basis(StyleUnit::Percent(0_f32.into()));
root.insert_child(&mut root_child1, 1);
let mut root_child2 = Node::new_with_config(&mut config);
root_child2.set_flex_grow(1_f32);
root_child2.set_flex_shrink(1_f32);
root_child2.set_flex_basis(StyleUnit::Percent(0_f32.into()));
root.insert_child(&mut root_child2, 2);
root.calculate_layout(Undefined, Undefined, Direction::LTR);
assert_eq!(0_f32, root.get_layout_left());
assert_eq!(0_f32, root.get_layout_top());
assert_eq!(300_f32, root.get_layout_width());
assert_eq!(300_f32, root.get_layout_height());
assert_eq!(0_f32, root_child0.get_layout_left());
assert_eq!(0_f32, root_child0.get_layout_top());
assert_eq!(80_f32, root_child0.get_layout_width());
assert_eq!(300_f32, root_child0.get_layout_height());
assert_eq!(110_f32, root_child1.get_layout_left());
assert_eq!(0_f32, root_child1.get_layout_top());
assert_eq!(80_f32, root_child1.get_layout_width());
assert_eq!(300_f32, root_child1.get_layout_height());
assert_eq!(220_f32, root_child2.get_layout_left());
assert_eq!(0_f32, root_child2.get_layout_top());
assert_eq!(80_f32, root_child2.get_layout_width());
assert_eq!(300_f32, root_child2.get_layout_height());
root.calculate_layout(Undefined, Undefined, Direction::RTL);
assert_eq!(0_f32, root.get_layout_left());
assert_eq!(0_f32, root.get_layout_top());
assert_eq!(300_f32, root.get_layout_width());
assert_eq!(300_f32, root.get_layout_height());
assert_eq!(220_f32, root_child0.get_layout_left());
assert_eq!(0_f32, root_child0.get_layout_top());
assert_eq!(80_f32, root_child0.get_layout_width());
assert_eq!(300_f32, root_child0.get_layout_height());
assert_eq!(110_f32, root_child1.get_layout_left());
assert_eq!(0_f32, root_child1.get_layout_top());
assert_eq!(80_f32, root_child1.get_layout_width());
assert_eq!(300_f32, root_child1.get_layout_height());
assert_eq!(0_f32, root_child2.get_layout_left());
assert_eq!(0_f32, root_child2.get_layout_top());
assert_eq!(80_f32, root_child2.get_layout_width());
assert_eq!(300_f32, root_child2.get_layout_height());
}
#[test]
fn test_row_gap_percent_wrapping_with_mixed_flexible_content() {
let mut config = Config::new();
let mut root = Node::new_with_config(&mut config);
root.set_flex_direction(FlexDirection::Row);
root.set_position_type(PositionType::Absolute);
root.set_width(StyleUnit::Point(300_f32.into()));
root.set_height(StyleUnit::Point(300_f32.into()));
root.set_gap(Gutter::Column, StyleUnit::Percent(10_f32.into()));
root.set_gap(Gutter::Row, StyleUnit::Percent(10_f32.into()));
let mut root_child0 = Node::new_with_config(&mut config);
root_child0.set_width(StyleUnit::Point(10_f32.into()));
root.insert_child(&mut root_child0, 0);
let mut root_child1 = Node::new_with_config(&mut config);
root_child1.set_flex_grow(1_f32);
root_child1.set_flex_shrink(1_f32);
root_child1.set_flex_basis(StyleUnit::Percent(0_f32.into()));
root.insert_child(&mut root_child1, 1);
let mut root_child2 = Node::new_with_config(&mut config);
root_child2.set_width(StyleUnit::Percent(10_f32.into()));
root.insert_child(&mut root_child2, 2);
root.calculate_layout(Undefined, Undefined, Direction::LTR);
assert_eq!(0_f32, root.get_layout_left());
assert_eq!(0_f32, root.get_layout_top());
assert_eq!(300_f32, root.get_layout_width());
assert_eq!(300_f32, root.get_layout_height());
assert_eq!(0_f32, root_child0.get_layout_left());
assert_eq!(0_f32, root_child0.get_layout_top());
assert_eq!(10_f32, root_child0.get_layout_width());
assert_eq!(300_f32, root_child0.get_layout_height());
assert_eq!(40_f32, root_child1.get_layout_left());
assert_eq!(0_f32, root_child1.get_layout_top());
assert_eq!(200_f32, root_child1.get_layout_width());
assert_eq!(300_f32, root_child1.get_layout_height());
assert_eq!(270_f32, root_child2.get_layout_left());
assert_eq!(0_f32, root_child2.get_layout_top());
assert_eq!(30_f32, root_child2.get_layout_width());
assert_eq!(300_f32, root_child2.get_layout_height());
root.calculate_layout(Undefined, Undefined, Direction::RTL);
assert_eq!(0_f32, root.get_layout_left());
assert_eq!(0_f32, root.get_layout_top());
assert_eq!(300_f32, root.get_layout_width());
assert_eq!(300_f32, root.get_layout_height());
assert_eq!(290_f32, root_child0.get_layout_left());
assert_eq!(0_f32, root_child0.get_layout_top());
assert_eq!(10_f32, root_child0.get_layout_width());
assert_eq!(300_f32, root_child0.get_layout_height());
assert_eq!(60_f32, root_child1.get_layout_left());
assert_eq!(0_f32, root_child1.get_layout_top());
assert_eq!(200_f32, root_child1.get_layout_width());
assert_eq!(300_f32, root_child1.get_layout_height());
assert_eq!(0_f32, root_child2.get_layout_left());
assert_eq!(0_f32, root_child2.get_layout_top());
assert_eq!(30_f32, root_child2.get_layout_width());
assert_eq!(300_f32, root_child2.get_layout_height());
}
#[test]
#[ignore]
fn test_row_gap_percent_wrapping_with_min_width() {
let mut config = Config::new();
let mut root = Node::new_with_config(&mut config);
root.set_flex_direction(FlexDirection::Row);
root.set_position_type(PositionType::Absolute);
root.set_flex_wrap(Wrap::Wrap);
root.set_min_width(StyleUnit::Point(300_f32.into()));
root.set_gap(Gutter::Column, StyleUnit::Percent(10_f32.into()));
root.set_gap(Gutter::Row, StyleUnit::Percent(10_f32.into()));
let mut root_child0 = Node::new_with_config(&mut config);
root_child0.set_width(StyleUnit::Point(100_f32.into()));
root_child0.set_height(StyleUnit::Point(100_f32.into()));
root.insert_child(&mut root_child0, 0);
let mut root_child1 = Node::new_with_config(&mut config);
root_child1.set_width(StyleUnit::Point(100_f32.into()));
root_child1.set_height(StyleUnit::Point(100_f32.into()));
root.insert_child(&mut root_child1, 1);
let mut root_child2 = Node::new_with_config(&mut config);
root_child2.set_width(StyleUnit::Point(100_f32.into()));
root_child2.set_height(StyleUnit::Point(100_f32.into()));
root.insert_child(&mut root_child2, 2);
let mut root_child3 = Node::new_with_config(&mut config);
root_child3.set_width(StyleUnit::Point(100_f32.into()));
root_child3.set_height(StyleUnit::Point(100_f32.into()));
root.insert_child(&mut root_child3, 3);
let mut root_child4 = Node::new_with_config(&mut config);
root_child4.set_width(StyleUnit::Point(100_f32.into()));
root_child4.set_height(StyleUnit::Point(100_f32.into()));
root.insert_child(&mut root_child4, 4);
root.calculate_layout(Undefined, Undefined, Direction::LTR);
assert_eq!(0_f32, root.get_layout_left());
assert_eq!(0_f32, root.get_layout_top());
assert_eq!(300_f32, root.get_layout_width());
assert_eq!(300_f32, root.get_layout_height());
assert_eq!(0_f32, root_child0.get_layout_left());
assert_eq!(0_f32, root_child0.get_layout_top());
assert_eq!(100_f32, root_child0.get_layout_width());
assert_eq!(100_f32, root_child0.get_layout_height());
assert_eq!(130_f32, root_child1.get_layout_left());
assert_eq!(0_f32, root_child1.get_layout_top());
assert_eq!(100_f32, root_child1.get_layout_width());
assert_eq!(100_f32, root_child1.get_layout_height());
assert_eq!(0_f32, root_child2.get_layout_left());
assert_eq!(100_f32, root_child2.get_layout_top());
assert_eq!(100_f32, root_child2.get_layout_width());
assert_eq!(100_f32, root_child2.get_layout_height());
assert_eq!(130_f32, root_child3.get_layout_left());
assert_eq!(100_f32, root_child3.get_layout_top());
assert_eq!(100_f32, root_child3.get_layout_width());
assert_eq!(100_f32, root_child3.get_layout_height());
assert_eq!(0_f32, root_child4.get_layout_left());
assert_eq!(200_f32, root_child4.get_layout_top());
assert_eq!(100_f32, root_child4.get_layout_width());
assert_eq!(100_f32, root_child4.get_layout_height());
root.calculate_layout(Undefined, Undefined, Direction::RTL);
assert_eq!(0_f32, root.get_layout_left());
assert_eq!(0_f32, root.get_layout_top());
assert_eq!(300_f32, root.get_layout_width());
assert_eq!(300_f32, root.get_layout_height());
assert_eq!(200_f32, root_child0.get_layout_left());
assert_eq!(0_f32, root_child0.get_layout_top());
assert_eq!(100_f32, root_child0.get_layout_width());
assert_eq!(100_f32, root_child0.get_layout_height());
assert_eq!(70_f32, root_child1.get_layout_left());
assert_eq!(0_f32, root_child1.get_layout_top());
assert_eq!(100_f32, root_child1.get_layout_width());
assert_eq!(100_f32, root_child1.get_layout_height());
assert_eq!(200_f32, root_child2.get_layout_left());
assert_eq!(100_f32, root_child2.get_layout_top());
assert_eq!(100_f32, root_child2.get_layout_width());
assert_eq!(100_f32, root_child2.get_layout_height());
assert_eq!(70_f32, root_child3.get_layout_left());
assert_eq!(100_f32, root_child3.get_layout_top());
assert_eq!(100_f32, root_child3.get_layout_width());
assert_eq!(100_f32, root_child3.get_layout_height());
assert_eq!(200_f32, root_child4.get_layout_left());
assert_eq!(200_f32, root_child4.get_layout_top());
assert_eq!(100_f32, root_child4.get_layout_width());
assert_eq!(100_f32, root_child4.get_layout_height());
}