Constant freya_elements::attributes::image_data::image_data

source ·
pub const image_data: (&'static str, Option<&'static str>, bool);
Expand description

Specify the image data for the image element.

Provides two main functions for handling image data:

  • static_bytes: Takes a static byte slice (&'static [u8]) for static images.
  • dynamic_bytes: Takes any value that can be converted into Bytes for dynamically loaded images.

§Example

static RUST_LOGO: &[u8] = include_bytes!("../_docs/rust_logo.png");

fn app() -> Element {
    rsx!(
        image {
            image_data: static_bytes(RUST_LOGO),
            width: "200",
            height: "200",
        }
    )
}

Using with dynamic bytes:


#[component]
fn DynamicImage(image_data: ReadOnlySignal<Vec<u8>>) -> Element {
    rsx!(
        image {
            image_data: dynamic_bytes(image_data.read().clone()),
            width: "200",
            height: "200",
        }
    )
}