Implement Properties

Implement a properties sidebar. In order to prevent
the UI from freezing, we use futures to load and cancel
loading file information. We also make use of
`gdk_pixbuf` and `svg_metadata` in order to get the file's
metadata before the file fully loads, meaning there's
little to no delay between changing files and seeing
the metadata for large images.

The properties widget uses expressions and
properties to avoid glue code for setting each label,
allowing us to have a clean separation between UI
and data.
This commit is contained in:
Christopher Davis 2022-07-26 11:31:11 -04:00
parent 1e95dd4cbb
commit ba4661031f
12 changed files with 664 additions and 45 deletions

View file

@ -30,7 +30,7 @@ use ashpd::WindowIdentifier;
use crate::config;
use crate::util;
use crate::widgets::LpImageView;
use crate::widgets::{LpImageView, LpPropertiesView};
mod imp {
use super::*;
@ -70,6 +70,8 @@ mod imp {
#[template_child]
pub image_view: TemplateChild<LpImageView>,
#[template_child]
pub properties_view: TemplateChild<LpPropertiesView>,
#[template_child]
pub drop_target: TemplateChild<gtk::DropTarget>,
}
@ -209,11 +211,11 @@ impl LpWindow {
let imp = self.imp();
if fullscreen {
imp.flap.set_fold_policy(adw::FlapFoldPolicy::Always);
imp.headerbar.add_css_class("osd");
imp.properties_view.add_css_class("osd")
} else {
imp.flap.set_fold_policy(adw::FlapFoldPolicy::Never);
imp.headerbar.remove_css_class("osd");
imp.properties_view.remove_css_class("osd")
}
self.set_fullscreened(fullscreen);
@ -382,4 +384,16 @@ impl LpWindow {
file.and_then(|f| util::get_file_display_name(&f)) // If the file exists, get display name
.unwrap_or_else(|| String::from("Image Viewer")) // Return that or the default if there's nothing
}
// We also have a closure that returns `adw::FlapFoldPolicy`.
// if we aren't fullscreened, or if the properties are revealed,
// we unfold the main flap. Otherwise we're always folded.
#[template_callback]
fn fold_policy(&self, fullscreened: bool, properties_revealed: bool) -> adw::FlapFoldPolicy {
if !fullscreened || properties_revealed {
adw::FlapFoldPolicy::Never
} else {
adw::FlapFoldPolicy::Always
}
}
}