image: Add zoom and scrolling support

Zoom via
- Scroll event controller
- Zoom gesture
- Overlay buttons
- Fixed zoom level shortcuts (1=100%, 2=200%)
Scrolling via
- Scrolled window
- Drag gesture
Changes
- Implement best-fit via calculating a zoom level
- Gesture for carousel no longer working because of scrolled window
- Split control overlays into two to not steal inputs in area between

Closes #17
This commit is contained in:
Sophie Herold 2022-11-10 19:39:23 +01:00
parent 73a1702c47
commit 029c0c9244
9 changed files with 952 additions and 155 deletions

View file

@ -26,7 +26,7 @@ use gtk::CompositeTemplate;
use gtk_macros::spawn;
use once_cell::sync::OnceCell;
use once_cell::sync::{Lazy, OnceCell};
use crate::widgets::LpImage;
@ -43,6 +43,8 @@ mod imp {
#[template_child]
pub(super) error_page: TemplateChild<adw::StatusPage>,
#[template_child]
pub(super) scrolled_window: TemplateChild<gtk::ScrolledWindow>,
#[template_child]
pub(super) image: TemplateChild<LpImage>,
#[template_child]
pub(super) popover: TemplateChild<gtk::PopoverMenu>,
@ -70,6 +72,23 @@ mod imp {
}
impl ObjectImpl for LpImagePage {
fn properties() -> &'static [glib::ParamSpec] {
static PROPERTIES: Lazy<Vec<glib::ParamSpec>> = Lazy::new(|| {
vec![glib::ParamSpecObject::builder::<LpImage>("image")
.read_only()
.build()]
});
PROPERTIES.as_ref()
}
fn property(&self, _id: usize, pspec: &glib::ParamSpec) -> glib::Value {
let obj = self.instance();
match pspec.name() {
"image" => obj.image().to_value(),
name => unimplemented!("property {name}"),
}
}
fn constructed(&self) {
let obj = self.instance();
@ -114,7 +133,7 @@ impl LpImagePage {
match load_texture_from_file(&file).await {
Ok(texture) => {
imp.image.set_texture_with_file(texture, &file);
imp.stack.set_visible_child(&*imp.image);
imp.stack.set_visible_child(&*imp.scrolled_window);
imp.spinner.set_spinning(false);
},
Err(e) => {