/** * Copyright (c) 2014-present, Facebook, Inc. * * 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/YGPercentageTest.html extern crate ordered_float; extern crate yoga; use yoga::*; #[test] fn test_percentage_width_height() { 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 as f32).into())); root.set_height(StyleUnit::Point((200 as f32).into())); let mut root_child0 = Node::new_with_config(&mut config); root_child0.set_width(StyleUnit::Percent((30 as f32).into())); root_child0.set_min_width(StyleUnit::Auto); root_child0.set_height(StyleUnit::Percent((30 as f32).into())); root_child0.set_min_height(StyleUnit::Auto); root.insert_child(&mut root_child0, 0); root.calculate_layout(Undefined, Undefined, Direction::LTR); assert_eq!(0 as f32, root.get_layout_left()); assert_eq!(0 as f32, root.get_layout_top()); assert_eq!(200 as f32, root.get_layout_width()); assert_eq!(200 as f32, root.get_layout_height()); assert_eq!(0 as f32, root_child0.get_layout_left()); assert_eq!(0 as f32, root_child0.get_layout_top()); assert_eq!(60 as f32, root_child0.get_layout_width()); assert_eq!(60 as f32, root_child0.get_layout_height()); root.calculate_layout(Undefined, Undefined, Direction::RTL); assert_eq!(0 as f32, root.get_layout_left()); assert_eq!(0 as f32, root.get_layout_top()); assert_eq!(200 as f32, root.get_layout_width()); assert_eq!(200 as f32, root.get_layout_height()); assert_eq!(140 as f32, root_child0.get_layout_left()); assert_eq!(0 as f32, root_child0.get_layout_top()); assert_eq!(60 as f32, root_child0.get_layout_width()); assert_eq!(60 as f32, root_child0.get_layout_height()); } #[test] fn test_percentage_position_left_top() { 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((400 as f32).into())); root.set_height(StyleUnit::Point((400 as f32).into())); let mut root_child0 = Node::new_with_config(&mut config); root_child0.set_position(Edge::Left, StyleUnit::Percent((10 as f32).into())); root_child0.set_position(Edge::Top, StyleUnit::Percent((20 as f32).into())); root_child0.set_width(StyleUnit::Percent((45 as f32).into())); root_child0.set_min_width(StyleUnit::Auto); root_child0.set_height(StyleUnit::Percent((55 as f32).into())); root_child0.set_min_height(StyleUnit::Auto); root.insert_child(&mut root_child0, 0); root.calculate_layout(Undefined, Undefined, Direction::LTR); assert_eq!(0 as f32, root.get_layout_left()); assert_eq!(0 as f32, root.get_layout_top()); assert_eq!(400 as f32, root.get_layout_width()); assert_eq!(400 as f32, root.get_layout_height()); assert_eq!(40 as f32, root_child0.get_layout_left()); assert_eq!(80 as f32, root_child0.get_layout_top()); assert_eq!(180 as f32, root_child0.get_layout_width()); assert_eq!(220 as f32, root_child0.get_layout_height()); root.calculate_layout(Undefined, Undefined, Direction::RTL); assert_eq!(0 as f32, root.get_layout_left()); assert_eq!(0 as f32, root.get_layout_top()); assert_eq!(400 as f32, root.get_layout_width()); assert_eq!(400 as f32, root.get_layout_height()); assert_eq!(260 as f32, root_child0.get_layout_left()); assert_eq!(80 as f32, root_child0.get_layout_top()); assert_eq!(180 as f32, root_child0.get_layout_width()); assert_eq!(220 as f32, root_child0.get_layout_height()); } #[test] fn test_percentage_position_bottom_right() { 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((500 as f32).into())); root.set_height(StyleUnit::Point((500 as f32).into())); let mut root_child0 = Node::new_with_config(&mut config); root_child0.set_position(Edge::Right, StyleUnit::Percent((20 as f32).into())); root_child0.set_position(Edge::Bottom, StyleUnit::Percent((10 as f32).into())); root_child0.set_width(StyleUnit::Percent((55 as f32).into())); root_child0.set_min_width(StyleUnit::Auto); root_child0.set_height(StyleUnit::Percent((15 as f32).into())); root_child0.set_min_height(StyleUnit::Auto); root.insert_child(&mut root_child0, 0); root.calculate_layout(Undefined, Undefined, Direction::LTR); assert_eq!(0 as f32, root.get_layout_left()); assert_eq!(0 as f32, root.get_layout_top()); assert_eq!(500 as f32, root.get_layout_width()); assert_eq!(500 as f32, root.get_layout_height()); assert_eq!(-100 as f32, root_child0.get_layout_left()); assert_eq!(-50 as f32, root_child0.get_layout_top()); assert_eq!(275 as f32, root_child0.get_layout_width()); assert_eq!(75 as f32, root_child0.get_layout_height()); root.calculate_layout(Undefined, Undefined, Direction::RTL); assert_eq!(0 as f32, root.get_layout_left()); assert_eq!(0 as f32, root.get_layout_top()); assert_eq!(500 as f32, root.get_layout_width()); assert_eq!(500 as f32, root.get_layout_height()); assert_eq!(125 as f32, root_child0.get_layout_left()); assert_eq!(-50 as f32, root_child0.get_layout_top()); assert_eq!(275 as f32, root_child0.get_layout_width()); assert_eq!(75 as f32, root_child0.get_layout_height()); } #[test] fn test_percentage_flex_basis() { 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 as f32).into())); root.set_height(StyleUnit::Point((200 as f32).into())); let mut root_child0 = Node::new_with_config(&mut config); root_child0.set_flex_grow(1 as f32); root_child0.set_flex_basis(StyleUnit::Percent((50 as f32).into())); root_child0.set_min_width(StyleUnit::Auto); root_child0.set_min_height(StyleUnit::Auto); root.insert_child(&mut root_child0, 0); let mut root_child1 = Node::new_with_config(&mut config); root_child1.set_flex_grow(1 as f32); root_child1.set_flex_basis(StyleUnit::Percent((25 as f32).into())); root_child1.set_min_width(StyleUnit::Auto); root_child1.set_min_height(StyleUnit::Auto); root.insert_child(&mut root_child1, 1); root.calculate_layout(Undefined, Undefined, Direction::LTR); assert_eq!(0 as f32, root.get_layout_left()); assert_eq!(0 as f32, root.get_layout_top()); assert_eq!(200 as f32, root.get_layout_width()); assert_eq!(200 as f32, root.get_layout_height()); assert_eq!(0 as f32, root_child0.get_layout_left()); assert_eq!(0 as f32, root_child0.get_layout_top()); assert_eq!(125 as f32, root_child0.get_layout_width()); assert_eq!(200 as f32, root_child0.get_layout_height()); assert_eq!(125 as f32, root_child1.get_layout_left()); assert_eq!(0 as f32, root_child1.get_layout_top()); assert_eq!(75 as f32, root_child1.get_layout_width()); assert_eq!(200 as f32, root_child1.get_layout_height()); root.calculate_layout(Undefined, Undefined, Direction::RTL); assert_eq!(0 as f32, root.get_layout_left()); assert_eq!(0 as f32, root.get_layout_top()); assert_eq!(200 as f32, root.get_layout_width()); assert_eq!(200 as f32, root.get_layout_height()); assert_eq!(75 as f32, root_child0.get_layout_left()); assert_eq!(0 as f32, root_child0.get_layout_top()); assert_eq!(125 as f32, root_child0.get_layout_width()); assert_eq!(200 as f32, root_child0.get_layout_height()); assert_eq!(0 as f32, root_child1.get_layout_left()); assert_eq!(0 as f32, root_child1.get_layout_top()); assert_eq!(75 as f32, root_child1.get_layout_width()); assert_eq!(200 as f32, root_child1.get_layout_height()); } #[test] fn test_percentage_flex_basis_cross() { let mut config = Config::new(); let mut root = Node::new_with_config(&mut config); root.set_width(StyleUnit::Point((200 as f32).into())); root.set_height(StyleUnit::Point((200 as f32).into())); let mut root_child0 = Node::new_with_config(&mut config); root_child0.set_flex_grow(1 as f32); root_child0.set_flex_basis(StyleUnit::Percent((50 as f32).into())); root_child0.set_min_width(StyleUnit::Auto); root_child0.set_min_height(StyleUnit::Auto); root.insert_child(&mut root_child0, 0); let mut root_child1 = Node::new_with_config(&mut config); root_child1.set_flex_grow(1 as f32); root_child1.set_flex_basis(StyleUnit::Percent((25 as f32).into())); root_child1.set_min_width(StyleUnit::Auto); root_child1.set_min_height(StyleUnit::Auto); root.insert_child(&mut root_child1, 1); root.calculate_layout(Undefined, Undefined, Direction::LTR); assert_eq!(0 as f32, root.get_layout_left()); assert_eq!(0 as f32, root.get_layout_top()); assert_eq!(200 as f32, root.get_layout_width()); assert_eq!(200 as f32, root.get_layout_height()); assert_eq!(0 as f32, root_child0.get_layout_left()); assert_eq!(0 as f32, root_child0.get_layout_top()); assert_eq!(200 as f32, root_child0.get_layout_width()); assert_eq!(125 as f32, root_child0.get_layout_height()); assert_eq!(0 as f32, root_child1.get_layout_left()); assert_eq!(125 as f32, root_child1.get_layout_top()); assert_eq!(200 as f32, root_child1.get_layout_width()); assert_eq!(75 as f32, root_child1.get_layout_height()); root.calculate_layout(Undefined, Undefined, Direction::RTL); assert_eq!(0 as f32, root.get_layout_left()); assert_eq!(0 as f32, root.get_layout_top()); assert_eq!(200 as f32, root.get_layout_width()); assert_eq!(200 as f32, root.get_layout_height()); assert_eq!(0 as f32, root_child0.get_layout_left()); assert_eq!(0 as f32, root_child0.get_layout_top()); assert_eq!(200 as f32, root_child0.get_layout_width()); assert_eq!(125 as f32, root_child0.get_layout_height()); assert_eq!(0 as f32, root_child1.get_layout_left()); assert_eq!(125 as f32, root_child1.get_layout_top()); assert_eq!(200 as f32, root_child1.get_layout_width()); assert_eq!(75 as f32, root_child1.get_layout_height()); } #[test] fn test_percentage_flex_basis_cross_min_height() { let mut config = Config::new(); let mut root = Node::new_with_config(&mut config); root.set_width(StyleUnit::Point((200 as f32).into())); root.set_height(StyleUnit::Point((200 as f32).into())); let mut root_child0 = Node::new_with_config(&mut config); root_child0.set_flex_grow(1 as f32); root_child0.set_min_width(StyleUnit::Auto); root_child0.set_min_height(StyleUnit::Percent((60 as f32).into())); root.insert_child(&mut root_child0, 0); let mut root_child1 = Node::new_with_config(&mut config); root_child1.set_flex_grow(2 as f32); root_child1.set_min_width(StyleUnit::Auto); root_child1.set_min_height(StyleUnit::Percent((10 as f32).into())); root.insert_child(&mut root_child1, 1); root.calculate_layout(Undefined, Undefined, Direction::LTR); assert_eq!(0 as f32, root.get_layout_left()); assert_eq!(0 as f32, root.get_layout_top()); assert_eq!(200 as f32, root.get_layout_width()); assert_eq!(200 as f32, root.get_layout_height()); assert_eq!(0 as f32, root_child0.get_layout_left()); assert_eq!(0 as f32, root_child0.get_layout_top()); assert_eq!(200 as f32, root_child0.get_layout_width()); assert_eq!(140 as f32, root_child0.get_layout_height()); assert_eq!(0 as f32, root_child1.get_layout_left()); assert_eq!(140 as f32, root_child1.get_layout_top()); assert_eq!(200 as f32, root_child1.get_layout_width()); assert_eq!(60 as f32, root_child1.get_layout_height()); root.calculate_layout(Undefined, Undefined, Direction::RTL); assert_eq!(0 as f32, root.get_layout_left()); assert_eq!(0 as f32, root.get_layout_top()); assert_eq!(200 as f32, root.get_layout_width()); assert_eq!(200 as f32, root.get_layout_height()); assert_eq!(0 as f32, root_child0.get_layout_left()); assert_eq!(0 as f32, root_child0.get_layout_top()); assert_eq!(200 as f32, root_child0.get_layout_width()); assert_eq!(140 as f32, root_child0.get_layout_height()); assert_eq!(0 as f32, root_child1.get_layout_left()); assert_eq!(140 as f32, root_child1.get_layout_top()); assert_eq!(200 as f32, root_child1.get_layout_width()); assert_eq!(60 as f32, root_child1.get_layout_height()); } #[test] fn test_percentage_flex_basis_main_max_height() { 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 as f32).into())); root.set_height(StyleUnit::Point((200 as f32).into())); let mut root_child0 = Node::new_with_config(&mut config); root_child0.set_flex_grow(1 as f32); root_child0.set_flex_basis(StyleUnit::Percent((10 as f32).into())); root_child0.set_min_width(StyleUnit::Auto); root_child0.set_min_height(StyleUnit::Auto); root_child0.set_max_height(StyleUnit::Percent((60 as f32).into())); root.insert_child(&mut root_child0, 0); let mut root_child1 = Node::new_with_config(&mut config); root_child1.set_flex_grow(4 as f32); root_child1.set_flex_basis(StyleUnit::Percent((10 as f32).into())); root_child1.set_min_width(StyleUnit::Auto); root_child1.set_min_height(StyleUnit::Auto); root_child1.set_max_height(StyleUnit::Percent((20 as f32).into())); root.insert_child(&mut root_child1, 1); root.calculate_layout(Undefined, Undefined, Direction::LTR); assert_eq!(0 as f32, root.get_layout_left()); assert_eq!(0 as f32, root.get_layout_top()); assert_eq!(200 as f32, root.get_layout_width()); assert_eq!(200 as f32, root.get_layout_height()); assert_eq!(0 as f32, root_child0.get_layout_left()); assert_eq!(0 as f32, root_child0.get_layout_top()); assert_eq!(52 as f32, root_child0.get_layout_width()); assert_eq!(120 as f32, root_child0.get_layout_height()); assert_eq!(52 as f32, root_child1.get_layout_left()); assert_eq!(0 as f32, root_child1.get_layout_top()); assert_eq!(148 as f32, root_child1.get_layout_width()); assert_eq!(40 as f32, root_child1.get_layout_height()); root.calculate_layout(Undefined, Undefined, Direction::RTL); assert_eq!(0 as f32, root.get_layout_left()); assert_eq!(0 as f32, root.get_layout_top()); assert_eq!(200 as f32, root.get_layout_width()); assert_eq!(200 as f32, root.get_layout_height()); assert_eq!(148 as f32, root_child0.get_layout_left()); assert_eq!(0 as f32, root_child0.get_layout_top()); assert_eq!(52 as f32, root_child0.get_layout_width()); assert_eq!(120 as f32, root_child0.get_layout_height()); assert_eq!(0 as f32, root_child1.get_layout_left()); assert_eq!(0 as f32, root_child1.get_layout_top()); assert_eq!(148 as f32, root_child1.get_layout_width()); assert_eq!(40 as f32, root_child1.get_layout_height()); } #[test] fn test_percentage_flex_basis_cross_max_height() { let mut config = Config::new(); let mut root = Node::new_with_config(&mut config); root.set_width(StyleUnit::Point((200 as f32).into())); root.set_height(StyleUnit::Point((200 as f32).into())); let mut root_child0 = Node::new_with_config(&mut config); root_child0.set_flex_grow(1 as f32); root_child0.set_flex_basis(StyleUnit::Percent((10 as f32).into())); root_child0.set_min_width(StyleUnit::Auto); root_child0.set_min_height(StyleUnit::Auto); root_child0.set_max_height(StyleUnit::Percent((60 as f32).into())); root.insert_child(&mut root_child0, 0); let mut root_child1 = Node::new_with_config(&mut config); root_child1.set_flex_grow(4 as f32); root_child1.set_flex_basis(StyleUnit::Percent((10 as f32).into())); root_child1.set_min_width(StyleUnit::Auto); root_child1.set_min_height(StyleUnit::Auto); root_child1.set_max_height(StyleUnit::Percent((20 as f32).into())); root.insert_child(&mut root_child1, 1); root.calculate_layout(Undefined, Undefined, Direction::LTR); assert_eq!(0 as f32, root.get_layout_left()); assert_eq!(0 as f32, root.get_layout_top()); assert_eq!(200 as f32, root.get_layout_width()); assert_eq!(200 as f32, root.get_layout_height()); assert_eq!(0 as f32, root_child0.get_layout_left()); assert_eq!(0 as f32, root_child0.get_layout_top()); assert_eq!(200 as f32, root_child0.get_layout_width()); assert_eq!(120 as f32, root_child0.get_layout_height()); assert_eq!(0 as f32, root_child1.get_layout_left()); assert_eq!(120 as f32, root_child1.get_layout_top()); assert_eq!(200 as f32, root_child1.get_layout_width()); assert_eq!(40 as f32, root_child1.get_layout_height()); root.calculate_layout(Undefined, Undefined, Direction::RTL); assert_eq!(0 as f32, root.get_layout_left()); assert_eq!(0 as f32, root.get_layout_top()); assert_eq!(200 as f32, root.get_layout_width()); assert_eq!(200 as f32, root.get_layout_height()); assert_eq!(0 as f32, root_child0.get_layout_left()); assert_eq!(0 as f32, root_child0.get_layout_top()); assert_eq!(200 as f32, root_child0.get_layout_width()); assert_eq!(120 as f32, root_child0.get_layout_height()); assert_eq!(0 as f32, root_child1.get_layout_left()); assert_eq!(120 as f32, root_child1.get_layout_top()); assert_eq!(200 as f32, root_child1.get_layout_width()); assert_eq!(40 as f32, root_child1.get_layout_height()); } #[test] fn test_percentage_flex_basis_main_max_width() { 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 as f32).into())); root.set_height(StyleUnit::Point((200 as f32).into())); let mut root_child0 = Node::new_with_config(&mut config); root_child0.set_flex_grow(1 as f32); root_child0.set_flex_basis(StyleUnit::Percent((15 as f32).into())); root_child0.set_min_width(StyleUnit::Auto); root_child0.set_max_width(StyleUnit::Percent((60 as f32).into())); root_child0.set_min_height(StyleUnit::Auto); root.insert_child(&mut root_child0, 0); let mut root_child1 = Node::new_with_config(&mut config); root_child1.set_flex_grow(4 as f32); root_child1.set_flex_basis(StyleUnit::Percent((10 as f32).into())); root_child1.set_min_width(StyleUnit::Auto); root_child1.set_max_width(StyleUnit::Percent((20 as f32).into())); root_child1.set_min_height(StyleUnit::Auto); root.insert_child(&mut root_child1, 1); root.calculate_layout(Undefined, Undefined, Direction::LTR); assert_eq!(0 as f32, root.get_layout_left()); assert_eq!(0 as f32, root.get_layout_top()); assert_eq!(200 as f32, root.get_layout_width()); assert_eq!(200 as f32, root.get_layout_height()); assert_eq!(0 as f32, root_child0.get_layout_left()); assert_eq!(0 as f32, root_child0.get_layout_top()); assert_eq!(120 as f32, root_child0.get_layout_width()); assert_eq!(200 as f32, root_child0.get_layout_height()); assert_eq!(120 as f32, root_child1.get_layout_left()); assert_eq!(0 as f32, root_child1.get_layout_top()); assert_eq!(40 as f32, root_child1.get_layout_width()); assert_eq!(200 as f32, root_child1.get_layout_height()); root.calculate_layout(Undefined, Undefined, Direction::RTL); assert_eq!(0 as f32, root.get_layout_left()); assert_eq!(0 as f32, root.get_layout_top()); assert_eq!(200 as f32, root.get_layout_width()); assert_eq!(200 as f32, root.get_layout_height()); assert_eq!(80 as f32, root_child0.get_layout_left()); assert_eq!(0 as f32, root_child0.get_layout_top()); assert_eq!(120 as f32, root_child0.get_layout_width()); assert_eq!(200 as f32, root_child0.get_layout_height()); assert_eq!(40 as f32, root_child1.get_layout_left()); assert_eq!(0 as f32, root_child1.get_layout_top()); assert_eq!(40 as f32, root_child1.get_layout_width()); assert_eq!(200 as f32, root_child1.get_layout_height()); } #[test] fn test_percentage_flex_basis_cross_max_width() { let mut config = Config::new(); let mut root = Node::new_with_config(&mut config); root.set_width(StyleUnit::Point((200 as f32).into())); root.set_height(StyleUnit::Point((200 as f32).into())); let mut root_child0 = Node::new_with_config(&mut config); root_child0.set_flex_grow(1 as f32); root_child0.set_flex_basis(StyleUnit::Percent((10 as f32).into())); root_child0.set_min_width(StyleUnit::Auto); root_child0.set_max_width(StyleUnit::Percent((60 as f32).into())); root_child0.set_min_height(StyleUnit::Auto); root.insert_child(&mut root_child0, 0); let mut root_child1 = Node::new_with_config(&mut config); root_child1.set_flex_grow(4 as f32); root_child1.set_flex_basis(StyleUnit::Percent((15 as f32).into())); root_child1.set_min_width(StyleUnit::Auto); root_child1.set_max_width(StyleUnit::Percent((20 as f32).into())); root_child1.set_min_height(StyleUnit::Auto); root.insert_child(&mut root_child1, 1); root.calculate_layout(Undefined, Undefined, Direction::LTR); assert_eq!(0 as f32, root.get_layout_left()); assert_eq!(0 as f32, root.get_layout_top()); assert_eq!(200 as f32, root.get_layout_width()); assert_eq!(200 as f32, root.get_layout_height()); assert_eq!(0 as f32, root_child0.get_layout_left()); assert_eq!(0 as f32, root_child0.get_layout_top()); assert_eq!(120 as f32, root_child0.get_layout_width()); assert_eq!(50 as f32, root_child0.get_layout_height()); assert_eq!(0 as f32, root_child1.get_layout_left()); assert_eq!(50 as f32, root_child1.get_layout_top()); assert_eq!(40 as f32, root_child1.get_layout_width()); assert_eq!(150 as f32, root_child1.get_layout_height()); root.calculate_layout(Undefined, Undefined, Direction::RTL); assert_eq!(0 as f32, root.get_layout_left()); assert_eq!(0 as f32, root.get_layout_top()); assert_eq!(200 as f32, root.get_layout_width()); assert_eq!(200 as f32, root.get_layout_height()); assert_eq!(80 as f32, root_child0.get_layout_left()); assert_eq!(0 as f32, root_child0.get_layout_top()); assert_eq!(120 as f32, root_child0.get_layout_width()); assert_eq!(50 as f32, root_child0.get_layout_height()); assert_eq!(160 as f32, root_child1.get_layout_left()); assert_eq!(50 as f32, root_child1.get_layout_top()); assert_eq!(40 as f32, root_child1.get_layout_width()); assert_eq!(150 as f32, root_child1.get_layout_height()); } #[test] fn test_percentage_flex_basis_main_min_width() { 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 as f32).into())); root.set_height(StyleUnit::Point((200 as f32).into())); let mut root_child0 = Node::new_with_config(&mut config); root_child0.set_flex_grow(1 as f32); root_child0.set_flex_basis(StyleUnit::Percent((15 as f32).into())); root_child0.set_min_width(StyleUnit::Percent((60 as f32).into())); root_child0.set_min_height(StyleUnit::Auto); root.insert_child(&mut root_child0, 0); let mut root_child1 = Node::new_with_config(&mut config); root_child1.set_flex_grow(4 as f32); root_child1.set_flex_basis(StyleUnit::Percent((10 as f32).into())); root_child1.set_min_width(StyleUnit::Percent((20 as f32).into())); root_child1.set_min_height(StyleUnit::Auto); root.insert_child(&mut root_child1, 1); root.calculate_layout(Undefined, Undefined, Direction::LTR); assert_eq!(0 as f32, root.get_layout_left()); assert_eq!(0 as f32, root.get_layout_top()); assert_eq!(200 as f32, root.get_layout_width()); assert_eq!(200 as f32, root.get_layout_height()); assert_eq!(0 as f32, root_child0.get_layout_left()); assert_eq!(0 as f32, root_child0.get_layout_top()); assert_eq!(120 as f32, root_child0.get_layout_width()); assert_eq!(200 as f32, root_child0.get_layout_height()); assert_eq!(120 as f32, root_child1.get_layout_left()); assert_eq!(0 as f32, root_child1.get_layout_top()); assert_eq!(80 as f32, root_child1.get_layout_width()); assert_eq!(200 as f32, root_child1.get_layout_height()); root.calculate_layout(Undefined, Undefined, Direction::RTL); assert_eq!(0 as f32, root.get_layout_left()); assert_eq!(0 as f32, root.get_layout_top()); assert_eq!(200 as f32, root.get_layout_width()); assert_eq!(200 as f32, root.get_layout_height()); assert_eq!(80 as f32, root_child0.get_layout_left()); assert_eq!(0 as f32, root_child0.get_layout_top()); assert_eq!(120 as f32, root_child0.get_layout_width()); assert_eq!(200 as f32, root_child0.get_layout_height()); assert_eq!(0 as f32, root_child1.get_layout_left()); assert_eq!(0 as f32, root_child1.get_layout_top()); assert_eq!(80 as f32, root_child1.get_layout_width()); assert_eq!(200 as f32, root_child1.get_layout_height()); } #[test] fn test_percentage_flex_basis_cross_min_width() { let mut config = Config::new(); let mut root = Node::new_with_config(&mut config); root.set_width(StyleUnit::Point((200 as f32).into())); root.set_height(StyleUnit::Point((200 as f32).into())); let mut root_child0 = Node::new_with_config(&mut config); root_child0.set_flex_grow(1 as f32); root_child0.set_flex_basis(StyleUnit::Percent((10 as f32).into())); root_child0.set_min_width(StyleUnit::Percent((60 as f32).into())); root_child0.set_min_height(StyleUnit::Auto); root.insert_child(&mut root_child0, 0); let mut root_child1 = Node::new_with_config(&mut config); root_child1.set_flex_grow(4 as f32); root_child1.set_flex_basis(StyleUnit::Percent((15 as f32).into())); root_child1.set_min_width(StyleUnit::Percent((20 as f32).into())); root_child1.set_min_height(StyleUnit::Auto); root.insert_child(&mut root_child1, 1); root.calculate_layout(Undefined, Undefined, Direction::LTR); assert_eq!(0 as f32, root.get_layout_left()); assert_eq!(0 as f32, root.get_layout_top()); assert_eq!(200 as f32, root.get_layout_width()); assert_eq!(200 as f32, root.get_layout_height()); assert_eq!(0 as f32, root_child0.get_layout_left()); assert_eq!(0 as f32, root_child0.get_layout_top()); assert_eq!(200 as f32, root_child0.get_layout_width()); assert_eq!(50 as f32, root_child0.get_layout_height()); assert_eq!(0 as f32, root_child1.get_layout_left()); assert_eq!(50 as f32, root_child1.get_layout_top()); assert_eq!(200 as f32, root_child1.get_layout_width()); assert_eq!(150 as f32, root_child1.get_layout_height()); root.calculate_layout(Undefined, Undefined, Direction::RTL); assert_eq!(0 as f32, root.get_layout_left()); assert_eq!(0 as f32, root.get_layout_top()); assert_eq!(200 as f32, root.get_layout_width()); assert_eq!(200 as f32, root.get_layout_height()); assert_eq!(0 as f32, root_child0.get_layout_left()); assert_eq!(0 as f32, root_child0.get_layout_top()); assert_eq!(200 as f32, root_child0.get_layout_width()); assert_eq!(50 as f32, root_child0.get_layout_height()); assert_eq!(0 as f32, root_child1.get_layout_left()); assert_eq!(50 as f32, root_child1.get_layout_top()); assert_eq!(200 as f32, root_child1.get_layout_width()); assert_eq!(150 as f32, root_child1.get_layout_height()); } #[test] fn test_percentage_multiple_nested_with_padding_margin_and_percentage_values() { let mut config = Config::new(); let mut root = Node::new_with_config(&mut config); root.set_width(StyleUnit::Point((200 as f32).into())); root.set_height(StyleUnit::Point((200 as f32).into())); let mut root_child0 = Node::new_with_config(&mut config); root_child0.set_flex_grow(1 as f32); root_child0.set_flex_basis(StyleUnit::Percent((10 as f32).into())); root_child0.set_margin(Edge::Left, StyleUnit::Point((5 as f32).into())); root_child0.set_margin(Edge::Top, StyleUnit::Point((5 as f32).into())); root_child0.set_margin(Edge::Right, StyleUnit::Point((5 as f32).into())); root_child0.set_margin(Edge::Bottom, StyleUnit::Point((5 as f32).into())); root_child0.set_padding(Edge::Left, StyleUnit::Point((3 as f32).into())); root_child0.set_padding(Edge::Top, StyleUnit::Point((3 as f32).into())); root_child0.set_padding(Edge::Right, StyleUnit::Point((3 as f32).into())); root_child0.set_padding(Edge::Bottom, StyleUnit::Point((3 as f32).into())); root_child0.set_min_width(StyleUnit::Percent((60 as f32).into())); root_child0.set_min_height(StyleUnit::Auto); 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((5 as f32).into())); root_child0_child0.set_margin(Edge::Top, StyleUnit::Point((5 as f32).into())); root_child0_child0.set_margin(Edge::Right, StyleUnit::Point((5 as f32).into())); root_child0_child0.set_margin(Edge::Bottom, StyleUnit::Point((5 as f32).into())); root_child0_child0.set_padding(Edge::Left, StyleUnit::Percent((3 as f32).into())); root_child0_child0.set_padding(Edge::Top, StyleUnit::Percent((3 as f32).into())); root_child0_child0.set_padding(Edge::Right, StyleUnit::Percent((3 as f32).into())); root_child0_child0.set_padding(Edge::Bottom, StyleUnit::Percent((3 as f32).into())); root_child0_child0.set_width(StyleUnit::Percent((50 as f32).into())); root_child0_child0.set_min_width(StyleUnit::Auto); root_child0_child0.set_min_height(StyleUnit::Auto); 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_margin(Edge::Left, StyleUnit::Percent((5 as f32).into())); root_child0_child0_child0.set_margin(Edge::Top, StyleUnit::Percent((5 as f32).into())); root_child0_child0_child0.set_margin(Edge::Right, StyleUnit::Percent((5 as f32).into())); root_child0_child0_child0.set_margin(Edge::Bottom, StyleUnit::Percent((5 as f32).into())); root_child0_child0_child0.set_padding(Edge::Left, StyleUnit::Point((3 as f32).into())); root_child0_child0_child0.set_padding(Edge::Top, StyleUnit::Point((3 as f32).into())); root_child0_child0_child0.set_padding(Edge::Right, StyleUnit::Point((3 as f32).into())); root_child0_child0_child0.set_padding(Edge::Bottom, StyleUnit::Point((3 as f32).into())); root_child0_child0_child0.set_width(StyleUnit::Percent((45 as f32).into())); root_child0_child0_child0.set_min_width(StyleUnit::Auto); root_child0_child0_child0.set_min_height(StyleUnit::Auto); root_child0_child0.insert_child(&mut root_child0_child0_child0, 0); let mut root_child1 = Node::new_with_config(&mut config); root_child1.set_flex_grow(4 as f32); root_child1.set_flex_basis(StyleUnit::Percent((15 as f32).into())); root_child1.set_min_width(StyleUnit::Percent((20 as f32).into())); root_child1.set_min_height(StyleUnit::Auto); root.insert_child(&mut root_child1, 1); root.calculate_layout(Undefined, Undefined, Direction::LTR); assert_eq!(0 as f32, root.get_layout_left()); assert_eq!(0 as f32, root.get_layout_top()); assert_eq!(200 as f32, root.get_layout_width()); assert_eq!(200 as f32, root.get_layout_height()); assert_eq!(5 as f32, root_child0.get_layout_left()); assert_eq!(5 as f32, root_child0.get_layout_top()); assert_eq!(190 as f32, root_child0.get_layout_width()); assert_eq!(48 as f32, root_child0.get_layout_height()); assert_eq!(8 as f32, root_child0_child0.get_layout_left()); assert_eq!(8 as f32, root_child0_child0.get_layout_top()); assert_eq!(92 as f32, root_child0_child0.get_layout_width()); assert_eq!(25 as f32, root_child0_child0.get_layout_height()); assert_eq!(10 as f32, root_child0_child0_child0.get_layout_left()); assert_eq!(10 as f32, root_child0_child0_child0.get_layout_top()); assert_eq!(36 as f32, root_child0_child0_child0.get_layout_width()); assert_eq!(6 as f32, root_child0_child0_child0.get_layout_height()); assert_eq!(0 as f32, root_child1.get_layout_left()); assert_eq!(58 as f32, root_child1.get_layout_top()); assert_eq!(200 as f32, root_child1.get_layout_width()); assert_eq!(142 as f32, root_child1.get_layout_height()); root.calculate_layout(Undefined, Undefined, Direction::RTL); assert_eq!(0 as f32, root.get_layout_left()); assert_eq!(0 as f32, root.get_layout_top()); assert_eq!(200 as f32, root.get_layout_width()); assert_eq!(200 as f32, root.get_layout_height()); assert_eq!(5 as f32, root_child0.get_layout_left()); assert_eq!(5 as f32, root_child0.get_layout_top()); assert_eq!(190 as f32, root_child0.get_layout_width()); assert_eq!(48 as f32, root_child0.get_layout_height()); assert_eq!(90 as f32, root_child0_child0.get_layout_left()); assert_eq!(8 as f32, root_child0_child0.get_layout_top()); assert_eq!(92 as f32, root_child0_child0.get_layout_width()); assert_eq!(25 as f32, root_child0_child0.get_layout_height()); assert_eq!(46 as f32, root_child0_child0_child0.get_layout_left()); assert_eq!(10 as f32, root_child0_child0_child0.get_layout_top()); assert_eq!(36 as f32, root_child0_child0_child0.get_layout_width()); assert_eq!(6 as f32, root_child0_child0_child0.get_layout_height()); assert_eq!(0 as f32, root_child1.get_layout_left()); assert_eq!(58 as f32, root_child1.get_layout_top()); assert_eq!(200 as f32, root_child1.get_layout_width()); assert_eq!(142 as f32, root_child1.get_layout_height()); } #[test] fn test_percentage_margin_should_calculate_based_only_on_width() { let mut config = Config::new(); let mut root = Node::new_with_config(&mut config); root.set_width(StyleUnit::Point((200 as f32).into())); root.set_height(StyleUnit::Point((100 as f32).into())); let mut root_child0 = Node::new_with_config(&mut config); root_child0.set_flex_grow(1 as f32); root_child0.set_margin(Edge::Left, StyleUnit::Percent((10 as f32).into())); root_child0.set_margin(Edge::Top, StyleUnit::Percent((10 as f32).into())); root_child0.set_margin(Edge::Right, StyleUnit::Percent((10 as f32).into())); root_child0.set_margin(Edge::Bottom, StyleUnit::Percent((10 as f32).into())); root_child0.set_min_width(StyleUnit::Auto); root_child0.set_min_height(StyleUnit::Auto); 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((10 as f32).into())); root_child0_child0.set_min_width(StyleUnit::Auto); root_child0_child0.set_height(StyleUnit::Point((10 as f32).into())); root_child0_child0.set_min_height(StyleUnit::Auto); root_child0.insert_child(&mut root_child0_child0, 0); root.calculate_layout(Undefined, Undefined, Direction::LTR); assert_eq!(0 as f32, root.get_layout_left()); assert_eq!(0 as f32, root.get_layout_top()); assert_eq!(200 as f32, root.get_layout_width()); assert_eq!(100 as f32, root.get_layout_height()); assert_eq!(20 as f32, root_child0.get_layout_left()); assert_eq!(20 as f32, root_child0.get_layout_top()); assert_eq!(160 as f32, root_child0.get_layout_width()); assert_eq!(60 as f32, root_child0.get_layout_height()); assert_eq!(0 as f32, root_child0_child0.get_layout_left()); assert_eq!(0 as f32, root_child0_child0.get_layout_top()); assert_eq!(10 as f32, root_child0_child0.get_layout_width()); assert_eq!(10 as f32, root_child0_child0.get_layout_height()); root.calculate_layout(Undefined, Undefined, Direction::RTL); assert_eq!(0 as f32, root.get_layout_left()); assert_eq!(0 as f32, root.get_layout_top()); assert_eq!(200 as f32, root.get_layout_width()); assert_eq!(100 as f32, root.get_layout_height()); assert_eq!(20 as f32, root_child0.get_layout_left()); assert_eq!(20 as f32, root_child0.get_layout_top()); assert_eq!(160 as f32, root_child0.get_layout_width()); assert_eq!(60 as f32, root_child0.get_layout_height()); assert_eq!(150 as f32, root_child0_child0.get_layout_left()); assert_eq!(0 as f32, root_child0_child0.get_layout_top()); assert_eq!(10 as f32, root_child0_child0.get_layout_width()); assert_eq!(10 as f32, root_child0_child0.get_layout_height()); } #[test] fn test_percentage_padding_should_calculate_based_only_on_width() { let mut config = Config::new(); let mut root = Node::new_with_config(&mut config); root.set_width(StyleUnit::Point((200 as f32).into())); root.set_height(StyleUnit::Point((100 as f32).into())); let mut root_child0 = Node::new_with_config(&mut config); root_child0.set_flex_grow(1 as f32); root_child0.set_padding(Edge::Left, StyleUnit::Percent((10 as f32).into())); root_child0.set_padding(Edge::Top, StyleUnit::Percent((10 as f32).into())); root_child0.set_padding(Edge::Right, StyleUnit::Percent((10 as f32).into())); root_child0.set_padding(Edge::Bottom, StyleUnit::Percent((10 as f32).into())); root_child0.set_min_width(StyleUnit::Auto); root_child0.set_min_height(StyleUnit::Auto); 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((10 as f32).into())); root_child0_child0.set_min_width(StyleUnit::Auto); root_child0_child0.set_height(StyleUnit::Point((10 as f32).into())); root_child0_child0.set_min_height(StyleUnit::Auto); root_child0.insert_child(&mut root_child0_child0, 0); root.calculate_layout(Undefined, Undefined, Direction::LTR); assert_eq!(0 as f32, root.get_layout_left()); assert_eq!(0 as f32, root.get_layout_top()); assert_eq!(200 as f32, root.get_layout_width()); assert_eq!(100 as f32, root.get_layout_height()); assert_eq!(0 as f32, root_child0.get_layout_left()); assert_eq!(0 as f32, root_child0.get_layout_top()); assert_eq!(200 as f32, root_child0.get_layout_width()); assert_eq!(100 as f32, root_child0.get_layout_height()); assert_eq!(20 as f32, root_child0_child0.get_layout_left()); assert_eq!(20 as f32, root_child0_child0.get_layout_top()); assert_eq!(10 as f32, root_child0_child0.get_layout_width()); assert_eq!(10 as f32, root_child0_child0.get_layout_height()); root.calculate_layout(Undefined, Undefined, Direction::RTL); assert_eq!(0 as f32, root.get_layout_left()); assert_eq!(0 as f32, root.get_layout_top()); assert_eq!(200 as f32, root.get_layout_width()); assert_eq!(100 as f32, root.get_layout_height()); assert_eq!(0 as f32, root_child0.get_layout_left()); assert_eq!(0 as f32, root_child0.get_layout_top()); assert_eq!(200 as f32, root_child0.get_layout_width()); assert_eq!(100 as f32, root_child0.get_layout_height()); assert_eq!(170 as f32, root_child0_child0.get_layout_left()); assert_eq!(20 as f32, root_child0_child0.get_layout_top()); assert_eq!(10 as f32, root_child0_child0.get_layout_width()); assert_eq!(10 as f32, root_child0_child0.get_layout_height()); } #[test] fn test_percentage_absolute_position() { let mut config = Config::new(); let mut root = Node::new_with_config(&mut config); root.set_width(StyleUnit::Point((200 as f32).into())); root.set_height(StyleUnit::Point((100 as f32).into())); let mut root_child0 = Node::new_with_config(&mut config); root_child0.set_position_type(PositionType::Absolute); root_child0.set_position(Edge::Left, StyleUnit::Percent((30 as f32).into())); root_child0.set_position(Edge::Top, StyleUnit::Percent((10 as f32).into())); root_child0.set_width(StyleUnit::Point((10 as f32).into())); root_child0.set_height(StyleUnit::Point((10 as f32).into())); root.insert_child(&mut root_child0, 0); root.calculate_layout(Undefined, Undefined, Direction::LTR); assert_eq!(0 as f32, root.get_layout_left()); assert_eq!(0 as f32, root.get_layout_top()); assert_eq!(200 as f32, root.get_layout_width()); assert_eq!(100 as f32, root.get_layout_height()); assert_eq!(60 as f32, root_child0.get_layout_left()); assert_eq!(10 as f32, root_child0.get_layout_top()); assert_eq!(10 as f32, root_child0.get_layout_width()); assert_eq!(10 as f32, root_child0.get_layout_height()); root.calculate_layout(Undefined, Undefined, Direction::RTL); assert_eq!(0 as f32, root.get_layout_left()); assert_eq!(0 as f32, root.get_layout_top()); assert_eq!(200 as f32, root.get_layout_width()); assert_eq!(100 as f32, root.get_layout_height()); assert_eq!(60 as f32, root_child0.get_layout_left()); assert_eq!(10 as f32, root_child0.get_layout_top()); assert_eq!(10 as f32, root_child0.get_layout_width()); assert_eq!(10 as f32, root_child0.get_layout_height()); } #[test] fn test_percentage_width_height_undefined_parent_size() { let mut config = Config::new(); let mut root = Node::new_with_config(&mut config); let mut root_child0 = Node::new_with_config(&mut config); root_child0.set_width(StyleUnit::Percent((50 as f32).into())); root_child0.set_min_width(StyleUnit::Auto); root_child0.set_height(StyleUnit::Percent((50 as f32).into())); root_child0.set_min_height(StyleUnit::Auto); root.insert_child(&mut root_child0, 0); root.calculate_layout(Undefined, Undefined, Direction::LTR); assert_eq!(0 as f32, root.get_layout_left()); assert_eq!(0 as f32, root.get_layout_top()); assert_eq!(0 as f32, root.get_layout_width()); assert_eq!(0 as f32, root.get_layout_height()); assert_eq!(0 as f32, root_child0.get_layout_left()); assert_eq!(0 as f32, root_child0.get_layout_top()); assert_eq!(0 as f32, root_child0.get_layout_width()); assert_eq!(0 as f32, root_child0.get_layout_height()); root.calculate_layout(Undefined, Undefined, Direction::RTL); assert_eq!(0 as f32, root.get_layout_left()); assert_eq!(0 as f32, root.get_layout_top()); assert_eq!(0 as f32, root.get_layout_width()); assert_eq!(0 as f32, root.get_layout_height()); assert_eq!(0 as f32, root_child0.get_layout_left()); assert_eq!(0 as f32, root_child0.get_layout_top()); assert_eq!(0 as f32, root_child0.get_layout_width()); assert_eq!(0 as f32, root_child0.get_layout_height()); } #[test] fn test_percent_within_flex_grow() { 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((350 as f32).into())); root.set_height(StyleUnit::Point((100 as f32).into())); let mut root_child0 = Node::new_with_config(&mut config); root_child0.set_width(StyleUnit::Point((100 as f32).into())); root_child0.set_min_width(StyleUnit::Auto); root_child0.set_min_height(StyleUnit::Auto); root.insert_child(&mut root_child0, 0); let mut root_child1 = Node::new_with_config(&mut config); root_child1.set_flex_grow(1 as f32); root_child1.set_min_width(StyleUnit::Auto); root_child1.set_min_height(StyleUnit::Auto); root.insert_child(&mut root_child1, 1); let mut root_child1_child0 = Node::new_with_config(&mut config); root_child1_child0.set_width(StyleUnit::Percent((100 as f32).into())); root_child1_child0.set_min_width(StyleUnit::Auto); root_child1_child0.set_min_height(StyleUnit::Auto); 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((100 as f32).into())); root_child2.set_min_width(StyleUnit::Auto); root_child2.set_min_height(StyleUnit::Auto); root.insert_child(&mut root_child2, 2); root.calculate_layout(Undefined, Undefined, Direction::LTR); assert_eq!(0 as f32, root.get_layout_left()); assert_eq!(0 as f32, root.get_layout_top()); assert_eq!(350 as f32, root.get_layout_width()); assert_eq!(100 as f32, root.get_layout_height()); assert_eq!(0 as f32, root_child0.get_layout_left()); assert_eq!(0 as f32, root_child0.get_layout_top()); assert_eq!(100 as f32, root_child0.get_layout_width()); assert_eq!(100 as f32, root_child0.get_layout_height()); assert_eq!(100 as f32, root_child1.get_layout_left()); assert_eq!(0 as f32, root_child1.get_layout_top()); assert_eq!(150 as f32, root_child1.get_layout_width()); assert_eq!(100 as f32, root_child1.get_layout_height()); assert_eq!(0 as f32, root_child1_child0.get_layout_left()); assert_eq!(0 as f32, root_child1_child0.get_layout_top()); assert_eq!(150 as f32, root_child1_child0.get_layout_width()); assert_eq!(0 as f32, root_child1_child0.get_layout_height()); assert_eq!(250 as f32, root_child2.get_layout_left()); assert_eq!(0 as f32, root_child2.get_layout_top()); assert_eq!(100 as f32, root_child2.get_layout_width()); assert_eq!(100 as f32, root_child2.get_layout_height()); root.calculate_layout(Undefined, Undefined, Direction::RTL); assert_eq!(0 as f32, root.get_layout_left()); assert_eq!(0 as f32, root.get_layout_top()); assert_eq!(350 as f32, root.get_layout_width()); assert_eq!(100 as f32, root.get_layout_height()); assert_eq!(250 as f32, root_child0.get_layout_left()); assert_eq!(0 as f32, root_child0.get_layout_top()); assert_eq!(100 as f32, root_child0.get_layout_width()); assert_eq!(100 as f32, root_child0.get_layout_height()); assert_eq!(100 as f32, root_child1.get_layout_left()); assert_eq!(0 as f32, root_child1.get_layout_top()); assert_eq!(150 as f32, root_child1.get_layout_width()); assert_eq!(100 as f32, root_child1.get_layout_height()); assert_eq!(0 as f32, root_child1_child0.get_layout_left()); assert_eq!(0 as f32, root_child1_child0.get_layout_top()); assert_eq!(150 as f32, root_child1_child0.get_layout_width()); assert_eq!(0 as f32, root_child1_child0.get_layout_height()); assert_eq!(0 as f32, root_child2.get_layout_left()); assert_eq!(0 as f32, root_child2.get_layout_top()); assert_eq!(100 as f32, root_child2.get_layout_width()); assert_eq!(100 as f32, root_child2.get_layout_height()); } #[test] fn test_percentage_container_in_wrapping_container() { 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((200 as f32).into())); root.set_height(StyleUnit::Point((200 as f32).into())); let mut root_child0 = Node::new_with_config(&mut config); root_child0.set_min_width(StyleUnit::Auto); root_child0.set_min_height(StyleUnit::Auto); root.insert_child(&mut root_child0, 0); let mut root_child0_child0 = Node::new_with_config(&mut config); root_child0_child0.set_flex_direction(FlexDirection::Row); root_child0_child0.set_justify_content(Justify::Center); root_child0_child0.set_width(StyleUnit::Percent((100 as f32).into())); root_child0_child0.set_min_width(StyleUnit::Auto); root_child0_child0.set_min_height(StyleUnit::Auto); 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((50 as f32).into())); root_child0_child0_child0.set_min_width(StyleUnit::Auto); root_child0_child0_child0.set_height(StyleUnit::Point((50 as f32).into())); root_child0_child0_child0.set_min_height(StyleUnit::Auto); root_child0_child0.insert_child(&mut root_child0_child0_child0, 0); let mut root_child0_child0_child1 = Node::new_with_config(&mut config); root_child0_child0_child1.set_width(StyleUnit::Point((50 as f32).into())); root_child0_child0_child1.set_min_width(StyleUnit::Auto); root_child0_child0_child1.set_height(StyleUnit::Point((50 as f32).into())); root_child0_child0_child1.set_min_height(StyleUnit::Auto); root_child0_child0.insert_child(&mut root_child0_child0_child1, 1); root.calculate_layout(Undefined, Undefined, Direction::LTR); assert_eq!(0 as f32, root.get_layout_left()); assert_eq!(0 as f32, root.get_layout_top()); assert_eq!(200 as f32, root.get_layout_width()); assert_eq!(200 as f32, root.get_layout_height()); assert_eq!(50 as f32, root_child0.get_layout_left()); assert_eq!(75 as f32, root_child0.get_layout_top()); assert_eq!(100 as f32, root_child0.get_layout_width()); assert_eq!(50 as f32, root_child0.get_layout_height()); assert_eq!(0 as f32, root_child0_child0.get_layout_left()); assert_eq!(0 as f32, root_child0_child0.get_layout_top()); assert_eq!(100 as f32, root_child0_child0.get_layout_width()); assert_eq!(50 as f32, root_child0_child0.get_layout_height()); assert_eq!(0 as f32, root_child0_child0_child0.get_layout_left()); assert_eq!(0 as f32, root_child0_child0_child0.get_layout_top()); assert_eq!(50 as f32, root_child0_child0_child0.get_layout_width()); assert_eq!(50 as f32, root_child0_child0_child0.get_layout_height()); assert_eq!(50 as f32, root_child0_child0_child1.get_layout_left()); assert_eq!(0 as f32, root_child0_child0_child1.get_layout_top()); assert_eq!(50 as f32, root_child0_child0_child1.get_layout_width()); assert_eq!(50 as f32, root_child0_child0_child1.get_layout_height()); root.calculate_layout(Undefined, Undefined, Direction::RTL); assert_eq!(0 as f32, root.get_layout_left()); assert_eq!(0 as f32, root.get_layout_top()); assert_eq!(200 as f32, root.get_layout_width()); assert_eq!(200 as f32, root.get_layout_height()); assert_eq!(50 as f32, root_child0.get_layout_left()); assert_eq!(75 as f32, root_child0.get_layout_top()); assert_eq!(100 as f32, root_child0.get_layout_width()); assert_eq!(50 as f32, root_child0.get_layout_height()); assert_eq!(0 as f32, root_child0_child0.get_layout_left()); assert_eq!(0 as f32, root_child0_child0.get_layout_top()); assert_eq!(100 as f32, root_child0_child0.get_layout_width()); assert_eq!(50 as f32, root_child0_child0.get_layout_height()); assert_eq!(50 as f32, root_child0_child0_child0.get_layout_left()); assert_eq!(0 as f32, root_child0_child0_child0.get_layout_top()); assert_eq!(50 as f32, root_child0_child0_child0.get_layout_width()); assert_eq!(50 as f32, root_child0_child0_child0.get_layout_height()); assert_eq!(0 as f32, root_child0_child0_child1.get_layout_left()); assert_eq!(0 as f32, root_child0_child0_child1.get_layout_top()); assert_eq!(50 as f32, root_child0_child0_child1.get_layout_width()); assert_eq!(50 as f32, root_child0_child0_child1.get_layout_height()); } #[test] fn test_percent_absolute_position() { let mut config = Config::new(); let mut root = Node::new_with_config(&mut config); root.set_width(StyleUnit::Point((60 as f32).into())); root.set_height(StyleUnit::Point((50 as f32).into())); let mut root_child0 = Node::new_with_config(&mut config); root_child0.set_flex_direction(FlexDirection::Row); root_child0.set_position_type(PositionType::Absolute); root_child0.set_position(Edge::Left, StyleUnit::Percent((50 as f32).into())); root_child0.set_width(StyleUnit::Percent((100 as f32).into())); root_child0.set_height(StyleUnit::Point((50 as 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::Percent((100 as f32).into())); root_child0_child0.set_min_width(StyleUnit::Auto); root_child0_child0.set_min_height(StyleUnit::Auto); root_child0.insert_child(&mut root_child0_child0, 0); let mut root_child0_child1 = Node::new_with_config(&mut config); root_child0_child1.set_width(StyleUnit::Percent((100 as f32).into())); root_child0_child1.set_min_width(StyleUnit::Auto); root_child0_child1.set_min_height(StyleUnit::Auto); root_child0.insert_child(&mut root_child0_child1, 1); root.calculate_layout(Undefined, Undefined, Direction::LTR); assert_eq!(0 as f32, root.get_layout_left()); assert_eq!(0 as f32, root.get_layout_top()); assert_eq!(60 as f32, root.get_layout_width()); assert_eq!(50 as f32, root.get_layout_height()); assert_eq!(30 as f32, root_child0.get_layout_left()); assert_eq!(0 as f32, root_child0.get_layout_top()); assert_eq!(60 as f32, root_child0.get_layout_width()); assert_eq!(50 as f32, root_child0.get_layout_height()); assert_eq!(0 as f32, root_child0_child0.get_layout_left()); assert_eq!(0 as f32, root_child0_child0.get_layout_top()); assert_eq!(60 as f32, root_child0_child0.get_layout_width()); assert_eq!(50 as f32, root_child0_child0.get_layout_height()); assert_eq!(60 as f32, root_child0_child1.get_layout_left()); assert_eq!(0 as f32, root_child0_child1.get_layout_top()); assert_eq!(60 as f32, root_child0_child1.get_layout_width()); assert_eq!(50 as f32, root_child0_child1.get_layout_height()); root.calculate_layout(Undefined, Undefined, Direction::RTL); assert_eq!(0 as f32, root.get_layout_left()); assert_eq!(0 as f32, root.get_layout_top()); assert_eq!(60 as f32, root.get_layout_width()); assert_eq!(50 as f32, root.get_layout_height()); assert_eq!(30 as f32, root_child0.get_layout_left()); assert_eq!(0 as f32, root_child0.get_layout_top()); assert_eq!(60 as f32, root_child0.get_layout_width()); assert_eq!(50 as f32, root_child0.get_layout_height()); assert_eq!(0 as f32, root_child0_child0.get_layout_left()); assert_eq!(0 as f32, root_child0_child0.get_layout_top()); assert_eq!(60 as f32, root_child0_child0.get_layout_width()); assert_eq!(50 as f32, root_child0_child0.get_layout_height()); assert_eq!(-60 as f32, root_child0_child1.get_layout_left()); assert_eq!(0 as f32, root_child0_child1.get_layout_top()); assert_eq!(60 as f32, root_child0_child1.get_layout_width()); assert_eq!(50 as f32, root_child0_child1.get_layout_height()); }