use crate::*; #[test] fn inline() { assert_xml!( r#"
hello
world
hello
world
"# ) } #[test] fn inline_set_size() { assert_xml!( r#"
"# ) } #[test] fn inline_block_with_padding() { assert_xml!( r#"
"# ) } #[test] fn inline_block_with_padding_2() { assert_xml!( r#"
"# ) } #[test] fn inline_in_block() { assert_xml!( r#"
"# ) } #[test] fn inline_in_flexbox() { assert_xml!( r#"
hello
hello
"# ) } // #[test] // fn inline_wrap() { // assert_xml!( // r#" //
//
//
world
//
//
// "# // ) // } #[test] fn inline_block() { assert_xml!( r#"
hello
hello
"# ) } #[test] fn inline_block_vertical_align_1() { assert_xml!( r#"
"# ) } #[test] fn inline_block_vertical_align_2() { assert_xml!( r#"
hello
"# ) } #[test] fn inline_block_wrap() { assert_xml!( r#"
"# ) } #[test] fn inline_block_wrap_2() { assert_xml!( r#"
"# ) } #[test] fn inline_block_wrap_3() { assert_xml!( r#"
"# ) } #[test] fn inline_block_wrap_4() { assert_xml!( r#"
"# ) } #[test] fn inline_block_margin() { assert_xml!( r#"
"# ) } #[test] fn inline_block_margin_1() { assert_xml!( r#"
"# ) } #[test] fn inline_block_margin_2() { assert_xml!( r#"
"# ) } #[test] fn inline_block_margin_3() { assert_xml!( r#"
"# ) } #[test] fn inline_block_in_flexbox() { assert_xml!( r#"
hello
hello
hello
hello
"# ) } #[test] fn block_in_inline_block() { assert_xml!( r#"
123
"# ) } use float_pigment_css::typing::Display; use float_pigment_forest::{ convert_node_ref_to_ptr, ChildOperation, DumpNode, DumpOptions, DumpStyleMode, Node, StyleSetter, }; use float_pigment_layout::{DefLength, OptionNum, OptionSize, Size}; unsafe fn as_ref<'a>(node: *mut Node) -> &'a Node { &*node } #[test] pub fn inline_block_as_root() { unsafe { let container = as_ref(Node::new_ptr()); container.set_display(Display::InlineBlock); let child = as_ref(Node::new_ptr()); child.set_width(DefLength::Points(Len::from_f32(10.))); child.set_height(DefLength::Points(Len::from_f32(20.))); container.append_child(convert_node_ref_to_ptr(child)); container.layout( OptionSize::new( OptionNum::some(Len::from_f32(375.)), OptionNum::some(Len::from_f32(750.)), ), Size::new(Len::from_f32(0.), Len::from_f32(0.)), ); assert_eq!(container.layout_position().width, 10.); } } #[test] pub fn inline_as_root() { unsafe { let container = as_ref(Node::new_ptr()); container.set_display(Display::Inline); let child = as_ref(Node::new_ptr()); child.set_width(DefLength::Percent(1.)); child.set_height(DefLength::Points(Len::from_f32(100.))); container.append_child(convert_node_ref_to_ptr(child)); container.layout( OptionSize::new( OptionNum::some(Len::from_f32(375.)), OptionNum::some(Len::from_f32(750.)), ), Size::new(Len::from_f32(0.), Len::from_f32(0.)), ); assert_eq!(container.layout_position().width, 375.); assert_eq!(child.layout_position().width, 375.); } } #[test] pub fn measurable_inline_block_with_padding() { unsafe { let container = as_ref(Node::new_ptr()); let child = as_ref(Node::new_ptr()); child.set_width(DefLength::Points(Len::from_f32(25.))); child.set_height(DefLength::Points(Len::from_f32(25.))); child.set_display(Display::InlineBlock); child.set_padding_left(DefLength::Points(Len::from_f32(12.))); child.set_padding_right(DefLength::Points(Len::from_f32(12.))); child.set_measure_func(Some(Box::new(|_, _, _, _, _, _, _, _, _| { Size::new(Len::from_f32(20.), Len::from_f32(20.)) }))); container.append_child(convert_node_ref_to_ptr(child)); container.layout( OptionSize::new( OptionNum::some(Len::from_f32(375.)), OptionNum::some(Len::from_f32(750.)), ), Size::new(Len::from_f32(0.), Len::from_f32(0.)), ); assert_eq!(child.layout_position().left, 0.); assert_eq!(child.layout_position().width, 49.); assert_eq!(child.layout_position().height, 25.); } } #[test] pub fn measurable_inline_block_with_margin() { unsafe { let container = as_ref(Node::new_ptr()); let child = as_ref(Node::new_ptr()); child.set_width(DefLength::Points(Len::from_f32(25.))); child.set_height(DefLength::Points(Len::from_f32(25.))); child.set_display(Display::InlineBlock); child.set_margin_left(DefLength::Points(Len::from_f32(12.))); child.set_margin_right(DefLength::Points(Len::from_f32(12.))); child.set_measure_func(Some(Box::new(|_, _, _, _, _, _, _, _, _| { Size::new(Len::from_f32(20.), Len::from_f32(20.)) }))); container.append_child(convert_node_ref_to_ptr(child)); container.layout( OptionSize::new( OptionNum::some(Len::from_f32(375.)), OptionNum::some(Len::from_f32(750.)), ), Size::new(Len::from_f32(0.), Len::from_f32(0.)), ); assert_eq!(child.layout_position().left, 12.); assert_eq!(child.layout_position().width, 25.); } } #[test] pub fn measurable_inline_block_with_margin_2() { unsafe { let container = as_ref(Node::new_ptr()); let child = as_ref(Node::new_ptr()); child.set_width(DefLength::Points(Len::from_f32(25.))); child.set_height(DefLength::Points(Len::from_f32(25.))); child.set_display(Display::InlineBlock); child.set_margin_left(DefLength::Points(Len::from_f32(12.))); child.set_margin_right(DefLength::Points(Len::from_f32(12.))); child.set_measure_func(Some(Box::new(|_, _, _, _, _, _, _, _, _| { Size::new(Len::from_f32(20.), Len::from_f32(20.)) }))); container.append_child(convert_node_ref_to_ptr(child)); let child_b = as_ref(Node::new_ptr()); child_b.set_width(DefLength::Points(Len::from_f32(25.))); child_b.set_height(DefLength::Points(Len::from_f32(25.))); child_b.set_display(Display::InlineBlock); child_b.set_margin_left(DefLength::Points(Len::from_f32(12.))); child_b.set_margin_right(DefLength::Points(Len::from_f32(12.))); child_b.set_measure_func(Some(Box::new(|_, _, _, _, _, _, _, _, _| { Size::new(Len::from_f32(25.), Len::from_f32(25.)) }))); container.append_child(convert_node_ref_to_ptr(child_b)); container.layout( OptionSize::new( OptionNum::some(Len::from_f32(375.)), OptionNum::some(Len::from_f32(750.)), ), Size::new(Len::from_f32(0.), Len::from_f32(0.)), ); println!( "{}", container.dump_to_html( DumpOptions { recursive: true, layout: true, style: DumpStyleMode::None }, 0 ) ); assert_eq!(child.layout_position().left, 12.); assert_eq!(child.layout_position().width, 25.); assert_eq!(child_b.layout_position().left, 61.); assert_eq!(child_b.layout_position().width, 25.); } } #[test] fn inline_complex_1() { assert_xml!( r#"
"# ) } #[test] fn inline_flex() { assert_xml!( r#"
"# ) } #[test] fn inline_block_wrap_precision() { assert_xml!( r#"
"# ) }