margin.rs 3.1 KB

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