freya_components/
image.rs

1/// Generate a Dioxus component rendering the specified image.
2///
3/// ### Example
4///
5/// ```no_run
6/// # use freya::prelude::*;
7///
8/// // You can pass as many `image` attributes you need, and these will become the default values and also allowed to be overriden.
9/// import_image!(RustLogo, "../../../examples/rust_logo.png", {
10///     width: "auto",
11///     height: "40%",
12///     aspect_ratio: "min",
13/// });
14///
15/// fn app() -> Element {
16///     rsx!(RustLogo {
17///         width: "150",
18///     })
19/// }
20/// ```
21#[macro_export]
22macro_rules! import_image {
23    ($component_name:ident, $path:expr, { $($key:ident : $value:expr),* $(,)? }) => {
24        #[allow(non_snake_case)]
25        #[dioxus::prelude::component]
26        pub fn $component_name(
27            $(#[props(default = $value.to_string())] $key: String,)*
28        ) -> freya::prelude::Element {
29            use freya::prelude::*;
30            let image_data = static_bytes(include_bytes!($path));
31
32            rsx!(image {
33                $($key: $key,)*
34                image_data,
35            })
36        }
37    };
38}