pub fn img(image: impl Fn() -> Vec<u8> + 'static) -> ImgExpand description
A view that can display an image and controls its position.
It takes function that produce Vec<u8> and will convert it into Image.
§Example:
let ferris_png = include_bytes!("../../examples/widget-gallery/assets/ferris.png");
// Create an image from the function returning Vec<u8>:
img(move || ferris_png.to_vec())
.style(|s| s.size(50.,50.));§Reactivity
The img function is not reactive, so to make it change on event, wrap it
with dyn_view.
§Example with reactive updates:
#[derive(Clone)]
enum Image {
ImageA,
ImageB
}
let ferris = include_bytes!("../../examples/widget-gallery/assets/ferris.png");
let sunflower = include_bytes!("../../examples/widget-gallery/assets/sunflower.jpg");
let switch_image = RwSignal::new(Image::ImageA);
// Create an image from the function returning Vec<u8>:
dyn_view(move || {
let image = switch_image.get();
img(move || {
match image {
Image::ImageA => ferris.to_vec(),
Image::ImageB => sunflower.to_vec()
}
}).style(|s| s.size(50.,50.))
});