strecher.rs 830 B

12345678910111213141516171819202122232425262728293031323334
  1. use stretch2::prelude::*;
  2. fn main() -> Result<(), Error> {
  3. let mut stretch = Stretch::new();
  4. let child = stretch.new_node(
  5. Style {
  6. size: Size {
  7. width: Dimension::Percent(0.5),
  8. height: Dimension::Auto,
  9. },
  10. ..Default::default()
  11. },
  12. &[],
  13. )?;
  14. let node = stretch.new_node(
  15. Style {
  16. size: Size {
  17. width: Dimension::Points(100.0),
  18. height: Dimension::Points(100.0),
  19. },
  20. justify_content: JustifyContent::Center,
  21. ..Default::default()
  22. },
  23. &[child],
  24. )?;
  25. stretch.compute_layout(node, Size::undefined())?;
  26. println!("node: {:#?}", stretch.layout(node)?);
  27. println!("child: {:#?}", stretch.layout(child)?);
  28. Ok(())
  29. }