#[test] #[allow(non_snake_case)] fn taffy_issue_696_overflow_hidden__border_box() { #[allow(unused_imports)] use taffy::{prelude::*, tree::Layout, TaffyTree}; let mut taffy: TaffyTree = TaffyTree::new(); let node00 = taffy .new_leaf(taffy::style::Style { display: taffy::style::Display::Flex, flex_shrink: 0f32, size: taffy::geometry::Size { width: auto(), height: taffy::style::Dimension::Length(200f32) }, ..Default::default() }) .unwrap(); let node0 = taffy .new_with_children( taffy::style::Style { display: taffy::style::Display::Flex, flex_direction: taffy::style::FlexDirection::Column, overflow: taffy::geometry::Point { x: taffy::style::Overflow::Hidden, y: taffy::style::Overflow::Hidden, }, scrollbar_width: 15f32, flex_basis: taffy::style::Dimension::Length(0f32), padding: 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], ) .unwrap(); let node = taffy .new_with_children( taffy::style::Style { display: taffy::style::Display::Flex, flex_direction: taffy::style::FlexDirection::Column, size: taffy::geometry::Size { width: taffy::style::Dimension::Length(200f32), height: auto() }, ..Default::default() }, &[node0], ) .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!(); let layout = taffy.layout(node).unwrap(); let Layout { size, location, .. } = layout; assert_eq!(size.width, 200f32, "width of node {:?}. Expected {}. Actual {}", node, 200f32, size.width); assert_eq!(size.height, 40f32, "height of node {:?}. Expected {}. Actual {}", node, 40f32, 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); let layout = taffy.layout(node0).unwrap(); let Layout { size, location, .. } = layout; assert_eq!(size.width, 200f32, "width of node {:?}. Expected {}. Actual {}", node0, 200f32, size.width); assert_eq!(size.height, 40f32, "height of node {:?}. Expected {}. Actual {}", node0, 40f32, 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(), 200f32, "scroll_height of node {:?}. Expected {}. Actual {}", node0, 200f32, layout.scroll_height() ); let layout = taffy.layout(node00).unwrap(); let Layout { size, location, .. } = layout; assert_eq!(size.width, 160f32, "width of node {:?}. Expected {}. Actual {}", node00, 160f32, size.width); assert_eq!(size.height, 200f32, "height of node {:?}. Expected {}. Actual {}", node00, 200f32, 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); } #[test] #[allow(non_snake_case)] fn taffy_issue_696_overflow_hidden__content_box() { #[allow(unused_imports)] use taffy::{prelude::*, tree::Layout, TaffyTree}; let mut taffy: TaffyTree = TaffyTree::new(); let node00 = taffy .new_leaf(taffy::style::Style { display: taffy::style::Display::Flex, box_sizing: taffy::style::BoxSizing::ContentBox, flex_shrink: 0f32, size: taffy::geometry::Size { width: auto(), height: taffy::style::Dimension::Length(200f32) }, ..Default::default() }) .unwrap(); let node0 = taffy .new_with_children( taffy::style::Style { display: taffy::style::Display::Flex, box_sizing: taffy::style::BoxSizing::ContentBox, flex_direction: taffy::style::FlexDirection::Column, overflow: taffy::geometry::Point { x: taffy::style::Overflow::Hidden, y: taffy::style::Overflow::Hidden, }, scrollbar_width: 15f32, flex_basis: taffy::style::Dimension::Length(0f32), padding: 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], ) .unwrap(); let node = taffy .new_with_children( taffy::style::Style { display: taffy::style::Display::Flex, box_sizing: taffy::style::BoxSizing::ContentBox, flex_direction: taffy::style::FlexDirection::Column, size: taffy::geometry::Size { width: taffy::style::Dimension::Length(200f32), height: auto() }, ..Default::default() }, &[node0], ) .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!(); let layout = taffy.layout(node).unwrap(); let Layout { size, location, .. } = layout; assert_eq!(size.width, 200f32, "width of node {:?}. Expected {}. Actual {}", node, 200f32, size.width); assert_eq!(size.height, 40f32, "height of node {:?}. Expected {}. Actual {}", node, 40f32, 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); let layout = taffy.layout(node0).unwrap(); let Layout { size, location, .. } = layout; assert_eq!(size.width, 200f32, "width of node {:?}. Expected {}. Actual {}", node0, 200f32, size.width); assert_eq!(size.height, 40f32, "height of node {:?}. Expected {}. Actual {}", node0, 40f32, 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(), 200f32, "scroll_height of node {:?}. Expected {}. Actual {}", node0, 200f32, layout.scroll_height() ); let layout = taffy.layout(node00).unwrap(); let Layout { size, location, .. } = layout; assert_eq!(size.width, 160f32, "width of node {:?}. Expected {}. Actual {}", node00, 160f32, size.width); assert_eq!(size.height, 200f32, "height of node {:?}. Expected {}. Actual {}", node00, 200f32, 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); }