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
use crate::{api::prelude::*, proc_macros::*, render::prelude::*};

widget!(
    /// The `ImageWidget` widget is used to draw an image. It is not interactive.
    ///
    /// **style:** `image-widget`
    ImageWidget {
        /// Sets or shares the image property.
        ///
        /// Set image property:
        /// * &str: `Image::new().image("path/to/image.png").build(xt)`
        /// * String: `Image::new().image(String::from()).build(xt)`
        /// * (width: u32, height: u32, data: Vec<u32>): `Image::new().image((width, height, vec![0; width * height]));`
        image: Image
    }
);

impl Template for ImageWidget {
    fn template(self, _: Entity, _: &mut BuildContext) -> Self {
        self.name("ImageWidget").style("image-widget").image("")
    }

    fn render_object(&self) -> Box<dyn RenderObject> {
        Box::new(ImageRenderObject)
    }

    fn layout(&self) -> Box<dyn Layout> {
        Box::new(FixedSizeLayout::new())
    }
}