I have been using druid for my newest project, and I'm really enjoying the simplicity of the model. However I'm struggling to use lenses with an image, and the docs unfortunately don't include the docs for the image feature.
I was considering writing my own lens, but I don't want to clone a bunch of data around after unlocking. I'm using the github dependency path, so whatever version they're currently on.
#[derive(Clone, Default, Lens)]
pub struct State {
pub display_image: Option<Arc<RwLock<ImageBuf>>>,
...
}
...
let image = ViewSwitcher::new(
|data: &State, _env| data.display_image.is_some(),
move |f, data: &State, _env| {
if *f {
Box::new(
//if I don't use Arc<RwLock<?>> here, the compiler complains that Imgbuf doesn't impl Data
//The initial image is shown, but when Imgbuf changes, the widget is not updated
//I would imagine this has to do with it being an Arc<RwLock<?>>, but I'm not sure how to make druid and rust happy at the same time
//Is there a wrapper widget available to give me the option of using a closure to update instead of a lens? Like how Label::dynamic(|data, env|) works?
Image::new(data.display_image.as_ref().unwrap().read().unwrap().clone())
.lens(State::display_image),
)
} else {
//Placeholder svg. Completely static. Works well!
Box::new(Svg::new(svg).fill_mode(FillStrat::Fill))
}
},
);
...
Important links:
I "fixed" this using the painter widget, with the drawback that I'm having to handle aspect ratios and sizing on my own. I would love an answer that uses the Image widget, because the source code says it handles sizing and aspect ratios.