anim.rs 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. fn main() {
  2. // render the
  3. let transition = move |cx, (width, height)| {};
  4. cx.render(rsx! {
  5. div {
  6. Transition {
  7. start: (0, 5),
  8. stop: (10, 10),
  9. render: transition
  10. }
  11. Transition {
  12. start: (0, 5),
  13. stop: (10, 10),
  14. render: move |cx, (width, height)| {
  15. //
  16. cx.render(rsx!{
  17. div {
  18. style {
  19. width: width,
  20. width: height
  21. }
  22. }
  23. })
  24. }
  25. }
  26. }
  27. })
  28. }
  29. // Animations with signals
  30. fn signal_based(cx: ()) {
  31. const InitPos: (i32, i32) = (0, 0);
  32. const EndPos: (i32, i32) = (100, 200);
  33. let spring = use_spring(cx, move |spring| spring.from(InitPos).to(EndPos));
  34. cx.render(rsx! {
  35. div {
  36. style: [
  37. width: spring.0,
  38. height: spring.1
  39. ]
  40. button { onclick: move |_| spring.set(InitPos), "Reset" }
  41. button { onclick: move |_| spring.set(EndPos), "Animate" }
  42. }
  43. })
  44. }