relayout.rs 2.2 KB

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