margin.rs 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  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. ..Default::default()
  26. },
  27. ..Default::default()
  28. },
  29. &[node0],
  30. )
  31. .unwrap();
  32. stretch
  33. .compute_layout(node, stretch::geometry::Size::undefined())
  34. .unwrap();
  35. assert_eq!(stretch.layout(node).unwrap().size.width, 100f32);
  36. assert_eq!(stretch.layout(node).unwrap().size.height, 100f32);
  37. assert_eq!(stretch.layout(node).unwrap().location.x, 0f32);
  38. assert_eq!(stretch.layout(node).unwrap().location.y, 0f32);
  39. assert_eq!(stretch.layout(node0).unwrap().size.width, 80f32);
  40. assert_eq!(stretch.layout(node0).unwrap().size.height, 100f32);
  41. assert_eq!(stretch.layout(node0).unwrap().location.x, 10f32);
  42. assert_eq!(stretch.layout(node0).unwrap().location.y, 0f32);
  43. }
  44. #[test]
  45. fn margin_and_flex_row2() {
  46. let mut stretch = stretch::Stretch::new();
  47. let node0 = stretch
  48. .new_node(
  49. stretch::style::Style {
  50. flex_grow: 1f32,
  51. margin: stretch::geometry::Rect {
  52. // left
  53. start: stretch::style::Dimension::Points(10f32),
  54. // right?
  55. end: stretch::style::Dimension::Points(10f32),
  56. // top?
  57. // top: stretch::style::Dimension::Points(10f32),
  58. // bottom?
  59. // bottom: stretch::style::Dimension::Points(10f32),
  60. ..Default::default()
  61. },
  62. ..Default::default()
  63. },
  64. &[],
  65. )
  66. .unwrap();
  67. let node = stretch
  68. .new_node(
  69. stretch::style::Style {
  70. size: stretch::geometry::Size {
  71. width: stretch::style::Dimension::Points(100f32),
  72. height: stretch::style::Dimension::Points(100f32),
  73. ..Default::default()
  74. },
  75. ..Default::default()
  76. },
  77. &[node0],
  78. )
  79. .unwrap();
  80. stretch
  81. .compute_layout(node, stretch::geometry::Size::undefined())
  82. .unwrap();
  83. assert_eq!(stretch.layout(node).unwrap().size.width, 100f32);
  84. assert_eq!(stretch.layout(node).unwrap().size.height, 100f32);
  85. assert_eq!(stretch.layout(node).unwrap().location.x, 0f32);
  86. assert_eq!(stretch.layout(node).unwrap().location.y, 0f32);
  87. dbg!(stretch.layout(node0));
  88. // assert_eq!(stretch.layout(node0).unwrap().size.width, 80f32);
  89. // assert_eq!(stretch.layout(node0).unwrap().size.height, 100f32);
  90. // assert_eq!(stretch.layout(node0).unwrap().location.x, 10f32);
  91. // assert_eq!(stretch.layout(node0).unwrap().location.y, 0f32);
  92. }