Hello again,
I’m working on a project that allows selecting a video and using it as a bootscreen. To so, when the user selects a video, a thumbnail should be shown.
The is that once GtkImage
gets a large image, the whole window resizes to fit the new size and it’s not possible to make the window smaller anymore; only larger.
In the python implementation (using Qt), the original thumbnail is stored and at every resize it’s used to generate a new, scaled thumbnail to fit the widget.
How would one achieve the same thing in Gtk-rs?
Excuse the beginner rust, but it looks like this atm (no resizing)
let chooser__video: FileChooserButton = builder.get_object("chooser__video").unwrap();
let label__thumbnail: Image = builder.get_object("label__thumbnail").unwrap();
chooser__video.connect_file_set(move |chooser| {
let option = chooser.get_file();
if option.is_none() {
return;
}
let file = option.unwrap();
if file.get_path().is_none() {
return;
}
let thumbnail = ffmpeg::get_video_thumbnail(file.get_path().unwrap().to_str().unwrap());
if thumbnail.is_some() {
label__thumbnail.set_from_pixbuf(Option::from(&thumbnail))
} else {
todo!("Handle error handling")
}
});
I tried putting that code into a struct to store the thumbnail, but couldn’t get it to work.
pub struct Application {
thumbnail: Option<Pixbuf>,
pub builder: Builder,
}
impl Application {
pub fn connect(&mut self) {
// ...
chooser__video.connect_file_set(move |chooser| {
// ...
let thumbnail: Pixbuf = ffmpeg::get_video_thumbnail(file.get_path().unwrap().to_str().unwrap()).unwrap();
self.thumbnail = Option::from(thumbnail); // --> closures cannot mutate their captured variables
let size = label__thumbnail.get_size_request();
let new_thumbnail = thumbnail.scale_simple(size.0, size.1, InterpType::Bilinear);
label__thumbnail.set_from_pixbuf(Option::from(&new_thumbnail));
});
}
}
It does look like a solution that I found in C, but I can’t think rust yet.
How could I get this to work in rust?