#[test] fn grid_absolute_resolved_insets() { #[allow(unused_imports)] use taffy::{prelude::*, tree::Layout, TaffyTree}; let mut taffy: TaffyTree = TaffyTree::new(); let node00 = taffy .new_leaf(taffy::style::Style { position: taffy::style::Position::Absolute, inset: taffy::geometry::Rect { left: taffy::style::LengthPercentageAuto::Auto, right: auto(), top: taffy::style::LengthPercentageAuto::Auto, bottom: auto(), }, ..Default::default() }) .unwrap(); let node01 = taffy .new_leaf(taffy::style::Style { position: taffy::style::Position::Absolute, inset: taffy::geometry::Rect { left: taffy::style::LengthPercentageAuto::Length(0f32), right: auto(), top: taffy::style::LengthPercentageAuto::Length(0f32), bottom: auto(), }, ..Default::default() }) .unwrap(); let node02 = taffy .new_leaf(taffy::style::Style { position: taffy::style::Position::Absolute, inset: taffy::geometry::Rect { left: taffy::style::LengthPercentageAuto::Percent(1f32), right: auto(), top: taffy::style::LengthPercentageAuto::Percent(1f32), bottom: auto(), }, ..Default::default() }) .unwrap(); let node03 = taffy .new_leaf(taffy::style::Style { position: taffy::style::Position::Absolute, inset: taffy::geometry::Rect { left: auto(), right: taffy::style::LengthPercentageAuto::Percent(1f32), top: auto(), bottom: taffy::style::LengthPercentageAuto::Percent(1f32), }, ..Default::default() }) .unwrap(); let node04 = taffy .new_leaf(taffy::style::Style { position: taffy::style::Position::Absolute, inset: taffy::geometry::Rect { left: taffy::style::LengthPercentageAuto::Length(30f32), right: auto(), top: taffy::style::LengthPercentageAuto::Length(30f32), bottom: auto(), }, ..Default::default() }) .unwrap(); let node05 = taffy .new_leaf(taffy::style::Style { position: taffy::style::Position::Absolute, size: taffy::geometry::Size { width: taffy::style::Dimension::Percent(1f32), height: taffy::style::Dimension::Percent(1f32), }, inset: taffy::geometry::Rect { left: taffy::style::LengthPercentageAuto::Length(0f32), right: auto(), top: taffy::style::LengthPercentageAuto::Length(0f32), bottom: auto(), }, ..Default::default() }) .unwrap(); let node0 = taffy .new_with_children( taffy::style::Style { display: taffy::style::Display::Grid, size: taffy::geometry::Size { width: taffy::style::Dimension::Length(200f32), height: taffy::style::Dimension::Length(200f32), }, padding: taffy::geometry::Rect { left: taffy::style::LengthPercentage::Length(15f32), right: taffy::style::LengthPercentage::Length(15f32), top: taffy::style::LengthPercentage::Length(15f32), bottom: taffy::style::LengthPercentage::Length(15f32), }, border: taffy::geometry::Rect { left: taffy::style::LengthPercentage::Length(20f32), right: taffy::style::LengthPercentage::Length(20f32), top: taffy::style::LengthPercentage::Length(20f32), bottom: taffy::style::LengthPercentage::Length(20f32), }, ..Default::default() }, &[node00, node01, node02, node03, node04, node05], ) .unwrap(); let node10 = taffy .new_leaf(taffy::style::Style { position: taffy::style::Position::Absolute, inset: taffy::geometry::Rect { left: taffy::style::LengthPercentageAuto::Auto, right: auto(), top: taffy::style::LengthPercentageAuto::Auto, bottom: auto(), }, ..Default::default() }) .unwrap(); let node11 = taffy .new_leaf(taffy::style::Style { position: taffy::style::Position::Absolute, inset: taffy::geometry::Rect { left: taffy::style::LengthPercentageAuto::Length(0f32), right: auto(), top: taffy::style::LengthPercentageAuto::Length(0f32), bottom: auto(), }, ..Default::default() }) .unwrap(); let node12 = taffy .new_leaf(taffy::style::Style { position: taffy::style::Position::Absolute, inset: taffy::geometry::Rect { left: taffy::style::LengthPercentageAuto::Percent(1f32), right: auto(), top: taffy::style::LengthPercentageAuto::Percent(1f32), bottom: auto(), }, ..Default::default() }) .unwrap(); let node13 = taffy .new_leaf(taffy::style::Style { position: taffy::style::Position::Absolute, inset: taffy::geometry::Rect { left: auto(), right: taffy::style::LengthPercentageAuto::Percent(1f32), top: auto(), bottom: taffy::style::LengthPercentageAuto::Percent(1f32), }, ..Default::default() }) .unwrap(); let node14 = taffy .new_leaf(taffy::style::Style { position: taffy::style::Position::Absolute, inset: taffy::geometry::Rect { left: taffy::style::LengthPercentageAuto::Length(30f32), right: auto(), top: taffy::style::LengthPercentageAuto::Length(30f32), bottom: auto(), }, ..Default::default() }) .unwrap(); let node15 = taffy .new_leaf(taffy::style::Style { position: taffy::style::Position::Absolute, size: taffy::geometry::Size { width: taffy::style::Dimension::Percent(1f32), height: taffy::style::Dimension::Percent(1f32), }, inset: taffy::geometry::Rect { left: taffy::style::LengthPercentageAuto::Length(0f32), right: auto(), top: taffy::style::LengthPercentageAuto::Length(0f32), bottom: auto(), }, ..Default::default() }) .unwrap(); let node1 = taffy .new_with_children( taffy::style::Style { display: taffy::style::Display::Grid, overflow: taffy::geometry::Point { x: taffy::style::Overflow::Scroll, y: taffy::style::Overflow::Scroll, }, scrollbar_width: 15f32, size: taffy::geometry::Size { width: taffy::style::Dimension::Length(200f32), height: taffy::style::Dimension::Length(200f32), }, padding: taffy::geometry::Rect { left: taffy::style::LengthPercentage::Length(15f32), right: taffy::style::LengthPercentage::Length(15f32), top: taffy::style::LengthPercentage::Length(15f32), bottom: taffy::style::LengthPercentage::Length(15f32), }, border: taffy::geometry::Rect { left: taffy::style::LengthPercentage::Length(20f32), right: taffy::style::LengthPercentage::Length(20f32), top: taffy::style::LengthPercentage::Length(20f32), bottom: taffy::style::LengthPercentage::Length(20f32), }, ..Default::default() }, &[node10, node11, node12, node13, node14, node15], ) .unwrap(); let node = taffy.new_with_children(taffy::style::Style { ..Default::default() }, &[node0, node1]).unwrap(); taffy.compute_layout_with_measure(node, taffy::geometry::Size::MAX_CONTENT, crate::test_measure_function).unwrap(); println!("\nComputed tree:"); taffy.print_tree(node); println!(); #[cfg_attr(not(feature = "content_size"), allow(unused_variables))] let layout @ Layout { size, location, .. } = taffy.layout(node).unwrap(); assert_eq!(size.width, 400f32, "width of node {:?}. Expected {}. Actual {}", node, 400f32, size.width); assert_eq!(size.height, 200f32, "height of node {:?}. Expected {}. Actual {}", node, 200f32, size.height); assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node, 0f32, location.x); assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node, 0f32, location.y); #[cfg(feature = "content_size")] assert_eq!( layout.scroll_width(), 0f32, "scroll_width of node {:?}. Expected {}. Actual {}", node, 0f32, layout.scroll_width() ); #[cfg(feature = "content_size")] assert_eq!( layout.scroll_height(), 0f32, "scroll_height of node {:?}. Expected {}. Actual {}", node, 0f32, layout.scroll_height() ); #[cfg_attr(not(feature = "content_size"), allow(unused_variables))] let layout @ Layout { size, location, .. } = taffy.layout(node0).unwrap(); assert_eq!(size.width, 200f32, "width of node {:?}. Expected {}. Actual {}", node0, 200f32, size.width); assert_eq!(size.height, 200f32, "height of node {:?}. Expected {}. Actual {}", node0, 200f32, size.height); assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node0, 0f32, location.x); assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node0, 0f32, location.y); #[cfg(feature = "content_size")] assert_eq!( layout.scroll_width(), 0f32, "scroll_width of node {:?}. Expected {}. Actual {}", node0, 0f32, layout.scroll_width() ); #[cfg(feature = "content_size")] assert_eq!( layout.scroll_height(), 0f32, "scroll_height of node {:?}. Expected {}. Actual {}", node0, 0f32, layout.scroll_height() ); #[cfg_attr(not(feature = "content_size"), allow(unused_variables))] let layout @ Layout { size, location, .. } = taffy.layout(node00).unwrap(); assert_eq!(size.width, 0f32, "width of node {:?}. Expected {}. Actual {}", node00, 0f32, size.width); assert_eq!(size.height, 0f32, "height of node {:?}. Expected {}. Actual {}", node00, 0f32, size.height); assert_eq!(location.x, 20f32, "x of node {:?}. Expected {}. Actual {}", node00, 20f32, location.x); assert_eq!(location.y, 20f32, "y of node {:?}. Expected {}. Actual {}", node00, 20f32, location.y); #[cfg(feature = "content_size")] assert_eq!( layout.scroll_width(), 0f32, "scroll_width of node {:?}. Expected {}. Actual {}", node00, 0f32, layout.scroll_width() ); #[cfg(feature = "content_size")] assert_eq!( layout.scroll_height(), 0f32, "scroll_height of node {:?}. Expected {}. Actual {}", node00, 0f32, layout.scroll_height() ); #[cfg_attr(not(feature = "content_size"), allow(unused_variables))] let layout @ Layout { size, location, .. } = taffy.layout(node01).unwrap(); assert_eq!(size.width, 0f32, "width of node {:?}. Expected {}. Actual {}", node01, 0f32, size.width); assert_eq!(size.height, 0f32, "height of node {:?}. Expected {}. Actual {}", node01, 0f32, size.height); assert_eq!(location.x, 20f32, "x of node {:?}. Expected {}. Actual {}", node01, 20f32, location.x); assert_eq!(location.y, 20f32, "y of node {:?}. Expected {}. Actual {}", node01, 20f32, location.y); #[cfg(feature = "content_size")] assert_eq!( layout.scroll_width(), 0f32, "scroll_width of node {:?}. Expected {}. Actual {}", node01, 0f32, layout.scroll_width() ); #[cfg(feature = "content_size")] assert_eq!( layout.scroll_height(), 0f32, "scroll_height of node {:?}. Expected {}. Actual {}", node01, 0f32, layout.scroll_height() ); #[cfg_attr(not(feature = "content_size"), allow(unused_variables))] let layout @ Layout { size, location, .. } = taffy.layout(node02).unwrap(); assert_eq!(size.width, 0f32, "width of node {:?}. Expected {}. Actual {}", node02, 0f32, size.width); assert_eq!(size.height, 0f32, "height of node {:?}. Expected {}. Actual {}", node02, 0f32, size.height); assert_eq!(location.x, 180f32, "x of node {:?}. Expected {}. Actual {}", node02, 180f32, location.x); assert_eq!(location.y, 180f32, "y of node {:?}. Expected {}. Actual {}", node02, 180f32, location.y); #[cfg(feature = "content_size")] assert_eq!( layout.scroll_width(), 0f32, "scroll_width of node {:?}. Expected {}. Actual {}", node02, 0f32, layout.scroll_width() ); #[cfg(feature = "content_size")] assert_eq!( layout.scroll_height(), 0f32, "scroll_height of node {:?}. Expected {}. Actual {}", node02, 0f32, layout.scroll_height() ); #[cfg_attr(not(feature = "content_size"), allow(unused_variables))] let layout @ Layout { size, location, .. } = taffy.layout(node03).unwrap(); assert_eq!(size.width, 0f32, "width of node {:?}. Expected {}. Actual {}", node03, 0f32, size.width); assert_eq!(size.height, 0f32, "height of node {:?}. Expected {}. Actual {}", node03, 0f32, size.height); assert_eq!(location.x, 20f32, "x of node {:?}. Expected {}. Actual {}", node03, 20f32, location.x); assert_eq!(location.y, 20f32, "y of node {:?}. Expected {}. Actual {}", node03, 20f32, location.y); #[cfg(feature = "content_size")] assert_eq!( layout.scroll_width(), 0f32, "scroll_width of node {:?}. Expected {}. Actual {}", node03, 0f32, layout.scroll_width() ); #[cfg(feature = "content_size")] assert_eq!( layout.scroll_height(), 0f32, "scroll_height of node {:?}. Expected {}. Actual {}", node03, 0f32, layout.scroll_height() ); #[cfg_attr(not(feature = "content_size"), allow(unused_variables))] let layout @ Layout { size, location, .. } = taffy.layout(node04).unwrap(); assert_eq!(size.width, 0f32, "width of node {:?}. Expected {}. Actual {}", node04, 0f32, size.width); assert_eq!(size.height, 0f32, "height of node {:?}. Expected {}. Actual {}", node04, 0f32, size.height); assert_eq!(location.x, 50f32, "x of node {:?}. Expected {}. Actual {}", node04, 50f32, location.x); assert_eq!(location.y, 50f32, "y of node {:?}. Expected {}. Actual {}", node04, 50f32, location.y); #[cfg(feature = "content_size")] assert_eq!( layout.scroll_width(), 0f32, "scroll_width of node {:?}. Expected {}. Actual {}", node04, 0f32, layout.scroll_width() ); #[cfg(feature = "content_size")] assert_eq!( layout.scroll_height(), 0f32, "scroll_height of node {:?}. Expected {}. Actual {}", node04, 0f32, layout.scroll_height() ); #[cfg_attr(not(feature = "content_size"), allow(unused_variables))] let layout @ Layout { size, location, .. } = taffy.layout(node05).unwrap(); assert_eq!(size.width, 160f32, "width of node {:?}. Expected {}. Actual {}", node05, 160f32, size.width); assert_eq!(size.height, 160f32, "height of node {:?}. Expected {}. Actual {}", node05, 160f32, size.height); assert_eq!(location.x, 20f32, "x of node {:?}. Expected {}. Actual {}", node05, 20f32, location.x); assert_eq!(location.y, 20f32, "y of node {:?}. Expected {}. Actual {}", node05, 20f32, location.y); #[cfg(feature = "content_size")] assert_eq!( layout.scroll_width(), 0f32, "scroll_width of node {:?}. Expected {}. Actual {}", node05, 0f32, layout.scroll_width() ); #[cfg(feature = "content_size")] assert_eq!( layout.scroll_height(), 0f32, "scroll_height of node {:?}. Expected {}. Actual {}", node05, 0f32, layout.scroll_height() ); #[cfg_attr(not(feature = "content_size"), allow(unused_variables))] let layout @ Layout { size, location, .. } = taffy.layout(node1).unwrap(); assert_eq!(size.width, 200f32, "width of node {:?}. Expected {}. Actual {}", node1, 200f32, size.width); assert_eq!(size.height, 200f32, "height of node {:?}. Expected {}. Actual {}", node1, 200f32, size.height); assert_eq!(location.x, 200f32, "x of node {:?}. Expected {}. Actual {}", node1, 200f32, location.x); assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node1, 0f32, location.y); #[cfg(feature = "content_size")] assert_eq!( layout.scroll_width(), 0f32, "scroll_width of node {:?}. Expected {}. Actual {}", node1, 0f32, layout.scroll_width() ); #[cfg(feature = "content_size")] assert_eq!( layout.scroll_height(), 0f32, "scroll_height of node {:?}. Expected {}. Actual {}", node1, 0f32, layout.scroll_height() ); #[cfg_attr(not(feature = "content_size"), allow(unused_variables))] let layout @ Layout { size, location, .. } = taffy.layout(node10).unwrap(); assert_eq!(size.width, 0f32, "width of node {:?}. Expected {}. Actual {}", node10, 0f32, size.width); assert_eq!(size.height, 0f32, "height of node {:?}. Expected {}. Actual {}", node10, 0f32, size.height); assert_eq!(location.x, 20f32, "x of node {:?}. Expected {}. Actual {}", node10, 20f32, location.x); assert_eq!(location.y, 20f32, "y of node {:?}. Expected {}. Actual {}", node10, 20f32, location.y); #[cfg(feature = "content_size")] assert_eq!( layout.scroll_width(), 0f32, "scroll_width of node {:?}. Expected {}. Actual {}", node10, 0f32, layout.scroll_width() ); #[cfg(feature = "content_size")] assert_eq!( layout.scroll_height(), 0f32, "scroll_height of node {:?}. Expected {}. Actual {}", node10, 0f32, layout.scroll_height() ); #[cfg_attr(not(feature = "content_size"), allow(unused_variables))] let layout @ Layout { size, location, .. } = taffy.layout(node11).unwrap(); assert_eq!(size.width, 0f32, "width of node {:?}. Expected {}. Actual {}", node11, 0f32, size.width); assert_eq!(size.height, 0f32, "height of node {:?}. Expected {}. Actual {}", node11, 0f32, size.height); assert_eq!(location.x, 20f32, "x of node {:?}. Expected {}. Actual {}", node11, 20f32, location.x); assert_eq!(location.y, 20f32, "y of node {:?}. Expected {}. Actual {}", node11, 20f32, location.y); #[cfg(feature = "content_size")] assert_eq!( layout.scroll_width(), 0f32, "scroll_width of node {:?}. Expected {}. Actual {}", node11, 0f32, layout.scroll_width() ); #[cfg(feature = "content_size")] assert_eq!( layout.scroll_height(), 0f32, "scroll_height of node {:?}. Expected {}. Actual {}", node11, 0f32, layout.scroll_height() ); #[cfg_attr(not(feature = "content_size"), allow(unused_variables))] let layout @ Layout { size, location, .. } = taffy.layout(node12).unwrap(); assert_eq!(size.width, 0f32, "width of node {:?}. Expected {}. Actual {}", node12, 0f32, size.width); assert_eq!(size.height, 0f32, "height of node {:?}. Expected {}. Actual {}", node12, 0f32, size.height); assert_eq!(location.x, 165f32, "x of node {:?}. Expected {}. Actual {}", node12, 165f32, location.x); assert_eq!(location.y, 165f32, "y of node {:?}. Expected {}. Actual {}", node12, 165f32, location.y); #[cfg(feature = "content_size")] assert_eq!( layout.scroll_width(), 0f32, "scroll_width of node {:?}. Expected {}. Actual {}", node12, 0f32, layout.scroll_width() ); #[cfg(feature = "content_size")] assert_eq!( layout.scroll_height(), 0f32, "scroll_height of node {:?}. Expected {}. Actual {}", node12, 0f32, layout.scroll_height() ); #[cfg_attr(not(feature = "content_size"), allow(unused_variables))] let layout @ Layout { size, location, .. } = taffy.layout(node13).unwrap(); assert_eq!(size.width, 0f32, "width of node {:?}. Expected {}. Actual {}", node13, 0f32, size.width); assert_eq!(size.height, 0f32, "height of node {:?}. Expected {}. Actual {}", node13, 0f32, size.height); assert_eq!(location.x, 20f32, "x of node {:?}. Expected {}. Actual {}", node13, 20f32, location.x); assert_eq!(location.y, 20f32, "y of node {:?}. Expected {}. Actual {}", node13, 20f32, location.y); #[cfg(feature = "content_size")] assert_eq!( layout.scroll_width(), 0f32, "scroll_width of node {:?}. Expected {}. Actual {}", node13, 0f32, layout.scroll_width() ); #[cfg(feature = "content_size")] assert_eq!( layout.scroll_height(), 0f32, "scroll_height of node {:?}. Expected {}. Actual {}", node13, 0f32, layout.scroll_height() ); #[cfg_attr(not(feature = "content_size"), allow(unused_variables))] let layout @ Layout { size, location, .. } = taffy.layout(node14).unwrap(); assert_eq!(size.width, 0f32, "width of node {:?}. Expected {}. Actual {}", node14, 0f32, size.width); assert_eq!(size.height, 0f32, "height of node {:?}. Expected {}. Actual {}", node14, 0f32, size.height); assert_eq!(location.x, 50f32, "x of node {:?}. Expected {}. Actual {}", node14, 50f32, location.x); assert_eq!(location.y, 50f32, "y of node {:?}. Expected {}. Actual {}", node14, 50f32, location.y); #[cfg(feature = "content_size")] assert_eq!( layout.scroll_width(), 0f32, "scroll_width of node {:?}. Expected {}. Actual {}", node14, 0f32, layout.scroll_width() ); #[cfg(feature = "content_size")] assert_eq!( layout.scroll_height(), 0f32, "scroll_height of node {:?}. Expected {}. Actual {}", node14, 0f32, layout.scroll_height() ); #[cfg_attr(not(feature = "content_size"), allow(unused_variables))] let layout @ Layout { size, location, .. } = taffy.layout(node15).unwrap(); assert_eq!(size.width, 145f32, "width of node {:?}. Expected {}. Actual {}", node15, 145f32, size.width); assert_eq!(size.height, 145f32, "height of node {:?}. Expected {}. Actual {}", node15, 145f32, size.height); assert_eq!(location.x, 20f32, "x of node {:?}. Expected {}. Actual {}", node15, 20f32, location.x); assert_eq!(location.y, 20f32, "y of node {:?}. Expected {}. Actual {}", node15, 20f32, location.y); #[cfg(feature = "content_size")] assert_eq!( layout.scroll_width(), 0f32, "scroll_width of node {:?}. Expected {}. Actual {}", node15, 0f32, layout.scroll_width() ); #[cfg(feature = "content_size")] assert_eq!( layout.scroll_height(), 0f32, "scroll_height of node {:?}. Expected {}. Actual {}", node15, 0f32, layout.scroll_height() ); }