/* * Copyright (c) Meta Platforms, Inc. and affiliates. * * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. */ // @generated by gentest/gentest.rb from gentest/fixtures/YGMarginTest.html extern crate ordered_float; extern crate yoga; use yoga::*; #[test] fn test_margin_start() { let mut config = Config::new(); let mut root = Node::new_with_config(&mut config); root.set_flex_direction(FlexDirection::Row); root.set_width(StyleUnit::Point(100_f32.into())); root.set_height(StyleUnit::Point(100_f32.into())); let mut root_child0 = Node::new_with_config(&mut config); root_child0.set_margin(Edge::Start, StyleUnit::Point(10_f32.into())); root_child0.set_width(StyleUnit::Point(10_f32.into())); root.insert_child(&mut root_child0, 0); 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!(10_f32, root_child0.get_layout_width()); assert_eq!(100_f32, root_child0.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!(10_f32, root_child0.get_layout_width()); assert_eq!(100_f32, root_child0.get_layout_height()); } #[test] fn test_margin_top() { let mut config = Config::new(); let mut root = Node::new_with_config(&mut config); root.set_width(StyleUnit::Point(100_f32.into())); root.set_height(StyleUnit::Point(100_f32.into())); let mut root_child0 = Node::new_with_config(&mut config); root_child0.set_margin(Edge::Top, StyleUnit::Point(10_f32.into())); root_child0.set_height(StyleUnit::Point(10_f32.into())); root.insert_child(&mut root_child0, 0); 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!(100_f32, root_child0.get_layout_width()); assert_eq!(10_f32, root_child0.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!(0_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!(10_f32, root_child0.get_layout_height()); } #[test] fn test_margin_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_width(StyleUnit::Point(100_f32.into())); root.set_height(StyleUnit::Point(100_f32.into())); let mut root_child0 = Node::new_with_config(&mut config); root_child0.set_margin(Edge::End, StyleUnit::Point(10_f32.into())); root_child0.set_width(StyleUnit::Point(10_f32.into())); root.insert_child(&mut root_child0, 0); 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!(80_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()); 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!(10_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()); } #[test] fn test_margin_bottom() { let mut config = Config::new(); let mut root = Node::new_with_config(&mut config); root.set_justify_content(Justify::FlexEnd); root.set_width(StyleUnit::Point(100_f32.into())); root.set_height(StyleUnit::Point(100_f32.into())); let mut root_child0 = Node::new_with_config(&mut config); root_child0.set_margin(Edge::Bottom, StyleUnit::Point(10_f32.into())); root_child0.set_height(StyleUnit::Point(10_f32.into())); root.insert_child(&mut root_child0, 0); 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!(80_f32, root_child0.get_layout_top()); assert_eq!(100_f32, root_child0.get_layout_width()); assert_eq!(10_f32, root_child0.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!(0_f32, root_child0.get_layout_left()); assert_eq!(80_f32, root_child0.get_layout_top()); assert_eq!(100_f32, root_child0.get_layout_width()); assert_eq!(10_f32, root_child0.get_layout_height()); } #[test] fn test_margin_and_flex_row() { let mut config = Config::new(); let mut root = Node::new_with_config(&mut config); root.set_flex_direction(FlexDirection::Row); root.set_width(StyleUnit::Point(100_f32.into())); root.set_height(StyleUnit::Point(100_f32.into())); let mut root_child0 = Node::new_with_config(&mut config); root_child0.set_flex_grow(1_f32); root_child0.set_margin(Edge::Start, StyleUnit::Point(10_f32.into())); root_child0.set_margin(Edge::End, StyleUnit::Point(10_f32.into())); root.insert_child(&mut root_child0, 0); 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!(80_f32, root_child0.get_layout_width()); assert_eq!(100_f32, root_child0.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!(10_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!(100_f32, root_child0.get_layout_height()); } #[test] fn test_margin_and_flex_column() { let mut config = Config::new(); let mut root = Node::new_with_config(&mut config); root.set_width(StyleUnit::Point(100_f32.into())); root.set_height(StyleUnit::Point(100_f32.into())); let mut root_child0 = Node::new_with_config(&mut config); root_child0.set_flex_grow(1_f32); root_child0.set_margin(Edge::Top, StyleUnit::Point(10_f32.into())); root_child0.set_margin(Edge::Bottom, StyleUnit::Point(10_f32.into())); root.insert_child(&mut root_child0, 0); 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!(100_f32, root_child0.get_layout_width()); assert_eq!(80_f32, root_child0.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!(0_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!(80_f32, root_child0.get_layout_height()); } #[test] fn test_margin_and_stretch_row() { let mut config = Config::new(); let mut root = Node::new_with_config(&mut config); root.set_flex_direction(FlexDirection::Row); root.set_width(StyleUnit::Point(100_f32.into())); root.set_height(StyleUnit::Point(100_f32.into())); let mut root_child0 = Node::new_with_config(&mut config); root_child0.set_flex_grow(1_f32); root_child0.set_margin(Edge::Top, StyleUnit::Point(10_f32.into())); root_child0.set_margin(Edge::Bottom, StyleUnit::Point(10_f32.into())); root.insert_child(&mut root_child0, 0); 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!(100_f32, root_child0.get_layout_width()); assert_eq!(80_f32, root_child0.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!(0_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!(80_f32, root_child0.get_layout_height()); } #[test] fn test_margin_and_stretch_column() { let mut config = Config::new(); let mut root = Node::new_with_config(&mut config); root.set_width(StyleUnit::Point(100_f32.into())); root.set_height(StyleUnit::Point(100_f32.into())); let mut root_child0 = Node::new_with_config(&mut config); root_child0.set_flex_grow(1_f32); root_child0.set_margin(Edge::Start, StyleUnit::Point(10_f32.into())); root_child0.set_margin(Edge::End, StyleUnit::Point(10_f32.into())); root.insert_child(&mut root_child0, 0); 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!(80_f32, root_child0.get_layout_width()); assert_eq!(100_f32, root_child0.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!(10_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!(100_f32, root_child0.get_layout_height()); } #[test] fn test_margin_with_sibling_row() { let mut config = Config::new(); let mut root = Node::new_with_config(&mut config); root.set_flex_direction(FlexDirection::Row); root.set_width(StyleUnit::Point(100_f32.into())); root.set_height(StyleUnit::Point(100_f32.into())); let mut root_child0 = Node::new_with_config(&mut config); root_child0.set_flex_grow(1_f32); root_child0.set_margin(Edge::End, 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.insert_child(&mut root_child1, 1); 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!(45_f32, root_child0.get_layout_width()); assert_eq!(100_f32, root_child0.get_layout_height()); assert_eq!(55_f32, root_child1.get_layout_left()); assert_eq!(0_f32, root_child1.get_layout_top()); assert_eq!(45_f32, root_child1.get_layout_width()); assert_eq!(100_f32, root_child1.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!(55_f32, root_child0.get_layout_left()); assert_eq!(0_f32, root_child0.get_layout_top()); assert_eq!(45_f32, root_child0.get_layout_width()); assert_eq!(100_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!(45_f32, root_child1.get_layout_width()); assert_eq!(100_f32, root_child1.get_layout_height()); } #[test] fn test_margin_with_sibling_column() { let mut config = Config::new(); let mut root = Node::new_with_config(&mut config); root.set_width(StyleUnit::Point(100_f32.into())); root.set_height(StyleUnit::Point(100_f32.into())); let mut root_child0 = Node::new_with_config(&mut config); root_child0.set_flex_grow(1_f32); root_child0.set_margin(Edge::Bottom, 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.insert_child(&mut root_child1, 1); 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!(100_f32, root_child0.get_layout_width()); assert_eq!(45_f32, root_child0.get_layout_height()); assert_eq!(0_f32, root_child1.get_layout_left()); assert_eq!(55_f32, root_child1.get_layout_top()); assert_eq!(100_f32, root_child1.get_layout_width()); assert_eq!(45_f32, root_child1.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!(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!(45_f32, root_child0.get_layout_height()); assert_eq!(0_f32, root_child1.get_layout_left()); assert_eq!(55_f32, root_child1.get_layout_top()); assert_eq!(100_f32, root_child1.get_layout_width()); assert_eq!(45_f32, root_child1.get_layout_height()); } #[test] fn test_margin_auto_bottom() { let mut config = Config::new(); let mut root = Node::new_with_config(&mut config); root.set_align_items(Align::Center); root.set_width(StyleUnit::Point(200_f32.into())); root.set_height(StyleUnit::Point(200_f32.into())); let mut root_child0 = Node::new_with_config(&mut config); root_child0.set_margin(Edge::Bottom, StyleUnit::Auto); root_child0.set_width(StyleUnit::Point(50_f32.into())); root_child0.set_height(StyleUnit::Point(50_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(50_f32.into())); root_child1.set_height(StyleUnit::Point(50_f32.into())); root.insert_child(&mut root_child1, 1); 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!(200_f32, root.get_layout_width()); assert_eq!(200_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!(50_f32, root_child0.get_layout_width()); assert_eq!(50_f32, root_child0.get_layout_height()); assert_eq!(75_f32, root_child1.get_layout_left()); assert_eq!(150_f32, root_child1.get_layout_top()); assert_eq!(50_f32, root_child1.get_layout_width()); assert_eq!(50_f32, root_child1.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!(200_f32, root.get_layout_width()); assert_eq!(200_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!(50_f32, root_child0.get_layout_width()); assert_eq!(50_f32, root_child0.get_layout_height()); assert_eq!(75_f32, root_child1.get_layout_left()); assert_eq!(150_f32, root_child1.get_layout_top()); assert_eq!(50_f32, root_child1.get_layout_width()); assert_eq!(50_f32, root_child1.get_layout_height()); } #[test] fn test_margin_auto_top() { let mut config = Config::new(); let mut root = Node::new_with_config(&mut config); root.set_align_items(Align::Center); root.set_width(StyleUnit::Point(200_f32.into())); root.set_height(StyleUnit::Point(200_f32.into())); let mut root_child0 = Node::new_with_config(&mut config); root_child0.set_margin(Edge::Top, StyleUnit::Auto); root_child0.set_width(StyleUnit::Point(50_f32.into())); root_child0.set_height(StyleUnit::Point(50_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(50_f32.into())); root_child1.set_height(StyleUnit::Point(50_f32.into())); root.insert_child(&mut root_child1, 1); 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!(200_f32, root.get_layout_width()); assert_eq!(200_f32, root.get_layout_height()); assert_eq!(75_f32, root_child0.get_layout_left()); assert_eq!(100_f32, root_child0.get_layout_top()); assert_eq!(50_f32, root_child0.get_layout_width()); assert_eq!(50_f32, root_child0.get_layout_height()); assert_eq!(75_f32, root_child1.get_layout_left()); assert_eq!(150_f32, root_child1.get_layout_top()); assert_eq!(50_f32, root_child1.get_layout_width()); assert_eq!(50_f32, root_child1.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!(200_f32, root.get_layout_width()); assert_eq!(200_f32, root.get_layout_height()); assert_eq!(75_f32, root_child0.get_layout_left()); assert_eq!(100_f32, root_child0.get_layout_top()); assert_eq!(50_f32, root_child0.get_layout_width()); assert_eq!(50_f32, root_child0.get_layout_height()); assert_eq!(75_f32, root_child1.get_layout_left()); assert_eq!(150_f32, root_child1.get_layout_top()); assert_eq!(50_f32, root_child1.get_layout_width()); assert_eq!(50_f32, root_child1.get_layout_height()); } #[test] fn test_margin_auto_bottom_and_top() { let mut config = Config::new(); let mut root = Node::new_with_config(&mut config); root.set_align_items(Align::Center); root.set_width(StyleUnit::Point(200_f32.into())); root.set_height(StyleUnit::Point(200_f32.into())); let mut root_child0 = Node::new_with_config(&mut config); root_child0.set_margin(Edge::Top, StyleUnit::Auto); root_child0.set_margin(Edge::Bottom, StyleUnit::Auto); root_child0.set_width(StyleUnit::Point(50_f32.into())); root_child0.set_height(StyleUnit::Point(50_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(50_f32.into())); root_child1.set_height(StyleUnit::Point(50_f32.into())); root.insert_child(&mut root_child1, 1); 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!(200_f32, root.get_layout_width()); assert_eq!(200_f32, root.get_layout_height()); assert_eq!(75_f32, root_child0.get_layout_left()); assert_eq!(50_f32, root_child0.get_layout_top()); assert_eq!(50_f32, root_child0.get_layout_width()); assert_eq!(50_f32, root_child0.get_layout_height()); assert_eq!(75_f32, root_child1.get_layout_left()); assert_eq!(150_f32, root_child1.get_layout_top()); assert_eq!(50_f32, root_child1.get_layout_width()); assert_eq!(50_f32, root_child1.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!(200_f32, root.get_layout_width()); assert_eq!(200_f32, root.get_layout_height()); assert_eq!(75_f32, root_child0.get_layout_left()); assert_eq!(50_f32, root_child0.get_layout_top()); assert_eq!(50_f32, root_child0.get_layout_width()); assert_eq!(50_f32, root_child0.get_layout_height()); assert_eq!(75_f32, root_child1.get_layout_left()); assert_eq!(150_f32, root_child1.get_layout_top()); assert_eq!(50_f32, root_child1.get_layout_width()); assert_eq!(50_f32, root_child1.get_layout_height()); } #[test] fn test_margin_auto_bottom_and_top_justify_center() { let mut config = Config::new(); let mut root = Node::new_with_config(&mut config); root.set_justify_content(Justify::Center); root.set_width(StyleUnit::Point(200_f32.into())); root.set_height(StyleUnit::Point(200_f32.into())); let mut root_child0 = Node::new_with_config(&mut config); root_child0.set_margin(Edge::Top, StyleUnit::Auto); root_child0.set_margin(Edge::Bottom, StyleUnit::Auto); root_child0.set_width(StyleUnit::Point(50_f32.into())); root_child0.set_height(StyleUnit::Point(50_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(50_f32.into())); root_child1.set_height(StyleUnit::Point(50_f32.into())); root.insert_child(&mut root_child1, 1); 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!(200_f32, root.get_layout_width()); assert_eq!(200_f32, root.get_layout_height()); assert_eq!(0_f32, root_child0.get_layout_left()); assert_eq!(50_f32, root_child0.get_layout_top()); assert_eq!(50_f32, root_child0.get_layout_width()); assert_eq!(50_f32, root_child0.get_layout_height()); assert_eq!(0_f32, root_child1.get_layout_left()); assert_eq!(150_f32, root_child1.get_layout_top()); assert_eq!(50_f32, root_child1.get_layout_width()); assert_eq!(50_f32, root_child1.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!(200_f32, root.get_layout_width()); assert_eq!(200_f32, root.get_layout_height()); assert_eq!(150_f32, root_child0.get_layout_left()); assert_eq!(50_f32, root_child0.get_layout_top()); assert_eq!(50_f32, root_child0.get_layout_width()); assert_eq!(50_f32, root_child0.get_layout_height()); assert_eq!(150_f32, root_child1.get_layout_left()); assert_eq!(150_f32, root_child1.get_layout_top()); assert_eq!(50_f32, root_child1.get_layout_width()); assert_eq!(50_f32, root_child1.get_layout_height()); } #[test] fn test_margin_auto_mutiple_children_column() { let mut config = Config::new(); let mut root = Node::new_with_config(&mut config); root.set_align_items(Align::Center); root.set_width(StyleUnit::Point(200_f32.into())); root.set_height(StyleUnit::Point(200_f32.into())); let mut root_child0 = Node::new_with_config(&mut config); root_child0.set_margin(Edge::Top, StyleUnit::Auto); root_child0.set_width(StyleUnit::Point(50_f32.into())); root_child0.set_height(StyleUnit::Point(50_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::Auto); root_child1.set_width(StyleUnit::Point(50_f32.into())); root_child1.set_height(StyleUnit::Point(50_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(50_f32.into())); root_child2.set_height(StyleUnit::Point(50_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!(200_f32, root.get_layout_width()); assert_eq!(200_f32, root.get_layout_height()); assert_eq!(75_f32, root_child0.get_layout_left()); assert_eq!(25_f32, root_child0.get_layout_top()); assert_eq!(50_f32, root_child0.get_layout_width()); assert_eq!(50_f32, root_child0.get_layout_height()); assert_eq!(75_f32, root_child1.get_layout_left()); assert_eq!(100_f32, root_child1.get_layout_top()); assert_eq!(50_f32, root_child1.get_layout_width()); assert_eq!(50_f32, root_child1.get_layout_height()); assert_eq!(75_f32, root_child2.get_layout_left()); assert_eq!(150_f32, root_child2.get_layout_top()); assert_eq!(50_f32, root_child2.get_layout_width()); assert_eq!(50_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!(200_f32, root.get_layout_width()); assert_eq!(200_f32, root.get_layout_height()); assert_eq!(75_f32, root_child0.get_layout_left()); assert_eq!(25_f32, root_child0.get_layout_top()); assert_eq!(50_f32, root_child0.get_layout_width()); assert_eq!(50_f32, root_child0.get_layout_height()); assert_eq!(75_f32, root_child1.get_layout_left()); assert_eq!(100_f32, root_child1.get_layout_top()); assert_eq!(50_f32, root_child1.get_layout_width()); assert_eq!(50_f32, root_child1.get_layout_height()); assert_eq!(75_f32, root_child2.get_layout_left()); assert_eq!(150_f32, root_child2.get_layout_top()); assert_eq!(50_f32, root_child2.get_layout_width()); assert_eq!(50_f32, root_child2.get_layout_height()); } #[test] fn test_margin_auto_mutiple_children_row() { 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::Center); root.set_width(StyleUnit::Point(200_f32.into())); root.set_height(StyleUnit::Point(200_f32.into())); let mut root_child0 = Node::new_with_config(&mut config); root_child0.set_margin(Edge::Right, StyleUnit::Auto); root_child0.set_width(StyleUnit::Point(50_f32.into())); root_child0.set_height(StyleUnit::Point(50_f32.into())); root.insert_child(&mut root_child0, 0); let mut root_child1 = Node::new_with_config(&mut config); root_child1.set_margin(Edge::Right, StyleUnit::Auto); root_child1.set_width(StyleUnit::Point(50_f32.into())); root_child1.set_height(StyleUnit::Point(50_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(50_f32.into())); root_child2.set_height(StyleUnit::Point(50_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!(200_f32, root.get_layout_width()); assert_eq!(200_f32, root.get_layout_height()); assert_eq!(0_f32, root_child0.get_layout_left()); assert_eq!(75_f32, root_child0.get_layout_top()); assert_eq!(50_f32, root_child0.get_layout_width()); assert_eq!(50_f32, root_child0.get_layout_height()); assert_eq!(75_f32, root_child1.get_layout_left()); assert_eq!(75_f32, root_child1.get_layout_top()); assert_eq!(50_f32, root_child1.get_layout_width()); assert_eq!(50_f32, root_child1.get_layout_height()); assert_eq!(150_f32, root_child2.get_layout_left()); assert_eq!(75_f32, root_child2.get_layout_top()); assert_eq!(50_f32, root_child2.get_layout_width()); assert_eq!(50_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!(200_f32, root.get_layout_width()); assert_eq!(200_f32, root.get_layout_height()); assert_eq!(125_f32, root_child0.get_layout_left()); assert_eq!(75_f32, root_child0.get_layout_top()); assert_eq!(50_f32, root_child0.get_layout_width()); assert_eq!(50_f32, root_child0.get_layout_height()); assert_eq!(50_f32, root_child1.get_layout_left()); assert_eq!(75_f32, root_child1.get_layout_top()); assert_eq!(50_f32, root_child1.get_layout_width()); assert_eq!(50_f32, root_child1.get_layout_height()); assert_eq!(0_f32, root_child2.get_layout_left()); assert_eq!(75_f32, root_child2.get_layout_top()); assert_eq!(50_f32, root_child2.get_layout_width()); assert_eq!(50_f32, root_child2.get_layout_height()); } #[test] fn test_margin_auto_left_and_right_column() { 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::Center); root.set_width(StyleUnit::Point(200_f32.into())); root.set_height(StyleUnit::Point(200_f32.into())); let mut root_child0 = Node::new_with_config(&mut config); root_child0.set_margin(Edge::Left, StyleUnit::Auto); root_child0.set_margin(Edge::Right, StyleUnit::Auto); root_child0.set_width(StyleUnit::Point(50_f32.into())); root_child0.set_height(StyleUnit::Point(50_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(50_f32.into())); root_child1.set_height(StyleUnit::Point(50_f32.into())); root.insert_child(&mut root_child1, 1); 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!(200_f32, root.get_layout_width()); assert_eq!(200_f32, root.get_layout_height()); assert_eq!(50_f32, root_child0.get_layout_left()); assert_eq!(75_f32, root_child0.get_layout_top()); assert_eq!(50_f32, root_child0.get_layout_width()); assert_eq!(50_f32, root_child0.get_layout_height()); assert_eq!(150_f32, root_child1.get_layout_left()); assert_eq!(75_f32, root_child1.get_layout_top()); assert_eq!(50_f32, root_child1.get_layout_width()); assert_eq!(50_f32, root_child1.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!(200_f32, root.get_layout_width()); assert_eq!(200_f32, root.get_layout_height()); assert_eq!(100_f32, root_child0.get_layout_left()); assert_eq!(75_f32, root_child0.get_layout_top()); assert_eq!(50_f32, root_child0.get_layout_width()); assert_eq!(50_f32, root_child0.get_layout_height()); assert_eq!(0_f32, root_child1.get_layout_left()); assert_eq!(75_f32, root_child1.get_layout_top()); assert_eq!(50_f32, root_child1.get_layout_width()); assert_eq!(50_f32, root_child1.get_layout_height()); } #[test] fn test_margin_auto_left_and_right() { let mut config = Config::new(); let mut root = Node::new_with_config(&mut config); root.set_width(StyleUnit::Point(200_f32.into())); root.set_height(StyleUnit::Point(200_f32.into())); let mut root_child0 = Node::new_with_config(&mut config); root_child0.set_margin(Edge::Left, StyleUnit::Auto); root_child0.set_margin(Edge::Right, StyleUnit::Auto); root_child0.set_width(StyleUnit::Point(50_f32.into())); root_child0.set_height(StyleUnit::Point(50_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(50_f32.into())); root_child1.set_height(StyleUnit::Point(50_f32.into())); root.insert_child(&mut root_child1, 1); 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!(200_f32, root.get_layout_width()); assert_eq!(200_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!(50_f32, root_child0.get_layout_width()); assert_eq!(50_f32, root_child0.get_layout_height()); assert_eq!(0_f32, root_child1.get_layout_left()); assert_eq!(50_f32, root_child1.get_layout_top()); assert_eq!(50_f32, root_child1.get_layout_width()); assert_eq!(50_f32, root_child1.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!(200_f32, root.get_layout_width()); assert_eq!(200_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!(50_f32, root_child0.get_layout_width()); assert_eq!(50_f32, root_child0.get_layout_height()); assert_eq!(150_f32, root_child1.get_layout_left()); assert_eq!(50_f32, root_child1.get_layout_top()); assert_eq!(50_f32, root_child1.get_layout_width()); assert_eq!(50_f32, root_child1.get_layout_height()); } #[test] fn test_margin_auto_start_and_end_column() { 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::Center); root.set_width(StyleUnit::Point(200_f32.into())); root.set_height(StyleUnit::Point(200_f32.into())); let mut root_child0 = Node::new_with_config(&mut config); root_child0.set_margin(Edge::Start, StyleUnit::Auto); root_child0.set_margin(Edge::End, StyleUnit::Auto); root_child0.set_width(StyleUnit::Point(50_f32.into())); root_child0.set_height(StyleUnit::Point(50_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(50_f32.into())); root_child1.set_height(StyleUnit::Point(50_f32.into())); root.insert_child(&mut root_child1, 1); 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!(200_f32, root.get_layout_width()); assert_eq!(200_f32, root.get_layout_height()); assert_eq!(50_f32, root_child0.get_layout_left()); assert_eq!(75_f32, root_child0.get_layout_top()); assert_eq!(50_f32, root_child0.get_layout_width()); assert_eq!(50_f32, root_child0.get_layout_height()); assert_eq!(150_f32, root_child1.get_layout_left()); assert_eq!(75_f32, root_child1.get_layout_top()); assert_eq!(50_f32, root_child1.get_layout_width()); assert_eq!(50_f32, root_child1.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!(200_f32, root.get_layout_width()); assert_eq!(200_f32, root.get_layout_height()); assert_eq!(100_f32, root_child0.get_layout_left()); assert_eq!(75_f32, root_child0.get_layout_top()); assert_eq!(50_f32, root_child0.get_layout_width()); assert_eq!(50_f32, root_child0.get_layout_height()); assert_eq!(0_f32, root_child1.get_layout_left()); assert_eq!(75_f32, root_child1.get_layout_top()); assert_eq!(50_f32, root_child1.get_layout_width()); assert_eq!(50_f32, root_child1.get_layout_height()); } #[test] fn test_margin_auto_start_and_end() { let mut config = Config::new(); let mut root = Node::new_with_config(&mut config); root.set_width(StyleUnit::Point(200_f32.into())); root.set_height(StyleUnit::Point(200_f32.into())); let mut root_child0 = Node::new_with_config(&mut config); root_child0.set_margin(Edge::Start, StyleUnit::Auto); root_child0.set_margin(Edge::End, StyleUnit::Auto); root_child0.set_width(StyleUnit::Point(50_f32.into())); root_child0.set_height(StyleUnit::Point(50_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(50_f32.into())); root_child1.set_height(StyleUnit::Point(50_f32.into())); root.insert_child(&mut root_child1, 1); 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!(200_f32, root.get_layout_width()); assert_eq!(200_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!(50_f32, root_child0.get_layout_width()); assert_eq!(50_f32, root_child0.get_layout_height()); assert_eq!(0_f32, root_child1.get_layout_left()); assert_eq!(50_f32, root_child1.get_layout_top()); assert_eq!(50_f32, root_child1.get_layout_width()); assert_eq!(50_f32, root_child1.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!(200_f32, root.get_layout_width()); assert_eq!(200_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!(50_f32, root_child0.get_layout_width()); assert_eq!(50_f32, root_child0.get_layout_height()); assert_eq!(150_f32, root_child1.get_layout_left()); assert_eq!(50_f32, root_child1.get_layout_top()); assert_eq!(50_f32, root_child1.get_layout_width()); assert_eq!(50_f32, root_child1.get_layout_height()); } #[test] fn test_margin_auto_left_and_right_column_and_center() { let mut config = Config::new(); let mut root = Node::new_with_config(&mut config); root.set_align_items(Align::Center); root.set_width(StyleUnit::Point(200_f32.into())); root.set_height(StyleUnit::Point(200_f32.into())); let mut root_child0 = Node::new_with_config(&mut config); root_child0.set_margin(Edge::Left, StyleUnit::Auto); root_child0.set_margin(Edge::Right, StyleUnit::Auto); root_child0.set_width(StyleUnit::Point(50_f32.into())); root_child0.set_height(StyleUnit::Point(50_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(50_f32.into())); root_child1.set_height(StyleUnit::Point(50_f32.into())); root.insert_child(&mut root_child1, 1); 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!(200_f32, root.get_layout_width()); assert_eq!(200_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!(50_f32, root_child0.get_layout_width()); assert_eq!(50_f32, root_child0.get_layout_height()); assert_eq!(75_f32, root_child1.get_layout_left()); assert_eq!(50_f32, root_child1.get_layout_top()); assert_eq!(50_f32, root_child1.get_layout_width()); assert_eq!(50_f32, root_child1.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!(200_f32, root.get_layout_width()); assert_eq!(200_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!(50_f32, root_child0.get_layout_width()); assert_eq!(50_f32, root_child0.get_layout_height()); assert_eq!(75_f32, root_child1.get_layout_left()); assert_eq!(50_f32, root_child1.get_layout_top()); assert_eq!(50_f32, root_child1.get_layout_width()); assert_eq!(50_f32, root_child1.get_layout_height()); } #[test] fn test_margin_auto_left() { let mut config = Config::new(); let mut root = Node::new_with_config(&mut config); root.set_align_items(Align::Center); root.set_width(StyleUnit::Point(200_f32.into())); root.set_height(StyleUnit::Point(200_f32.into())); let mut root_child0 = Node::new_with_config(&mut config); root_child0.set_margin(Edge::Left, StyleUnit::Auto); root_child0.set_width(StyleUnit::Point(50_f32.into())); root_child0.set_height(StyleUnit::Point(50_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(50_f32.into())); root_child1.set_height(StyleUnit::Point(50_f32.into())); root.insert_child(&mut root_child1, 1); 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!(200_f32, root.get_layout_width()); assert_eq!(200_f32, root.get_layout_height()); assert_eq!(150_f32, root_child0.get_layout_left()); assert_eq!(0_f32, root_child0.get_layout_top()); assert_eq!(50_f32, root_child0.get_layout_width()); assert_eq!(50_f32, root_child0.get_layout_height()); assert_eq!(75_f32, root_child1.get_layout_left()); assert_eq!(50_f32, root_child1.get_layout_top()); assert_eq!(50_f32, root_child1.get_layout_width()); assert_eq!(50_f32, root_child1.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!(200_f32, root.get_layout_width()); assert_eq!(200_f32, root.get_layout_height()); assert_eq!(150_f32, root_child0.get_layout_left()); assert_eq!(0_f32, root_child0.get_layout_top()); assert_eq!(50_f32, root_child0.get_layout_width()); assert_eq!(50_f32, root_child0.get_layout_height()); assert_eq!(75_f32, root_child1.get_layout_left()); assert_eq!(50_f32, root_child1.get_layout_top()); assert_eq!(50_f32, root_child1.get_layout_width()); assert_eq!(50_f32, root_child1.get_layout_height()); } #[test] fn test_margin_auto_right() { let mut config = Config::new(); let mut root = Node::new_with_config(&mut config); root.set_align_items(Align::Center); root.set_width(StyleUnit::Point(200_f32.into())); root.set_height(StyleUnit::Point(200_f32.into())); let mut root_child0 = Node::new_with_config(&mut config); root_child0.set_margin(Edge::Right, StyleUnit::Auto); root_child0.set_width(StyleUnit::Point(50_f32.into())); root_child0.set_height(StyleUnit::Point(50_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(50_f32.into())); root_child1.set_height(StyleUnit::Point(50_f32.into())); root.insert_child(&mut root_child1, 1); 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!(200_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!(50_f32, root_child0.get_layout_width()); assert_eq!(50_f32, root_child0.get_layout_height()); assert_eq!(75_f32, root_child1.get_layout_left()); assert_eq!(50_f32, root_child1.get_layout_top()); assert_eq!(50_f32, root_child1.get_layout_width()); assert_eq!(50_f32, root_child1.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!(200_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!(50_f32, root_child0.get_layout_width()); assert_eq!(50_f32, root_child0.get_layout_height()); assert_eq!(75_f32, root_child1.get_layout_left()); assert_eq!(50_f32, root_child1.get_layout_top()); assert_eq!(50_f32, root_child1.get_layout_width()); assert_eq!(50_f32, root_child1.get_layout_height()); } #[test] fn test_margin_auto_left_and_right_stretch() { let mut config = Config::new(); let mut root = Node::new_with_config(&mut config); root.set_flex_direction(FlexDirection::Row); root.set_width(StyleUnit::Point(200_f32.into())); root.set_height(StyleUnit::Point(200_f32.into())); let mut root_child0 = Node::new_with_config(&mut config); root_child0.set_margin(Edge::Left, StyleUnit::Auto); root_child0.set_margin(Edge::Right, StyleUnit::Auto); root_child0.set_width(StyleUnit::Point(50_f32.into())); root_child0.set_height(StyleUnit::Point(50_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(50_f32.into())); root_child1.set_height(StyleUnit::Point(50_f32.into())); root.insert_child(&mut root_child1, 1); 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!(200_f32, root.get_layout_width()); assert_eq!(200_f32, root.get_layout_height()); assert_eq!(50_f32, root_child0.get_layout_left()); assert_eq!(0_f32, root_child0.get_layout_top()); assert_eq!(50_f32, root_child0.get_layout_width()); assert_eq!(50_f32, root_child0.get_layout_height()); assert_eq!(150_f32, root_child1.get_layout_left()); assert_eq!(0_f32, root_child1.get_layout_top()); assert_eq!(50_f32, root_child1.get_layout_width()); assert_eq!(50_f32, root_child1.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!(200_f32, root.get_layout_width()); assert_eq!(200_f32, root.get_layout_height()); assert_eq!(100_f32, root_child0.get_layout_left()); assert_eq!(0_f32, root_child0.get_layout_top()); assert_eq!(50_f32, root_child0.get_layout_width()); assert_eq!(50_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!(50_f32, root_child1.get_layout_width()); assert_eq!(50_f32, root_child1.get_layout_height()); } #[test] fn test_margin_auto_top_and_bottom_stretch() { let mut config = Config::new(); let mut root = Node::new_with_config(&mut config); root.set_width(StyleUnit::Point(200_f32.into())); root.set_height(StyleUnit::Point(200_f32.into())); let mut root_child0 = Node::new_with_config(&mut config); root_child0.set_margin(Edge::Top, StyleUnit::Auto); root_child0.set_margin(Edge::Bottom, StyleUnit::Auto); root_child0.set_width(StyleUnit::Point(50_f32.into())); root_child0.set_height(StyleUnit::Point(50_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(50_f32.into())); root_child1.set_height(StyleUnit::Point(50_f32.into())); root.insert_child(&mut root_child1, 1); 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!(200_f32, root.get_layout_width()); assert_eq!(200_f32, root.get_layout_height()); assert_eq!(0_f32, root_child0.get_layout_left()); assert_eq!(50_f32, root_child0.get_layout_top()); assert_eq!(50_f32, root_child0.get_layout_width()); assert_eq!(50_f32, root_child0.get_layout_height()); assert_eq!(0_f32, root_child1.get_layout_left()); assert_eq!(150_f32, root_child1.get_layout_top()); assert_eq!(50_f32, root_child1.get_layout_width()); assert_eq!(50_f32, root_child1.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!(200_f32, root.get_layout_width()); assert_eq!(200_f32, root.get_layout_height()); assert_eq!(150_f32, root_child0.get_layout_left()); assert_eq!(50_f32, root_child0.get_layout_top()); assert_eq!(50_f32, root_child0.get_layout_width()); assert_eq!(50_f32, root_child0.get_layout_height()); assert_eq!(150_f32, root_child1.get_layout_left()); assert_eq!(150_f32, root_child1.get_layout_top()); assert_eq!(50_f32, root_child1.get_layout_width()); assert_eq!(50_f32, root_child1.get_layout_height()); } #[test] fn test_margin_should_not_be_part_of_max_height() { let mut config = Config::new(); let mut root = Node::new_with_config(&mut config); root.set_width(StyleUnit::Point(250_f32.into())); root.set_height(StyleUnit::Point(250_f32.into())); let mut root_child0 = Node::new_with_config(&mut config); root_child0.set_margin(Edge::Top, StyleUnit::Point(20_f32.into())); root_child0.set_width(StyleUnit::Point(100_f32.into())); root_child0.set_height(StyleUnit::Point(100_f32.into())); root_child0.set_max_height(StyleUnit::Point(100_f32.into())); root.insert_child(&mut root_child0, 0); 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!(250_f32, root.get_layout_width()); assert_eq!(250_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!(100_f32, root_child0.get_layout_width()); assert_eq!(100_f32, root_child0.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!(250_f32, root.get_layout_width()); assert_eq!(250_f32, root.get_layout_height()); assert_eq!(150_f32, root_child0.get_layout_left()); assert_eq!(20_f32, root_child0.get_layout_top()); assert_eq!(100_f32, root_child0.get_layout_width()); assert_eq!(100_f32, root_child0.get_layout_height()); } #[test] fn test_margin_should_not_be_part_of_max_width() { let mut config = Config::new(); let mut root = Node::new_with_config(&mut config); root.set_width(StyleUnit::Point(250_f32.into())); root.set_height(StyleUnit::Point(250_f32.into())); let mut root_child0 = Node::new_with_config(&mut config); root_child0.set_margin(Edge::Left, StyleUnit::Point(20_f32.into())); root_child0.set_width(StyleUnit::Point(100_f32.into())); root_child0.set_max_width(StyleUnit::Point(100_f32.into())); root_child0.set_height(StyleUnit::Point(100_f32.into())); root.insert_child(&mut root_child0, 0); 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!(250_f32, root.get_layout_width()); assert_eq!(250_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!(100_f32, root_child0.get_layout_width()); assert_eq!(100_f32, root_child0.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!(250_f32, root.get_layout_width()); assert_eq!(250_f32, root.get_layout_height()); assert_eq!(150_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()); } #[test] fn test_margin_auto_left_right_child_bigger_than_parent() { let mut config = Config::new(); let mut root = Node::new_with_config(&mut config); root.set_justify_content(Justify::Center); root.set_width(StyleUnit::Point(52_f32.into())); root.set_height(StyleUnit::Point(52_f32.into())); let mut root_child0 = Node::new_with_config(&mut config); root_child0.set_margin(Edge::Left, StyleUnit::Auto); root_child0.set_margin(Edge::Right, StyleUnit::Auto); root_child0.set_width(StyleUnit::Point(72_f32.into())); root_child0.set_height(StyleUnit::Point(72_f32.into())); root.insert_child(&mut root_child0, 0); 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!(52_f32, root.get_layout_width()); assert_eq!(52_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!(72_f32, root_child0.get_layout_width()); assert_eq!(72_f32, root_child0.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!(52_f32, root.get_layout_width()); assert_eq!(52_f32, root.get_layout_height()); assert_eq!(-20_f32, root_child0.get_layout_left()); assert_eq!(-10_f32, root_child0.get_layout_top()); assert_eq!(72_f32, root_child0.get_layout_width()); assert_eq!(72_f32, root_child0.get_layout_height()); } #[test] fn test_margin_auto_left_child_bigger_than_parent() { let mut config = Config::new(); let mut root = Node::new_with_config(&mut config); root.set_justify_content(Justify::Center); root.set_width(StyleUnit::Point(52_f32.into())); root.set_height(StyleUnit::Point(52_f32.into())); let mut root_child0 = Node::new_with_config(&mut config); root_child0.set_margin(Edge::Left, StyleUnit::Auto); root_child0.set_width(StyleUnit::Point(72_f32.into())); root_child0.set_height(StyleUnit::Point(72_f32.into())); root.insert_child(&mut root_child0, 0); 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!(52_f32, root.get_layout_width()); assert_eq!(52_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!(72_f32, root_child0.get_layout_width()); assert_eq!(72_f32, root_child0.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!(52_f32, root.get_layout_width()); assert_eq!(52_f32, root.get_layout_height()); assert_eq!(-20_f32, root_child0.get_layout_left()); assert_eq!(-10_f32, root_child0.get_layout_top()); assert_eq!(72_f32, root_child0.get_layout_width()); assert_eq!(72_f32, root_child0.get_layout_height()); } #[test] fn test_margin_fix_left_auto_right_child_bigger_than_parent() { let mut config = Config::new(); let mut root = Node::new_with_config(&mut config); root.set_justify_content(Justify::Center); root.set_width(StyleUnit::Point(52_f32.into())); root.set_height(StyleUnit::Point(52_f32.into())); let mut root_child0 = Node::new_with_config(&mut config); root_child0.set_margin(Edge::Left, StyleUnit::Point(10_f32.into())); root_child0.set_margin(Edge::Right, StyleUnit::Auto); root_child0.set_width(StyleUnit::Point(72_f32.into())); root_child0.set_height(StyleUnit::Point(72_f32.into())); root.insert_child(&mut root_child0, 0); 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!(52_f32, root.get_layout_width()); assert_eq!(52_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!(72_f32, root_child0.get_layout_width()); assert_eq!(72_f32, root_child0.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!(52_f32, root.get_layout_width()); assert_eq!(52_f32, root.get_layout_height()); assert_eq!(-20_f32, root_child0.get_layout_left()); assert_eq!(-10_f32, root_child0.get_layout_top()); assert_eq!(72_f32, root_child0.get_layout_width()); assert_eq!(72_f32, root_child0.get_layout_height()); } #[test] fn test_margin_auto_left_fix_right_child_bigger_than_parent() { let mut config = Config::new(); let mut root = Node::new_with_config(&mut config); root.set_justify_content(Justify::Center); root.set_width(StyleUnit::Point(52_f32.into())); root.set_height(StyleUnit::Point(52_f32.into())); let mut root_child0 = Node::new_with_config(&mut config); root_child0.set_margin(Edge::Left, StyleUnit::Auto); root_child0.set_margin(Edge::Right, StyleUnit::Point(10_f32.into())); root_child0.set_width(StyleUnit::Point(72_f32.into())); root_child0.set_height(StyleUnit::Point(72_f32.into())); root.insert_child(&mut root_child0, 0); 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!(52_f32, root.get_layout_width()); assert_eq!(52_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!(72_f32, root_child0.get_layout_width()); assert_eq!(72_f32, root_child0.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!(52_f32, root.get_layout_width()); assert_eq!(52_f32, root.get_layout_height()); assert_eq!(-30_f32, root_child0.get_layout_left()); assert_eq!(-10_f32, root_child0.get_layout_top()); assert_eq!(72_f32, root_child0.get_layout_width()); assert_eq!(72_f32, root_child0.get_layout_height()); } #[test] fn test_margin_auto_top_stretching_child() { let mut config = Config::new(); let mut root = Node::new_with_config(&mut config); root.set_align_items(Align::Center); root.set_width(StyleUnit::Point(200_f32.into())); root.set_height(StyleUnit::Point(200_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::Auto); root.insert_child(&mut root_child0, 0); let mut root_child1 = Node::new_with_config(&mut config); root_child1.set_width(StyleUnit::Point(50_f32.into())); root_child1.set_height(StyleUnit::Point(50_f32.into())); root.insert_child(&mut root_child1, 1); 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!(200_f32, root.get_layout_width()); assert_eq!(200_f32, root.get_layout_height()); assert_eq!(100_f32, root_child0.get_layout_left()); assert_eq!(0_f32, root_child0.get_layout_top()); assert_eq!(0_f32, root_child0.get_layout_width()); assert_eq!(150_f32, root_child0.get_layout_height()); assert_eq!(75_f32, root_child1.get_layout_left()); assert_eq!(150_f32, root_child1.get_layout_top()); assert_eq!(50_f32, root_child1.get_layout_width()); assert_eq!(50_f32, root_child1.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!(200_f32, root.get_layout_width()); assert_eq!(200_f32, root.get_layout_height()); assert_eq!(100_f32, root_child0.get_layout_left()); assert_eq!(0_f32, root_child0.get_layout_top()); assert_eq!(0_f32, root_child0.get_layout_width()); assert_eq!(150_f32, root_child0.get_layout_height()); assert_eq!(75_f32, root_child1.get_layout_left()); assert_eq!(150_f32, root_child1.get_layout_top()); assert_eq!(50_f32, root_child1.get_layout_width()); assert_eq!(50_f32, root_child1.get_layout_height()); } #[test] fn test_margin_auto_left_stretching_child() { let mut config = Config::new(); let mut root = Node::new_with_config(&mut config); root.set_align_items(Align::Center); root.set_width(StyleUnit::Point(200_f32.into())); root.set_height(StyleUnit::Point(200_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::Auto); root.insert_child(&mut root_child0, 0); let mut root_child1 = Node::new_with_config(&mut config); root_child1.set_width(StyleUnit::Point(50_f32.into())); root_child1.set_height(StyleUnit::Point(50_f32.into())); root.insert_child(&mut root_child1, 1); 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!(200_f32, root.get_layout_width()); assert_eq!(200_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!(0_f32, root_child0.get_layout_width()); assert_eq!(150_f32, root_child0.get_layout_height()); assert_eq!(75_f32, root_child1.get_layout_left()); assert_eq!(150_f32, root_child1.get_layout_top()); assert_eq!(50_f32, root_child1.get_layout_width()); assert_eq!(50_f32, root_child1.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!(200_f32, root.get_layout_width()); assert_eq!(200_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!(0_f32, root_child0.get_layout_width()); assert_eq!(150_f32, root_child0.get_layout_height()); assert_eq!(75_f32, root_child1.get_layout_left()); assert_eq!(150_f32, root_child1.get_layout_top()); assert_eq!(50_f32, root_child1.get_layout_width()); assert_eq!(50_f32, root_child1.get_layout_height()); }