relayout.rs 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. use stretch2 as stretch;
  2. #[test]
  3. fn relayout() {
  4. let mut stretch = stretch::Stretch::new();
  5. let node1 = stretch
  6. .new_node(
  7. stretch::style::Style {
  8. position: stretch::geometry::Point {
  9. x: stretch::style::Dimension::Points(10f32),
  10. y: stretch::style::Dimension::Points(10f32),
  11. },
  12. size: stretch::geometry::Size {
  13. width: stretch::style::Dimension::Points(10f32),
  14. height: stretch::style::Dimension::Points(10f32),
  15. },
  16. ..Default::default()
  17. },
  18. &[],
  19. )
  20. .unwrap();
  21. let node0 = stretch
  22. .new_node(
  23. stretch::style::Style {
  24. size: stretch::geometry::Size {
  25. width: stretch::style::Dimension::Percent(1f32),
  26. height: stretch::style::Dimension::Percent(1f32),
  27. },
  28. ..Default::default()
  29. },
  30. &[node1],
  31. )
  32. .unwrap();
  33. let node = stretch
  34. .new_node(
  35. stretch::style::Style {
  36. size: stretch::geometry::Size {
  37. width: stretch::style::Dimension::Points(100f32),
  38. height: stretch::style::Dimension::Points(100f32),
  39. },
  40. ..Default::default()
  41. },
  42. &[node0],
  43. )
  44. .unwrap();
  45. for _ in 0..10 {
  46. stretch
  47. .compute_layout(node, stretch::geometry::Size::undefined())
  48. .unwrap();
  49. assert_eq!(stretch.layout(node).unwrap().size.width, 100f32);
  50. assert_eq!(stretch.layout(node).unwrap().size.height, 100f32);
  51. assert_eq!(stretch.layout(node).unwrap().location.x, 0f32);
  52. assert_eq!(stretch.layout(node).unwrap().location.y, 0f32);
  53. assert_eq!(stretch.layout(node1).unwrap().size.width, 10f32);
  54. assert_eq!(stretch.layout(node1).unwrap().size.height, 10f32);
  55. assert_eq!(stretch.layout(node1).unwrap().location.x, 0f32);
  56. assert_eq!(stretch.layout(node1).unwrap().location.y, 0f32);
  57. assert_eq!(stretch.layout(node0).unwrap().size.width, 100f32);
  58. assert_eq!(stretch.layout(node0).unwrap().size.height, 100f32);
  59. assert_eq!(stretch.layout(node0).unwrap().location.x, 0f32);
  60. assert_eq!(stretch.layout(node0).unwrap().location.y, 0f32);
  61. }
  62. }