dioxus_web/events/
load.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
use std::any::Any;

use dioxus_html::HasImageData;
use web_sys::Event;

use super::WebEventExt;

#[derive(Clone)]
pub(crate) struct WebImageEvent {
    raw: Event,
    error: bool,
}

impl WebImageEvent {
    pub fn new(raw: Event, error: bool) -> Self {
        Self { raw, error }
    }
}

impl HasImageData for WebImageEvent {
    fn load_error(&self) -> bool {
        self.error
    }

    fn as_any(&self) -> &dyn Any {
        &self.raw
    }
}

impl WebEventExt for dioxus_html::ImageData {
    type WebEvent = Event;

    #[inline(always)]
    fn try_as_web_event(&self) -> Option<Event> {
        self.downcast::<WebImageEvent>().map(|e| e.raw.clone())
    }
}