Components / ImageLightbox
ImageLightbox
A picture over the whole app, with zoom, arrows, Esc, caption and counter.
Example
The component itself, running in WebAssembly, beside its code in a playground. Try it.
Code
use ravenrs::prelude::*;
fn image_lightbox() -> impl View {
let open = State::new(None::<usize>);
let opener = open.clone();
let shades = [0.25_f32, 0.45, 0.65];
let pictures = shades.into_iter().filter_map(|shade| {
let image = ImageData::from_fn(320, 200, move |x, _| Color::rgb(shade, 0.3, x as f32 / 320.0))?;
Some(LightboxItem::new(image).caption(format!("Shade {shade}")))
});
VStack::new((
Button::new("Open pictures").on_click(move || opener.set(Some(0))),
ImageLightbox::new(open.binding(), pictures),
))
}