load.rs 683 B

12345678910111213141516171819202122232425262728293031323334353637
  1. use std::any::Any;
  2. use dioxus_html::HasImageData;
  3. use web_sys::Event;
  4. use super::WebEventExt;
  5. #[derive(Clone)]
  6. pub(crate) struct WebImageEvent {
  7. raw: Event,
  8. error: bool,
  9. }
  10. impl WebImageEvent {
  11. pub fn new(raw: Event, error: bool) -> Self {
  12. Self { raw, error }
  13. }
  14. }
  15. impl HasImageData for WebImageEvent {
  16. fn load_error(&self) -> bool {
  17. self.error
  18. }
  19. fn as_any(&self) -> &dyn Any {
  20. &self.raw as &dyn Any
  21. }
  22. }
  23. impl WebEventExt for dioxus_html::ImageData {
  24. type WebEvent = Event;
  25. #[inline(always)]
  26. fn try_as_web_event(&self) -> Option<Event> {
  27. self.downcast::<WebImageEvent>().map(|e| e.raw.clone())
  28. }
  29. }