Updating the contents of an image?
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 9.7k
- Forks
- 565
- PR merge metrics
- No merged PRs in 30d
Description
I've been a bit confused today about the Image widget. I want to have it display the contents of a file on disk and if that file changes display the updated version. But I could not figure out how to make image actually update itself once Data changes. I had a look at the implementation and realised that the update method is not implemented. It also didn't seem to work with a LensWrap.
I wrapped it in a controller and this works, but I was wondering whether this isn't quite the stumbling block for new users.
struct ImageController;
impl druid::widget::Controller<WatchoutState, Image> for ImageController {
fn update(
&mut self,
child: &mut Image,
ctx: &mut druid::UpdateCtx,
old_data: &WatchoutState,
data: &WatchoutState,
env: &druid::Env,
) {
child.set_image_data(data.image.clone())
ctx.children_changed();
}
}
// Usage
let image = Image::new(ImageBuf::empty());
let size_box = druid::widget::SizedBox::new(image.controller(ImageController))
.expand()
Is there a reason why images don't update? (or am I holding it wrong?) Otherwise I'd gladly submit a PR.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the Image widget implementation, especially its update method, and compare it with the controller's update entry point shown here. Reproduce the file-backed image case from the linked watchout example, including the LensWrap behavior, then verify that changing the image data refreshes the displayed image without the controller workaround.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- frontend
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100