window: Adjust to image size when opening

Give LpImage a native with that should feel nice.
When opening a new window with a new image the window size
is determined by LpImage's natural width.
The image size and EXIF data is loaded before the image such
that the window can be shown in the right dimension while
loading the actual image.
This commit is contained in:
Sophie Herold 2022-11-16 20:14:39 +01:00 • committed by Christopher Davis
parent 68221bacba
commit e04992b46d
12 changed files with 389 additions and 79 deletions

View file

@ -24,6 +24,7 @@ use adw::prelude::*;
use adw::subclass::prelude::*;
use crate::config;
use crate::widgets::{LpImage, LpImagePage};
use crate::window::LpWindow;
mod imp {
@ -74,7 +75,35 @@ mod imp {
for file in files {
let win = LpWindow::new(&*application);
win.set_image_from_file(file, true);
win.show();
// show window when image size is known
let watch = win
.imp()
.image_view
.property_expression("current-page-strict")
.chain_property::<LpImagePage>("image")
.chain_property::<LpImage>("image-size")
.watch(
glib::Object::NONE,
glib::clone!(@weak win => move || {
win.image_size_ready();
}),
);
win.imp().watch_image_size.replace(Some(watch));
// show if loading image errors
let watch = win
.imp()
.image_view
.property_expression("current-page-strict")
.chain_property::<LpImagePage>("error")
.watch(
glib::Object::NONE,
glib::clone!(@weak win => move || {
win.image_error();
}),
);
win.imp().watch_image_error.replace(Some(watch));
}
}
}