resize.rs 849 B

123456789101112131415161718192021222324252627282930
  1. //! Run a callback
  2. //!
  3. //! Whenever an Element is finally mounted to the Dom, its data is available to be read.
  4. //! These fields can typically only be read asynchronously, since various renderers need to release the main thread to
  5. //! perform layout and painting.
  6. use dioxus::prelude::*;
  7. use dioxus_elements::geometry::euclid::Size2D;
  8. fn main() {
  9. dioxus::launch(app);
  10. }
  11. fn app() -> Element {
  12. let mut dimensions = use_signal(Size2D::zero);
  13. rsx!(
  14. document::Link {
  15. rel: "stylesheet",
  16. href: asset!("/examples/assets/read_size.css"),
  17. }
  18. div {
  19. width: "50%",
  20. height: "50%",
  21. background_color: "red",
  22. onresize: move |evt| dimensions.set(evt.data().get_content_box_size().unwrap()),
  23. "This element is {dimensions():?}"
  24. }
  25. )
  26. }