/* * 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/YGAlignItemsTest.html extern crate ordered_float; extern crate yoga; use yoga::*; #[test] fn test_align_items_stretch() { 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_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!(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()); 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!(10_f32, root_child0.get_layout_height()); } #[test] fn test_align_items_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(100_f32.into())); root.set_height(StyleUnit::Point(100_f32.into())); let mut root_child0 = Node::new_with_config(&mut config); root_child0.set_width(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!(45_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!(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!(45_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!(10_f32, root_child0.get_layout_height()); } #[test] fn test_align_items_flex_start() { let mut config = Config::new(); let mut root = Node::new_with_config(&mut config); root.set_align_items(Align::FlexStart); 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_width(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!(0_f32, root_child0.get_layout_top()); assert_eq!(10_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!(90_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!(10_f32, root_child0.get_layout_height()); } #[test] fn test_align_items_flex_end() { let mut config = Config::new(); let mut root = Node::new_with_config(&mut config); root.set_align_items(Align::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_width(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!(90_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!(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!(0_f32, root_child0.get_layout_top()); assert_eq!(10_f32, root_child0.get_layout_width()); assert_eq!(10_f32, root_child0.get_layout_height()); } #[test] fn test_align_baseline() { 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::Baseline); 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_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(20_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!(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!(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!(30_f32, root_child1.get_layout_top()); assert_eq!(50_f32, root_child1.get_layout_width()); assert_eq!(20_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!(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!(0_f32, root_child1.get_layout_left()); assert_eq!(30_f32, root_child1.get_layout_top()); assert_eq!(50_f32, root_child1.get_layout_width()); assert_eq!(20_f32, root_child1.get_layout_height()); } #[test] fn test_align_baseline_child() { 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::Baseline); 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_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(20_f32.into())); root.insert_child(&mut root_child1, 1); let mut root_child1_child0 = Node::new_with_config(&mut config); root_child1_child0.set_width(StyleUnit::Point(50_f32.into())); root_child1_child0.set_height(StyleUnit::Point(10_f32.into())); root_child1.insert_child(&mut root_child1_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!(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!(50_f32, root_child1.get_layout_left()); assert_eq!(40_f32, root_child1.get_layout_top()); assert_eq!(50_f32, root_child1.get_layout_width()); assert_eq!(20_f32, root_child1.get_layout_height()); assert_eq!(0_f32, root_child1_child0.get_layout_left()); assert_eq!(0_f32, root_child1_child0.get_layout_top()); assert_eq!(50_f32, root_child1_child0.get_layout_width()); assert_eq!(10_f32, root_child1_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!(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!(0_f32, root_child1.get_layout_left()); assert_eq!(40_f32, root_child1.get_layout_top()); assert_eq!(50_f32, root_child1.get_layout_width()); assert_eq!(20_f32, root_child1.get_layout_height()); assert_eq!(0_f32, root_child1_child0.get_layout_left()); assert_eq!(0_f32, root_child1_child0.get_layout_top()); assert_eq!(50_f32, root_child1_child0.get_layout_width()); assert_eq!(10_f32, root_child1_child0.get_layout_height()); } #[test] fn test_align_baseline_child_multiline() { 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::Baseline); 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_width(StyleUnit::Point(50_f32.into())); root_child0.set_height(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_direction(FlexDirection::Row); root_child1.set_flex_wrap(Wrap::Wrap); root_child1.set_width(StyleUnit::Point(50_f32.into())); root_child1.set_height(StyleUnit::Point(25_f32.into())); root.insert_child(&mut root_child1, 1); let mut root_child1_child0 = Node::new_with_config(&mut config); root_child1_child0.set_width(StyleUnit::Point(25_f32.into())); root_child1_child0.set_height(StyleUnit::Point(20_f32.into())); root_child1.insert_child(&mut root_child1_child0, 0); let mut root_child1_child1 = Node::new_with_config(&mut config); root_child1_child1.set_width(StyleUnit::Point(25_f32.into())); root_child1_child1.set_height(StyleUnit::Point(10_f32.into())); root_child1.insert_child(&mut root_child1_child1, 1); let mut root_child1_child2 = Node::new_with_config(&mut config); root_child1_child2.set_width(StyleUnit::Point(25_f32.into())); root_child1_child2.set_height(StyleUnit::Point(20_f32.into())); root_child1.insert_child(&mut root_child1_child2, 2); let mut root_child1_child3 = Node::new_with_config(&mut config); root_child1_child3.set_width(StyleUnit::Point(25_f32.into())); root_child1_child3.set_height(StyleUnit::Point(10_f32.into())); root_child1.insert_child(&mut root_child1_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!(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!(50_f32, root_child0.get_layout_width()); assert_eq!(60_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!(50_f32, root_child1.get_layout_width()); assert_eq!(25_f32, root_child1.get_layout_height()); assert_eq!(0_f32, root_child1_child0.get_layout_left()); assert_eq!(0_f32, root_child1_child0.get_layout_top()); assert_eq!(25_f32, root_child1_child0.get_layout_width()); assert_eq!(20_f32, root_child1_child0.get_layout_height()); assert_eq!(25_f32, root_child1_child1.get_layout_left()); assert_eq!(0_f32, root_child1_child1.get_layout_top()); assert_eq!(25_f32, root_child1_child1.get_layout_width()); assert_eq!(10_f32, root_child1_child1.get_layout_height()); assert_eq!(0_f32, root_child1_child2.get_layout_left()); assert_eq!(20_f32, root_child1_child2.get_layout_top()); assert_eq!(25_f32, root_child1_child2.get_layout_width()); assert_eq!(20_f32, root_child1_child2.get_layout_height()); assert_eq!(25_f32, root_child1_child3.get_layout_left()); assert_eq!(20_f32, root_child1_child3.get_layout_top()); assert_eq!(25_f32, root_child1_child3.get_layout_width()); assert_eq!(10_f32, root_child1_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!(100_f32, root.get_layout_width()); assert_eq!(100_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!(60_f32, root_child0.get_layout_height()); assert_eq!(0_f32, root_child1.get_layout_left()); assert_eq!(40_f32, root_child1.get_layout_top()); assert_eq!(50_f32, root_child1.get_layout_width()); assert_eq!(25_f32, root_child1.get_layout_height()); assert_eq!(25_f32, root_child1_child0.get_layout_left()); assert_eq!(0_f32, root_child1_child0.get_layout_top()); assert_eq!(25_f32, root_child1_child0.get_layout_width()); assert_eq!(20_f32, root_child1_child0.get_layout_height()); assert_eq!(0_f32, root_child1_child1.get_layout_left()); assert_eq!(0_f32, root_child1_child1.get_layout_top()); assert_eq!(25_f32, root_child1_child1.get_layout_width()); assert_eq!(10_f32, root_child1_child1.get_layout_height()); assert_eq!(25_f32, root_child1_child2.get_layout_left()); assert_eq!(20_f32, root_child1_child2.get_layout_top()); assert_eq!(25_f32, root_child1_child2.get_layout_width()); assert_eq!(20_f32, root_child1_child2.get_layout_height()); assert_eq!(0_f32, root_child1_child3.get_layout_left()); assert_eq!(20_f32, root_child1_child3.get_layout_top()); assert_eq!(25_f32, root_child1_child3.get_layout_width()); assert_eq!(10_f32, root_child1_child3.get_layout_height()); } #[test] fn test_align_baseline_child_multiline_override() { 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::Baseline); 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_width(StyleUnit::Point(50_f32.into())); root_child0.set_height(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_direction(FlexDirection::Row); root_child1.set_flex_wrap(Wrap::Wrap); root_child1.set_width(StyleUnit::Point(50_f32.into())); root_child1.set_height(StyleUnit::Point(25_f32.into())); root.insert_child(&mut root_child1, 1); let mut root_child1_child0 = Node::new_with_config(&mut config); root_child1_child0.set_width(StyleUnit::Point(25_f32.into())); root_child1_child0.set_height(StyleUnit::Point(20_f32.into())); root_child1.insert_child(&mut root_child1_child0, 0); let mut root_child1_child1 = Node::new_with_config(&mut config); root_child1_child1.set_align_self(Align::Baseline); root_child1_child1.set_width(StyleUnit::Point(25_f32.into())); root_child1_child1.set_height(StyleUnit::Point(10_f32.into())); root_child1.insert_child(&mut root_child1_child1, 1); let mut root_child1_child2 = Node::new_with_config(&mut config); root_child1_child2.set_width(StyleUnit::Point(25_f32.into())); root_child1_child2.set_height(StyleUnit::Point(20_f32.into())); root_child1.insert_child(&mut root_child1_child2, 2); let mut root_child1_child3 = Node::new_with_config(&mut config); root_child1_child3.set_align_self(Align::Baseline); root_child1_child3.set_width(StyleUnit::Point(25_f32.into())); root_child1_child3.set_height(StyleUnit::Point(10_f32.into())); root_child1.insert_child(&mut root_child1_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!(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!(50_f32, root_child0.get_layout_width()); assert_eq!(60_f32, root_child0.get_layout_height()); assert_eq!(50_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!(25_f32, root_child1.get_layout_height()); assert_eq!(0_f32, root_child1_child0.get_layout_left()); assert_eq!(0_f32, root_child1_child0.get_layout_top()); assert_eq!(25_f32, root_child1_child0.get_layout_width()); assert_eq!(20_f32, root_child1_child0.get_layout_height()); assert_eq!(25_f32, root_child1_child1.get_layout_left()); assert_eq!(0_f32, root_child1_child1.get_layout_top()); assert_eq!(25_f32, root_child1_child1.get_layout_width()); assert_eq!(10_f32, root_child1_child1.get_layout_height()); assert_eq!(0_f32, root_child1_child2.get_layout_left()); assert_eq!(20_f32, root_child1_child2.get_layout_top()); assert_eq!(25_f32, root_child1_child2.get_layout_width()); assert_eq!(20_f32, root_child1_child2.get_layout_height()); assert_eq!(25_f32, root_child1_child3.get_layout_left()); assert_eq!(20_f32, root_child1_child3.get_layout_top()); assert_eq!(25_f32, root_child1_child3.get_layout_width()); assert_eq!(10_f32, root_child1_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!(100_f32, root.get_layout_width()); assert_eq!(100_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!(60_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!(25_f32, root_child1.get_layout_height()); assert_eq!(25_f32, root_child1_child0.get_layout_left()); assert_eq!(0_f32, root_child1_child0.get_layout_top()); assert_eq!(25_f32, root_child1_child0.get_layout_width()); assert_eq!(20_f32, root_child1_child0.get_layout_height()); assert_eq!(0_f32, root_child1_child1.get_layout_left()); assert_eq!(0_f32, root_child1_child1.get_layout_top()); assert_eq!(25_f32, root_child1_child1.get_layout_width()); assert_eq!(10_f32, root_child1_child1.get_layout_height()); assert_eq!(25_f32, root_child1_child2.get_layout_left()); assert_eq!(20_f32, root_child1_child2.get_layout_top()); assert_eq!(25_f32, root_child1_child2.get_layout_width()); assert_eq!(20_f32, root_child1_child2.get_layout_height()); assert_eq!(0_f32, root_child1_child3.get_layout_left()); assert_eq!(20_f32, root_child1_child3.get_layout_top()); assert_eq!(25_f32, root_child1_child3.get_layout_width()); assert_eq!(10_f32, root_child1_child3.get_layout_height()); } #[test] fn test_align_baseline_child_multiline_no_override_on_secondline() { 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::Baseline); 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_width(StyleUnit::Point(50_f32.into())); root_child0.set_height(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_direction(FlexDirection::Row); root_child1.set_flex_wrap(Wrap::Wrap); root_child1.set_width(StyleUnit::Point(50_f32.into())); root_child1.set_height(StyleUnit::Point(25_f32.into())); root.insert_child(&mut root_child1, 1); let mut root_child1_child0 = Node::new_with_config(&mut config); root_child1_child0.set_width(StyleUnit::Point(25_f32.into())); root_child1_child0.set_height(StyleUnit::Point(20_f32.into())); root_child1.insert_child(&mut root_child1_child0, 0); let mut root_child1_child1 = Node::new_with_config(&mut config); root_child1_child1.set_width(StyleUnit::Point(25_f32.into())); root_child1_child1.set_height(StyleUnit::Point(10_f32.into())); root_child1.insert_child(&mut root_child1_child1, 1); let mut root_child1_child2 = Node::new_with_config(&mut config); root_child1_child2.set_width(StyleUnit::Point(25_f32.into())); root_child1_child2.set_height(StyleUnit::Point(20_f32.into())); root_child1.insert_child(&mut root_child1_child2, 2); let mut root_child1_child3 = Node::new_with_config(&mut config); root_child1_child3.set_align_self(Align::Baseline); root_child1_child3.set_width(StyleUnit::Point(25_f32.into())); root_child1_child3.set_height(StyleUnit::Point(10_f32.into())); root_child1.insert_child(&mut root_child1_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!(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!(50_f32, root_child0.get_layout_width()); assert_eq!(60_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!(50_f32, root_child1.get_layout_width()); assert_eq!(25_f32, root_child1.get_layout_height()); assert_eq!(0_f32, root_child1_child0.get_layout_left()); assert_eq!(0_f32, root_child1_child0.get_layout_top()); assert_eq!(25_f32, root_child1_child0.get_layout_width()); assert_eq!(20_f32, root_child1_child0.get_layout_height()); assert_eq!(25_f32, root_child1_child1.get_layout_left()); assert_eq!(0_f32, root_child1_child1.get_layout_top()); assert_eq!(25_f32, root_child1_child1.get_layout_width()); assert_eq!(10_f32, root_child1_child1.get_layout_height()); assert_eq!(0_f32, root_child1_child2.get_layout_left()); assert_eq!(20_f32, root_child1_child2.get_layout_top()); assert_eq!(25_f32, root_child1_child2.get_layout_width()); assert_eq!(20_f32, root_child1_child2.get_layout_height()); assert_eq!(25_f32, root_child1_child3.get_layout_left()); assert_eq!(20_f32, root_child1_child3.get_layout_top()); assert_eq!(25_f32, root_child1_child3.get_layout_width()); assert_eq!(10_f32, root_child1_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!(100_f32, root.get_layout_width()); assert_eq!(100_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!(60_f32, root_child0.get_layout_height()); assert_eq!(0_f32, root_child1.get_layout_left()); assert_eq!(40_f32, root_child1.get_layout_top()); assert_eq!(50_f32, root_child1.get_layout_width()); assert_eq!(25_f32, root_child1.get_layout_height()); assert_eq!(25_f32, root_child1_child0.get_layout_left()); assert_eq!(0_f32, root_child1_child0.get_layout_top()); assert_eq!(25_f32, root_child1_child0.get_layout_width()); assert_eq!(20_f32, root_child1_child0.get_layout_height()); assert_eq!(0_f32, root_child1_child1.get_layout_left()); assert_eq!(0_f32, root_child1_child1.get_layout_top()); assert_eq!(25_f32, root_child1_child1.get_layout_width()); assert_eq!(10_f32, root_child1_child1.get_layout_height()); assert_eq!(25_f32, root_child1_child2.get_layout_left()); assert_eq!(20_f32, root_child1_child2.get_layout_top()); assert_eq!(25_f32, root_child1_child2.get_layout_width()); assert_eq!(20_f32, root_child1_child2.get_layout_height()); assert_eq!(0_f32, root_child1_child3.get_layout_left()); assert_eq!(20_f32, root_child1_child3.get_layout_top()); assert_eq!(25_f32, root_child1_child3.get_layout_width()); assert_eq!(10_f32, root_child1_child3.get_layout_height()); } #[test] fn test_align_baseline_child_top() { 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::Baseline); 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_position(Edge::Top, StyleUnit::Point(10_f32.into())); 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(20_f32.into())); root.insert_child(&mut root_child1, 1); let mut root_child1_child0 = Node::new_with_config(&mut config); root_child1_child0.set_width(StyleUnit::Point(50_f32.into())); root_child1_child0.set_height(StyleUnit::Point(10_f32.into())); root_child1.insert_child(&mut root_child1_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!(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!(40_f32, root_child1.get_layout_top()); assert_eq!(50_f32, root_child1.get_layout_width()); assert_eq!(20_f32, root_child1.get_layout_height()); assert_eq!(0_f32, root_child1_child0.get_layout_left()); assert_eq!(0_f32, root_child1_child0.get_layout_top()); assert_eq!(50_f32, root_child1_child0.get_layout_width()); assert_eq!(10_f32, root_child1_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!(50_f32, root_child0.get_layout_left()); assert_eq!(10_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!(40_f32, root_child1.get_layout_top()); assert_eq!(50_f32, root_child1.get_layout_width()); assert_eq!(20_f32, root_child1.get_layout_height()); assert_eq!(0_f32, root_child1_child0.get_layout_left()); assert_eq!(0_f32, root_child1_child0.get_layout_top()); assert_eq!(50_f32, root_child1_child0.get_layout_width()); assert_eq!(10_f32, root_child1_child0.get_layout_height()); } #[test] fn test_align_baseline_child_top2() { 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::Baseline); 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_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_position(Edge::Top, StyleUnit::Point(5_f32.into())); root_child1.set_width(StyleUnit::Point(50_f32.into())); root_child1.set_height(StyleUnit::Point(20_f32.into())); root.insert_child(&mut root_child1, 1); let mut root_child1_child0 = Node::new_with_config(&mut config); root_child1_child0.set_width(StyleUnit::Point(50_f32.into())); root_child1_child0.set_height(StyleUnit::Point(10_f32.into())); root_child1.insert_child(&mut root_child1_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!(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!(50_f32, root_child1.get_layout_left()); assert_eq!(45_f32, root_child1.get_layout_top()); assert_eq!(50_f32, root_child1.get_layout_width()); assert_eq!(20_f32, root_child1.get_layout_height()); assert_eq!(0_f32, root_child1_child0.get_layout_left()); assert_eq!(0_f32, root_child1_child0.get_layout_top()); assert_eq!(50_f32, root_child1_child0.get_layout_width()); assert_eq!(10_f32, root_child1_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!(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!(0_f32, root_child1.get_layout_left()); assert_eq!(45_f32, root_child1.get_layout_top()); assert_eq!(50_f32, root_child1.get_layout_width()); assert_eq!(20_f32, root_child1.get_layout_height()); assert_eq!(0_f32, root_child1_child0.get_layout_left()); assert_eq!(0_f32, root_child1_child0.get_layout_top()); assert_eq!(50_f32, root_child1_child0.get_layout_width()); assert_eq!(10_f32, root_child1_child0.get_layout_height()); } #[test] fn test_align_baseline_double_nested_child() { 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::Baseline); 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_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_child0_child0 = Node::new_with_config(&mut config); root_child0_child0.set_width(StyleUnit::Point(50_f32.into())); root_child0_child0.set_height(StyleUnit::Point(20_f32.into())); root_child0.insert_child(&mut root_child0_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(20_f32.into())); root.insert_child(&mut root_child1, 1); let mut root_child1_child0 = Node::new_with_config(&mut config); root_child1_child0.set_width(StyleUnit::Point(50_f32.into())); root_child1_child0.set_height(StyleUnit::Point(15_f32.into())); root_child1.insert_child(&mut root_child1_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!(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_child0_child0.get_layout_left()); assert_eq!(0_f32, root_child0_child0.get_layout_top()); assert_eq!(50_f32, root_child0_child0.get_layout_width()); assert_eq!(20_f32, root_child0_child0.get_layout_height()); assert_eq!(50_f32, root_child1.get_layout_left()); assert_eq!(5_f32, root_child1.get_layout_top()); assert_eq!(50_f32, root_child1.get_layout_width()); assert_eq!(20_f32, root_child1.get_layout_height()); assert_eq!(0_f32, root_child1_child0.get_layout_left()); assert_eq!(0_f32, root_child1_child0.get_layout_top()); assert_eq!(50_f32, root_child1_child0.get_layout_width()); assert_eq!(15_f32, root_child1_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!(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!(0_f32, root_child0_child0.get_layout_left()); assert_eq!(0_f32, root_child0_child0.get_layout_top()); assert_eq!(50_f32, root_child0_child0.get_layout_width()); assert_eq!(20_f32, root_child0_child0.get_layout_height()); assert_eq!(0_f32, root_child1.get_layout_left()); assert_eq!(5_f32, root_child1.get_layout_top()); assert_eq!(50_f32, root_child1.get_layout_width()); assert_eq!(20_f32, root_child1.get_layout_height()); assert_eq!(0_f32, root_child1_child0.get_layout_left()); assert_eq!(0_f32, root_child1_child0.get_layout_top()); assert_eq!(50_f32, root_child1_child0.get_layout_width()); assert_eq!(15_f32, root_child1_child0.get_layout_height()); } #[test] fn test_align_baseline_column() { let mut config = Config::new(); let mut root = Node::new_with_config(&mut config); root.set_align_items(Align::Baseline); 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_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(20_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!(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!(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!(20_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!(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!(50_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!(20_f32, root_child1.get_layout_height()); } #[test] fn test_align_baseline_child_margin() { 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::Baseline); 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::Left, StyleUnit::Point(5_f32.into())); root_child0.set_margin(Edge::Top, StyleUnit::Point(5_f32.into())); root_child0.set_margin(Edge::Right, StyleUnit::Point(5_f32.into())); root_child0.set_margin(Edge::Bottom, StyleUnit::Point(5_f32.into())); 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(20_f32.into())); root.insert_child(&mut root_child1, 1); let mut root_child1_child0 = Node::new_with_config(&mut config); root_child1_child0.set_margin(Edge::Left, StyleUnit::Point(1_f32.into())); root_child1_child0.set_margin(Edge::Top, StyleUnit::Point(1_f32.into())); root_child1_child0.set_margin(Edge::Right, StyleUnit::Point(1_f32.into())); root_child1_child0.set_margin(Edge::Bottom, StyleUnit::Point(1_f32.into())); root_child1_child0.set_width(StyleUnit::Point(50_f32.into())); root_child1_child0.set_height(StyleUnit::Point(10_f32.into())); root_child1.insert_child(&mut root_child1_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!(5_f32, root_child0.get_layout_left()); assert_eq!(5_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!(60_f32, root_child1.get_layout_left()); assert_eq!(44_f32, root_child1.get_layout_top()); assert_eq!(50_f32, root_child1.get_layout_width()); assert_eq!(20_f32, root_child1.get_layout_height()); assert_eq!(1_f32, root_child1_child0.get_layout_left()); assert_eq!(1_f32, root_child1_child0.get_layout_top()); assert_eq!(50_f32, root_child1_child0.get_layout_width()); assert_eq!(10_f32, root_child1_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!(45_f32, root_child0.get_layout_left()); assert_eq!(5_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!(-10_f32, root_child1.get_layout_left()); assert_eq!(44_f32, root_child1.get_layout_top()); assert_eq!(50_f32, root_child1.get_layout_width()); assert_eq!(20_f32, root_child1.get_layout_height()); assert_eq!(-1_f32, root_child1_child0.get_layout_left()); assert_eq!(1_f32, root_child1_child0.get_layout_top()); assert_eq!(50_f32, root_child1_child0.get_layout_width()); assert_eq!(10_f32, root_child1_child0.get_layout_height()); } #[test] fn test_align_baseline_child_padding() { 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::Baseline); root.set_padding(Edge::Left, StyleUnit::Point(5_f32.into())); root.set_padding(Edge::Top, StyleUnit::Point(5_f32.into())); root.set_padding(Edge::Right, StyleUnit::Point(5_f32.into())); root.set_padding(Edge::Bottom, StyleUnit::Point(5_f32.into())); 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_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_padding(Edge::Left, StyleUnit::Point(5_f32.into())); root_child1.set_padding(Edge::Top, StyleUnit::Point(5_f32.into())); root_child1.set_padding(Edge::Right, StyleUnit::Point(5_f32.into())); root_child1.set_padding(Edge::Bottom, StyleUnit::Point(5_f32.into())); root_child1.set_width(StyleUnit::Point(50_f32.into())); root_child1.set_height(StyleUnit::Point(20_f32.into())); root.insert_child(&mut root_child1, 1); let mut root_child1_child0 = Node::new_with_config(&mut config); root_child1_child0.set_width(StyleUnit::Point(50_f32.into())); root_child1_child0.set_height(StyleUnit::Point(10_f32.into())); root_child1.insert_child(&mut root_child1_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!(5_f32, root_child0.get_layout_left()); assert_eq!(5_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!(55_f32, root_child1.get_layout_left()); assert_eq!(40_f32, root_child1.get_layout_top()); assert_eq!(50_f32, root_child1.get_layout_width()); assert_eq!(20_f32, root_child1.get_layout_height()); assert_eq!(5_f32, root_child1_child0.get_layout_left()); assert_eq!(5_f32, root_child1_child0.get_layout_top()); assert_eq!(50_f32, root_child1_child0.get_layout_width()); assert_eq!(10_f32, root_child1_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!(45_f32, root_child0.get_layout_left()); assert_eq!(5_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!(-5_f32, root_child1.get_layout_left()); assert_eq!(40_f32, root_child1.get_layout_top()); assert_eq!(50_f32, root_child1.get_layout_width()); assert_eq!(20_f32, root_child1.get_layout_height()); assert_eq!(-5_f32, root_child1_child0.get_layout_left()); assert_eq!(5_f32, root_child1_child0.get_layout_top()); assert_eq!(50_f32, root_child1_child0.get_layout_width()); assert_eq!(10_f32, root_child1_child0.get_layout_height()); } #[test] fn test_align_baseline_multiline() { 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::Baseline); root.set_flex_wrap(Wrap::Wrap); 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_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(20_f32.into())); root.insert_child(&mut root_child1, 1); let mut root_child1_child0 = Node::new_with_config(&mut config); root_child1_child0.set_width(StyleUnit::Point(50_f32.into())); root_child1_child0.set_height(StyleUnit::Point(10_f32.into())); root_child1.insert_child(&mut root_child1_child0, 0); 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(20_f32.into())); root.insert_child(&mut root_child2, 2); let mut root_child2_child0 = Node::new_with_config(&mut config); root_child2_child0.set_width(StyleUnit::Point(50_f32.into())); root_child2_child0.set_height(StyleUnit::Point(10_f32.into())); root_child2.insert_child(&mut root_child2_child0, 0); let mut root_child3 = Node::new_with_config(&mut config); root_child3.set_width(StyleUnit::Point(50_f32.into())); root_child3.set_height(StyleUnit::Point(50_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!(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!(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!(40_f32, root_child1.get_layout_top()); assert_eq!(50_f32, root_child1.get_layout_width()); assert_eq!(20_f32, root_child1.get_layout_height()); assert_eq!(0_f32, root_child1_child0.get_layout_left()); assert_eq!(0_f32, root_child1_child0.get_layout_top()); assert_eq!(50_f32, root_child1_child0.get_layout_width()); assert_eq!(10_f32, root_child1_child0.get_layout_height()); assert_eq!(0_f32, root_child2.get_layout_left()); assert_eq!(100_f32, root_child2.get_layout_top()); assert_eq!(50_f32, root_child2.get_layout_width()); assert_eq!(20_f32, root_child2.get_layout_height()); assert_eq!(0_f32, root_child2_child0.get_layout_left()); assert_eq!(0_f32, root_child2_child0.get_layout_top()); assert_eq!(50_f32, root_child2_child0.get_layout_width()); assert_eq!(10_f32, root_child2_child0.get_layout_height()); assert_eq!(50_f32, root_child3.get_layout_left()); assert_eq!(60_f32, root_child3.get_layout_top()); assert_eq!(50_f32, root_child3.get_layout_width()); assert_eq!(50_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!(100_f32, root.get_layout_width()); assert_eq!(100_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!(0_f32, root_child1.get_layout_left()); assert_eq!(40_f32, root_child1.get_layout_top()); assert_eq!(50_f32, root_child1.get_layout_width()); assert_eq!(20_f32, root_child1.get_layout_height()); assert_eq!(0_f32, root_child1_child0.get_layout_left()); assert_eq!(0_f32, root_child1_child0.get_layout_top()); assert_eq!(50_f32, root_child1_child0.get_layout_width()); assert_eq!(10_f32, root_child1_child0.get_layout_height()); assert_eq!(50_f32, root_child2.get_layout_left()); assert_eq!(100_f32, root_child2.get_layout_top()); assert_eq!(50_f32, root_child2.get_layout_width()); assert_eq!(20_f32, root_child2.get_layout_height()); assert_eq!(0_f32, root_child2_child0.get_layout_left()); assert_eq!(0_f32, root_child2_child0.get_layout_top()); assert_eq!(50_f32, root_child2_child0.get_layout_width()); assert_eq!(10_f32, root_child2_child0.get_layout_height()); assert_eq!(0_f32, root_child3.get_layout_left()); assert_eq!(60_f32, root_child3.get_layout_top()); assert_eq!(50_f32, root_child3.get_layout_width()); assert_eq!(50_f32, root_child3.get_layout_height()); } // WARNING: The expected values for this test have been manually overridden to match // those from upstream Yoga (which were presumably generated at an earlier point in time // when Chrome's behaviour on this test was different). This should be overwritten by // regenerating the gentests once upstream Yoga supports this functionality properly. #[test] fn test_align_baseline_multiline_column() { let mut config = Config::new(); let mut root = Node::new_with_config(&mut config); root.set_align_items(Align::Baseline); root.set_flex_wrap(Wrap::Wrap); 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_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(30_f32.into())); root_child1.set_height(StyleUnit::Point(50_f32.into())); root.insert_child(&mut root_child1, 1); let mut root_child1_child0 = Node::new_with_config(&mut config); root_child1_child0.set_width(StyleUnit::Point(20_f32.into())); root_child1_child0.set_height(StyleUnit::Point(20_f32.into())); root_child1.insert_child(&mut root_child1_child0, 0); let mut root_child2 = Node::new_with_config(&mut config); root_child2.set_width(StyleUnit::Point(40_f32.into())); root_child2.set_height(StyleUnit::Point(70_f32.into())); root.insert_child(&mut root_child2, 2); let mut root_child2_child0 = Node::new_with_config(&mut config); root_child2_child0.set_width(StyleUnit::Point(10_f32.into())); root_child2_child0.set_height(StyleUnit::Point(10_f32.into())); root_child2.insert_child(&mut root_child2_child0, 0); let mut root_child3 = Node::new_with_config(&mut config); root_child3.set_width(StyleUnit::Point(50_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!(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!(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!(30_f32, root_child1.get_layout_width()); assert_eq!(50_f32, root_child1.get_layout_height()); assert_eq!(0_f32, root_child1_child0.get_layout_left()); assert_eq!(0_f32, root_child1_child0.get_layout_top()); assert_eq!(20_f32, root_child1_child0.get_layout_width()); assert_eq!(20_f32, root_child1_child0.get_layout_height()); assert_eq!(50_f32, root_child2.get_layout_left()); assert_eq!(0_f32, root_child2.get_layout_top()); assert_eq!(40_f32, root_child2.get_layout_width()); assert_eq!(70_f32, root_child2.get_layout_height()); assert_eq!(0_f32, root_child2_child0.get_layout_left()); assert_eq!(0_f32, root_child2_child0.get_layout_top()); assert_eq!(10_f32, root_child2_child0.get_layout_width()); assert_eq!(10_f32, root_child2_child0.get_layout_height()); assert_eq!(50_f32, root_child3.get_layout_left()); assert_eq!(70_f32, root_child3.get_layout_top()); assert_eq!(50_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!(100_f32, root.get_layout_width()); assert_eq!(100_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!(70_f32, root_child1.get_layout_left()); assert_eq!(50_f32, root_child1.get_layout_top()); assert_eq!(30_f32, root_child1.get_layout_width()); assert_eq!(50_f32, root_child1.get_layout_height()); assert_eq!(10_f32, root_child1_child0.get_layout_left()); assert_eq!(0_f32, root_child1_child0.get_layout_top()); assert_eq!(20_f32, root_child1_child0.get_layout_width()); assert_eq!(20_f32, root_child1_child0.get_layout_height()); assert_eq!(10_f32, root_child2.get_layout_left()); assert_eq!(0_f32, root_child2.get_layout_top()); assert_eq!(40_f32, root_child2.get_layout_width()); assert_eq!(70_f32, root_child2.get_layout_height()); assert_eq!(30_f32, root_child2_child0.get_layout_left()); assert_eq!(0_f32, root_child2_child0.get_layout_top()); assert_eq!(10_f32, root_child2_child0.get_layout_width()); assert_eq!(10_f32, root_child2_child0.get_layout_height()); assert_eq!(0_f32, root_child3.get_layout_left()); assert_eq!(70_f32, root_child3.get_layout_top()); assert_eq!(50_f32, root_child3.get_layout_width()); assert_eq!(20_f32, root_child3.get_layout_height()); } // WARNING: The expected values for this test have been manually overridden to match // those from upstream Yoga (which were presumably generated at an earlier point in time // when Chrome's behaviour on this test was different). This should be overwritten by // regenerating the gentests once upstream Yoga supports this functionality properly. #[test] fn test_align_baseline_multiline_column2() { let mut config = Config::new(); let mut root = Node::new_with_config(&mut config); root.set_align_items(Align::Baseline); root.set_flex_wrap(Wrap::Wrap); 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_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(30_f32.into())); root_child1.set_height(StyleUnit::Point(50_f32.into())); root.insert_child(&mut root_child1, 1); let mut root_child1_child0 = Node::new_with_config(&mut config); root_child1_child0.set_width(StyleUnit::Point(20_f32.into())); root_child1_child0.set_height(StyleUnit::Point(20_f32.into())); root_child1.insert_child(&mut root_child1_child0, 0); let mut root_child2 = Node::new_with_config(&mut config); root_child2.set_width(StyleUnit::Point(40_f32.into())); root_child2.set_height(StyleUnit::Point(70_f32.into())); root.insert_child(&mut root_child2, 2); let mut root_child2_child0 = Node::new_with_config(&mut config); root_child2_child0.set_width(StyleUnit::Point(10_f32.into())); root_child2_child0.set_height(StyleUnit::Point(10_f32.into())); root_child2.insert_child(&mut root_child2_child0, 0); let mut root_child3 = Node::new_with_config(&mut config); root_child3.set_width(StyleUnit::Point(50_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!(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!(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!(30_f32, root_child1.get_layout_width()); assert_eq!(50_f32, root_child1.get_layout_height()); assert_eq!(0_f32, root_child1_child0.get_layout_left()); assert_eq!(0_f32, root_child1_child0.get_layout_top()); assert_eq!(20_f32, root_child1_child0.get_layout_width()); assert_eq!(20_f32, root_child1_child0.get_layout_height()); assert_eq!(50_f32, root_child2.get_layout_left()); assert_eq!(0_f32, root_child2.get_layout_top()); assert_eq!(40_f32, root_child2.get_layout_width()); assert_eq!(70_f32, root_child2.get_layout_height()); assert_eq!(0_f32, root_child2_child0.get_layout_left()); assert_eq!(0_f32, root_child2_child0.get_layout_top()); assert_eq!(10_f32, root_child2_child0.get_layout_width()); assert_eq!(10_f32, root_child2_child0.get_layout_height()); assert_eq!(50_f32, root_child3.get_layout_left()); assert_eq!(70_f32, root_child3.get_layout_top()); assert_eq!(50_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!(100_f32, root.get_layout_width()); assert_eq!(100_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!(70_f32, root_child1.get_layout_left()); assert_eq!(50_f32, root_child1.get_layout_top()); assert_eq!(30_f32, root_child1.get_layout_width()); assert_eq!(50_f32, root_child1.get_layout_height()); assert_eq!(10_f32, root_child1_child0.get_layout_left()); assert_eq!(0_f32, root_child1_child0.get_layout_top()); assert_eq!(20_f32, root_child1_child0.get_layout_width()); assert_eq!(20_f32, root_child1_child0.get_layout_height()); assert_eq!(10_f32, root_child2.get_layout_left()); assert_eq!(0_f32, root_child2.get_layout_top()); assert_eq!(40_f32, root_child2.get_layout_width()); assert_eq!(70_f32, root_child2.get_layout_height()); assert_eq!(30_f32, root_child2_child0.get_layout_left()); assert_eq!(0_f32, root_child2_child0.get_layout_top()); assert_eq!(10_f32, root_child2_child0.get_layout_width()); assert_eq!(10_f32, root_child2_child0.get_layout_height()); assert_eq!(0_f32, root_child3.get_layout_left()); assert_eq!(70_f32, root_child3.get_layout_top()); assert_eq!(50_f32, root_child3.get_layout_width()); assert_eq!(20_f32, root_child3.get_layout_height()); } #[test] fn test_align_baseline_multiline_row_and_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::Baseline); root.set_flex_wrap(Wrap::Wrap); 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_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); let mut root_child1_child0 = Node::new_with_config(&mut config); root_child1_child0.set_width(StyleUnit::Point(50_f32.into())); root_child1_child0.set_height(StyleUnit::Point(10_f32.into())); root_child1.insert_child(&mut root_child1_child0, 0); 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(20_f32.into())); root.insert_child(&mut root_child2, 2); let mut root_child2_child0 = Node::new_with_config(&mut config); root_child2_child0.set_width(StyleUnit::Point(50_f32.into())); root_child2_child0.set_height(StyleUnit::Point(10_f32.into())); root_child2.insert_child(&mut root_child2_child0, 0); let mut root_child3 = Node::new_with_config(&mut config); root_child3.set_width(StyleUnit::Point(50_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!(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!(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!(40_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_child1_child0.get_layout_left()); assert_eq!(0_f32, root_child1_child0.get_layout_top()); assert_eq!(50_f32, root_child1_child0.get_layout_width()); assert_eq!(10_f32, root_child1_child0.get_layout_height()); assert_eq!(0_f32, root_child2.get_layout_left()); assert_eq!(100_f32, root_child2.get_layout_top()); assert_eq!(50_f32, root_child2.get_layout_width()); assert_eq!(20_f32, root_child2.get_layout_height()); assert_eq!(0_f32, root_child2_child0.get_layout_left()); assert_eq!(0_f32, root_child2_child0.get_layout_top()); assert_eq!(50_f32, root_child2_child0.get_layout_width()); assert_eq!(10_f32, root_child2_child0.get_layout_height()); assert_eq!(50_f32, root_child3.get_layout_left()); assert_eq!(90_f32, root_child3.get_layout_top()); assert_eq!(50_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!(100_f32, root.get_layout_width()); assert_eq!(100_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!(0_f32, root_child1.get_layout_left()); assert_eq!(40_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_child1_child0.get_layout_left()); assert_eq!(0_f32, root_child1_child0.get_layout_top()); assert_eq!(50_f32, root_child1_child0.get_layout_width()); assert_eq!(10_f32, root_child1_child0.get_layout_height()); assert_eq!(50_f32, root_child2.get_layout_left()); assert_eq!(100_f32, root_child2.get_layout_top()); assert_eq!(50_f32, root_child2.get_layout_width()); assert_eq!(20_f32, root_child2.get_layout_height()); assert_eq!(0_f32, root_child2_child0.get_layout_left()); assert_eq!(0_f32, root_child2_child0.get_layout_top()); assert_eq!(50_f32, root_child2_child0.get_layout_width()); assert_eq!(10_f32, root_child2_child0.get_layout_height()); assert_eq!(0_f32, root_child3.get_layout_left()); assert_eq!(90_f32, root_child3.get_layout_top()); assert_eq!(50_f32, root_child3.get_layout_width()); assert_eq!(20_f32, root_child3.get_layout_height()); } #[test] fn test_align_items_center_child_with_margin_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_align_items(Align::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_align_items(Align::Center); root.insert_child(&mut root_child0, 0); let mut root_child0_child0 = Node::new_with_config(&mut config); root_child0_child0.set_margin(Edge::Left, StyleUnit::Point(10_f32.into())); root_child0_child0.set_margin(Edge::Right, StyleUnit::Point(10_f32.into())); root_child0_child0.set_width(StyleUnit::Point(52_f32.into())); root_child0_child0.set_height(StyleUnit::Point(52_f32.into())); root_child0.insert_child(&mut root_child0_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!(0_f32, root_child0.get_layout_top()); assert_eq!(72_f32, root_child0.get_layout_width()); assert_eq!(52_f32, root_child0.get_layout_height()); assert_eq!(10_f32, root_child0_child0.get_layout_left()); assert_eq!(0_f32, root_child0_child0.get_layout_top()); assert_eq!(52_f32, root_child0_child0.get_layout_width()); assert_eq!(52_f32, root_child0_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!(-10_f32, root_child0.get_layout_left()); assert_eq!(0_f32, root_child0.get_layout_top()); assert_eq!(72_f32, root_child0.get_layout_width()); assert_eq!(52_f32, root_child0.get_layout_height()); assert_eq!(10_f32, root_child0_child0.get_layout_left()); assert_eq!(0_f32, root_child0_child0.get_layout_top()); assert_eq!(52_f32, root_child0_child0.get_layout_width()); assert_eq!(52_f32, root_child0_child0.get_layout_height()); } #[test] fn test_align_items_flex_end_child_with_margin_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_align_items(Align::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_align_items(Align::FlexEnd); root.insert_child(&mut root_child0, 0); let mut root_child0_child0 = Node::new_with_config(&mut config); root_child0_child0.set_margin(Edge::Left, StyleUnit::Point(10_f32.into())); root_child0_child0.set_margin(Edge::Right, StyleUnit::Point(10_f32.into())); root_child0_child0.set_width(StyleUnit::Point(52_f32.into())); root_child0_child0.set_height(StyleUnit::Point(52_f32.into())); root_child0.insert_child(&mut root_child0_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!(0_f32, root_child0.get_layout_top()); assert_eq!(72_f32, root_child0.get_layout_width()); assert_eq!(52_f32, root_child0.get_layout_height()); assert_eq!(10_f32, root_child0_child0.get_layout_left()); assert_eq!(0_f32, root_child0_child0.get_layout_top()); assert_eq!(52_f32, root_child0_child0.get_layout_width()); assert_eq!(52_f32, root_child0_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!(-10_f32, root_child0.get_layout_left()); assert_eq!(0_f32, root_child0.get_layout_top()); assert_eq!(72_f32, root_child0.get_layout_width()); assert_eq!(52_f32, root_child0.get_layout_height()); assert_eq!(10_f32, root_child0_child0.get_layout_left()); assert_eq!(0_f32, root_child0_child0.get_layout_top()); assert_eq!(52_f32, root_child0_child0.get_layout_width()); assert_eq!(52_f32, root_child0_child0.get_layout_height()); } #[test] fn test_align_items_center_child_without_margin_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_align_items(Align::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_align_items(Align::Center); root.insert_child(&mut root_child0, 0); let mut root_child0_child0 = Node::new_with_config(&mut config); root_child0_child0.set_width(StyleUnit::Point(72_f32.into())); root_child0_child0.set_height(StyleUnit::Point(72_f32.into())); root_child0.insert_child(&mut root_child0_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()); assert_eq!(0_f32, root_child0_child0.get_layout_left()); assert_eq!(0_f32, root_child0_child0.get_layout_top()); assert_eq!(72_f32, root_child0_child0.get_layout_width()); assert_eq!(72_f32, root_child0_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!(-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()); assert_eq!(0_f32, root_child0_child0.get_layout_left()); assert_eq!(0_f32, root_child0_child0.get_layout_top()); assert_eq!(72_f32, root_child0_child0.get_layout_width()); assert_eq!(72_f32, root_child0_child0.get_layout_height()); } #[test] fn test_align_items_flex_end_child_without_margin_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_align_items(Align::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_align_items(Align::FlexEnd); root.insert_child(&mut root_child0, 0); let mut root_child0_child0 = Node::new_with_config(&mut config); root_child0_child0.set_width(StyleUnit::Point(72_f32.into())); root_child0_child0.set_height(StyleUnit::Point(72_f32.into())); root_child0.insert_child(&mut root_child0_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()); assert_eq!(0_f32, root_child0_child0.get_layout_left()); assert_eq!(0_f32, root_child0_child0.get_layout_top()); assert_eq!(72_f32, root_child0_child0.get_layout_width()); assert_eq!(72_f32, root_child0_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!(-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()); assert_eq!(0_f32, root_child0_child0.get_layout_left()); assert_eq!(0_f32, root_child0_child0.get_layout_top()); assert_eq!(72_f32, root_child0_child0.get_layout_width()); assert_eq!(72_f32, root_child0_child0.get_layout_height()); } #[test] fn test_align_center_should_size_based_on_content() { let mut config = Config::new(); let mut root = Node::new_with_config(&mut config); root.set_align_items(Align::Center); root.set_margin(Edge::Top, StyleUnit::Point(20_f32.into())); 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_justify_content(Justify::Center); root_child0.set_flex_shrink(1_f32); root.insert_child(&mut root_child0, 0); let mut root_child0_child0 = Node::new_with_config(&mut config); root_child0_child0.set_flex_grow(1_f32); root_child0_child0.set_flex_shrink(1_f32); root_child0.insert_child(&mut root_child0_child0, 0); let mut root_child0_child0_child0 = Node::new_with_config(&mut config); root_child0_child0_child0.set_width(StyleUnit::Point(20_f32.into())); root_child0_child0_child0.set_height(StyleUnit::Point(20_f32.into())); root_child0_child0.insert_child(&mut root_child0_child0_child0, 0); root.calculate_layout(Undefined, Undefined, Direction::LTR); assert_eq!(0_f32, root.get_layout_left()); assert_eq!(20_f32, root.get_layout_top()); assert_eq!(100_f32, root.get_layout_width()); assert_eq!(100_f32, root.get_layout_height()); assert_eq!(40_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_child0_child0.get_layout_left()); assert_eq!(0_f32, root_child0_child0.get_layout_top()); assert_eq!(20_f32, root_child0_child0.get_layout_width()); assert_eq!(20_f32, root_child0_child0.get_layout_height()); assert_eq!(0_f32, root_child0_child0_child0.get_layout_left()); assert_eq!(0_f32, root_child0_child0_child0.get_layout_top()); assert_eq!(20_f32, root_child0_child0_child0.get_layout_width()); assert_eq!(20_f32, root_child0_child0_child0.get_layout_height()); root.calculate_layout(Undefined, Undefined, Direction::RTL); assert_eq!(0_f32, root.get_layout_left()); assert_eq!(20_f32, root.get_layout_top()); assert_eq!(100_f32, root.get_layout_width()); assert_eq!(100_f32, root.get_layout_height()); assert_eq!(40_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_child0_child0.get_layout_left()); assert_eq!(0_f32, root_child0_child0.get_layout_top()); assert_eq!(20_f32, root_child0_child0.get_layout_width()); assert_eq!(20_f32, root_child0_child0.get_layout_height()); assert_eq!(0_f32, root_child0_child0_child0.get_layout_left()); assert_eq!(0_f32, root_child0_child0_child0.get_layout_top()); assert_eq!(20_f32, root_child0_child0_child0.get_layout_width()); assert_eq!(20_f32, root_child0_child0_child0.get_layout_height()); } #[test] fn test_align_stretch_should_size_based_on_parent() { let mut config = Config::new(); let mut root = Node::new_with_config(&mut config); root.set_margin(Edge::Top, StyleUnit::Point(20_f32.into())); 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_justify_content(Justify::Center); root_child0.set_flex_shrink(1_f32); root.insert_child(&mut root_child0, 0); let mut root_child0_child0 = Node::new_with_config(&mut config); root_child0_child0.set_flex_grow(1_f32); root_child0_child0.set_flex_shrink(1_f32); root_child0.insert_child(&mut root_child0_child0, 0); let mut root_child0_child0_child0 = Node::new_with_config(&mut config); root_child0_child0_child0.set_width(StyleUnit::Point(20_f32.into())); root_child0_child0_child0.set_height(StyleUnit::Point(20_f32.into())); root_child0_child0.insert_child(&mut root_child0_child0_child0, 0); root.calculate_layout(Undefined, Undefined, Direction::LTR); assert_eq!(0_f32, root.get_layout_left()); assert_eq!(20_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!(20_f32, root_child0.get_layout_height()); assert_eq!(0_f32, root_child0_child0.get_layout_left()); assert_eq!(0_f32, root_child0_child0.get_layout_top()); assert_eq!(100_f32, root_child0_child0.get_layout_width()); assert_eq!(20_f32, root_child0_child0.get_layout_height()); assert_eq!(0_f32, root_child0_child0_child0.get_layout_left()); assert_eq!(0_f32, root_child0_child0_child0.get_layout_top()); assert_eq!(20_f32, root_child0_child0_child0.get_layout_width()); assert_eq!(20_f32, root_child0_child0_child0.get_layout_height()); root.calculate_layout(Undefined, Undefined, Direction::RTL); assert_eq!(0_f32, root.get_layout_left()); assert_eq!(20_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!(20_f32, root_child0.get_layout_height()); assert_eq!(0_f32, root_child0_child0.get_layout_left()); assert_eq!(0_f32, root_child0_child0.get_layout_top()); assert_eq!(100_f32, root_child0_child0.get_layout_width()); assert_eq!(20_f32, root_child0_child0.get_layout_height()); assert_eq!(80_f32, root_child0_child0_child0.get_layout_left()); assert_eq!(0_f32, root_child0_child0_child0.get_layout_top()); assert_eq!(20_f32, root_child0_child0_child0.get_layout_width()); assert_eq!(20_f32, root_child0_child0_child0.get_layout_height()); } #[test] fn test_align_flex_start_with_shrinking_children() { let mut config = Config::new(); let mut root = Node::new_with_config(&mut config); root.set_width(StyleUnit::Point(500_f32.into())); root.set_height(StyleUnit::Point(500_f32.into())); let mut root_child0 = Node::new_with_config(&mut config); root_child0.set_align_items(Align::FlexStart); root.insert_child(&mut root_child0, 0); let mut root_child0_child0 = Node::new_with_config(&mut config); root_child0_child0.set_flex_grow(1_f32); root_child0_child0.set_flex_shrink(1_f32); root_child0.insert_child(&mut root_child0_child0, 0); let mut root_child0_child0_child0 = Node::new_with_config(&mut config); root_child0_child0_child0.set_flex_grow(1_f32); root_child0_child0_child0.set_flex_shrink(1_f32); root_child0_child0.insert_child(&mut root_child0_child0_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!(500_f32, root.get_layout_width()); assert_eq!(500_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!(500_f32, root_child0.get_layout_width()); assert_eq!(0_f32, root_child0.get_layout_height()); assert_eq!(0_f32, root_child0_child0.get_layout_left()); assert_eq!(0_f32, root_child0_child0.get_layout_top()); assert_eq!(0_f32, root_child0_child0.get_layout_width()); assert_eq!(0_f32, root_child0_child0.get_layout_height()); assert_eq!(0_f32, root_child0_child0_child0.get_layout_left()); assert_eq!(0_f32, root_child0_child0_child0.get_layout_top()); assert_eq!(0_f32, root_child0_child0_child0.get_layout_width()); assert_eq!(0_f32, root_child0_child0_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!(500_f32, root.get_layout_width()); assert_eq!(500_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!(500_f32, root_child0.get_layout_width()); assert_eq!(0_f32, root_child0.get_layout_height()); assert_eq!(500_f32, root_child0_child0.get_layout_left()); assert_eq!(0_f32, root_child0_child0.get_layout_top()); assert_eq!(0_f32, root_child0_child0.get_layout_width()); assert_eq!(0_f32, root_child0_child0.get_layout_height()); assert_eq!(0_f32, root_child0_child0_child0.get_layout_left()); assert_eq!(0_f32, root_child0_child0_child0.get_layout_top()); assert_eq!(0_f32, root_child0_child0_child0.get_layout_width()); assert_eq!(0_f32, root_child0_child0_child0.get_layout_height()); } #[test] fn test_align_flex_start_with_stretching_children() { let mut config = Config::new(); let mut root = Node::new_with_config(&mut config); root.set_width(StyleUnit::Point(500_f32.into())); root.set_height(StyleUnit::Point(500_f32.into())); let mut root_child0 = Node::new_with_config(&mut config); root.insert_child(&mut root_child0, 0); let mut root_child0_child0 = Node::new_with_config(&mut config); root_child0_child0.set_flex_grow(1_f32); root_child0_child0.set_flex_shrink(1_f32); root_child0.insert_child(&mut root_child0_child0, 0); let mut root_child0_child0_child0 = Node::new_with_config(&mut config); root_child0_child0_child0.set_flex_grow(1_f32); root_child0_child0_child0.set_flex_shrink(1_f32); root_child0_child0.insert_child(&mut root_child0_child0_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!(500_f32, root.get_layout_width()); assert_eq!(500_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!(500_f32, root_child0.get_layout_width()); assert_eq!(0_f32, root_child0.get_layout_height()); assert_eq!(0_f32, root_child0_child0.get_layout_left()); assert_eq!(0_f32, root_child0_child0.get_layout_top()); assert_eq!(500_f32, root_child0_child0.get_layout_width()); assert_eq!(0_f32, root_child0_child0.get_layout_height()); assert_eq!(0_f32, root_child0_child0_child0.get_layout_left()); assert_eq!(0_f32, root_child0_child0_child0.get_layout_top()); assert_eq!(500_f32, root_child0_child0_child0.get_layout_width()); assert_eq!(0_f32, root_child0_child0_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!(500_f32, root.get_layout_width()); assert_eq!(500_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!(500_f32, root_child0.get_layout_width()); assert_eq!(0_f32, root_child0.get_layout_height()); assert_eq!(0_f32, root_child0_child0.get_layout_left()); assert_eq!(0_f32, root_child0_child0.get_layout_top()); assert_eq!(500_f32, root_child0_child0.get_layout_width()); assert_eq!(0_f32, root_child0_child0.get_layout_height()); assert_eq!(0_f32, root_child0_child0_child0.get_layout_left()); assert_eq!(0_f32, root_child0_child0_child0.get_layout_top()); assert_eq!(500_f32, root_child0_child0_child0.get_layout_width()); assert_eq!(0_f32, root_child0_child0_child0.get_layout_height()); } #[test] fn test_align_flex_start_with_shrinking_children_with_stretch() { let mut config = Config::new(); let mut root = Node::new_with_config(&mut config); root.set_width(StyleUnit::Point(500_f32.into())); root.set_height(StyleUnit::Point(500_f32.into())); let mut root_child0 = Node::new_with_config(&mut config); root_child0.set_align_items(Align::FlexStart); root.insert_child(&mut root_child0, 0); let mut root_child0_child0 = Node::new_with_config(&mut config); root_child0_child0.set_flex_grow(1_f32); root_child0_child0.set_flex_shrink(1_f32); root_child0.insert_child(&mut root_child0_child0, 0); let mut root_child0_child0_child0 = Node::new_with_config(&mut config); root_child0_child0_child0.set_flex_grow(1_f32); root_child0_child0_child0.set_flex_shrink(1_f32); root_child0_child0.insert_child(&mut root_child0_child0_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!(500_f32, root.get_layout_width()); assert_eq!(500_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!(500_f32, root_child0.get_layout_width()); assert_eq!(0_f32, root_child0.get_layout_height()); assert_eq!(0_f32, root_child0_child0.get_layout_left()); assert_eq!(0_f32, root_child0_child0.get_layout_top()); assert_eq!(0_f32, root_child0_child0.get_layout_width()); assert_eq!(0_f32, root_child0_child0.get_layout_height()); assert_eq!(0_f32, root_child0_child0_child0.get_layout_left()); assert_eq!(0_f32, root_child0_child0_child0.get_layout_top()); assert_eq!(0_f32, root_child0_child0_child0.get_layout_width()); assert_eq!(0_f32, root_child0_child0_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!(500_f32, root.get_layout_width()); assert_eq!(500_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!(500_f32, root_child0.get_layout_width()); assert_eq!(0_f32, root_child0.get_layout_height()); assert_eq!(500_f32, root_child0_child0.get_layout_left()); assert_eq!(0_f32, root_child0_child0.get_layout_top()); assert_eq!(0_f32, root_child0_child0.get_layout_width()); assert_eq!(0_f32, root_child0_child0.get_layout_height()); assert_eq!(0_f32, root_child0_child0_child0.get_layout_left()); assert_eq!(0_f32, root_child0_child0_child0.get_layout_top()); assert_eq!(0_f32, root_child0_child0_child0.get_layout_width()); assert_eq!(0_f32, root_child0_child0_child0.get_layout_height()); }