margin.rs 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. #[test]
  2. fn margin_and_flex_row() {
  3. let mut taffy = taffy::Taffy::new();
  4. let node0 = taffy
  5. .new_node(
  6. taffy::style::Style {
  7. flex_grow: 1f32,
  8. margin: taffy::geometry::Rect {
  9. start: taffy::style::Dimension::Points(10f32),
  10. end: taffy::style::Dimension::Points(10f32),
  11. ..Default::default()
  12. },
  13. ..Default::default()
  14. },
  15. &[],
  16. )
  17. .unwrap();
  18. let node = taffy
  19. .new_node(
  20. taffy::style::Style {
  21. size: taffy::geometry::Size {
  22. width: taffy::style::Dimension::Points(100f32),
  23. height: taffy::style::Dimension::Points(100f32),
  24. },
  25. ..Default::default()
  26. },
  27. &[node0],
  28. )
  29. .unwrap();
  30. taffy
  31. .compute_layout(node, taffy::geometry::Size::undefined())
  32. .unwrap();
  33. assert_eq!(taffy.layout(node).unwrap().size.width, 100f32);
  34. assert_eq!(taffy.layout(node).unwrap().size.height, 100f32);
  35. assert_eq!(taffy.layout(node).unwrap().location.x, 0f32);
  36. assert_eq!(taffy.layout(node).unwrap().location.y, 0f32);
  37. assert_eq!(taffy.layout(node0).unwrap().size.width, 80f32);
  38. assert_eq!(taffy.layout(node0).unwrap().size.height, 100f32);
  39. assert_eq!(taffy.layout(node0).unwrap().location.x, 10f32);
  40. assert_eq!(taffy.layout(node0).unwrap().location.y, 0f32);
  41. }
  42. #[test]
  43. fn margin_and_flex_row2() {
  44. let mut taffy = taffy::Taffy::new();
  45. let node0 = taffy
  46. .new_node(
  47. taffy::style::Style {
  48. flex_grow: 1f32,
  49. margin: taffy::geometry::Rect {
  50. // left
  51. start: taffy::style::Dimension::Points(10f32),
  52. // right?
  53. end: taffy::style::Dimension::Points(10f32),
  54. // top?
  55. // top: taffy::style::Dimension::Points(10f32),
  56. // bottom?
  57. // bottom: taffy::style::Dimension::Points(10f32),
  58. ..Default::default()
  59. },
  60. ..Default::default()
  61. },
  62. &[],
  63. )
  64. .unwrap();
  65. let node = taffy
  66. .new_node(
  67. taffy::style::Style {
  68. size: taffy::geometry::Size {
  69. width: taffy::style::Dimension::Points(100f32),
  70. height: taffy::style::Dimension::Points(100f32),
  71. },
  72. ..Default::default()
  73. },
  74. &[node0],
  75. )
  76. .unwrap();
  77. taffy
  78. .compute_layout(node, taffy::geometry::Size::undefined())
  79. .unwrap();
  80. assert_eq!(taffy.layout(node).unwrap().size.width, 100f32);
  81. assert_eq!(taffy.layout(node).unwrap().size.height, 100f32);
  82. assert_eq!(taffy.layout(node).unwrap().location.x, 0f32);
  83. assert_eq!(taffy.layout(node).unwrap().location.y, 0f32);
  84. }