From c2e3bb2f832e93f90ac71570ef1537bea1dc504d Mon Sep 17 00:00:00 2001 From: Sophie Herold Date: Sat, 5 Nov 2022 00:57:18 +0100 Subject: [PATCH] menus: Add rotate left and right buttons --- data/gtk/image_page.ui | 86 +++++++++++++++++-------- data/gtk/window.ui | 132 ++++++++++++++++++++++++-------------- src/widgets/image.rs | 7 +- src/widgets/image_view.rs | 4 +- src/window.rs | 9 +-- 5 files changed, 153 insertions(+), 85 deletions(-) diff --git a/data/gtk/image_page.ui b/data/gtk/image_page.ui index 60f82fb..e5599ff 100644 --- a/data/gtk/image_page.ui +++ b/data/gtk/image_page.ui @@ -1,5 +1,41 @@ + +
+ + _Open With… + win.open-with + + + + _Print… + win.print + + + _Copy + win.copy + +
+
+ Rotate + inline-buttons + + rotate-left + + + rotate-right + +
+
+ + _Set as Background… + win.set-background + +
+
- -
- - _Open With… - win.open-with - - - - _Print… - win.print - - - _Copy - win.copy - - - _Rotate - win.rotate-image - - - _Set as Background… - win.set-background - -
-
diff --git a/data/gtk/window.ui b/data/gtk/window.ui index 0364392..b63c13c 100644 --- a/data/gtk/window.ui +++ b/data/gtk/window.ui @@ -1,5 +1,61 @@ + +
+ + _New Window + app.new-window + + + _Open… + win.open + +
+
+ + _Open With… + win.open-with + + + + _Print… + win.print + +
+
+ Rotate + inline-buttons + + rotate-left + + + rotate-right + +
+
+ + _Set as Background… + win.set-background + +
+
+ + _Help + app.help + + + _Keyboard Shortcuts + win.show-help-overlay + + + _About Image Viewer + app.about + +
+
- -
- - _New Window - app.new-window - - - _Open… - win.open - -
-
- - _Open With… - win.open-with - - - - _Print… - win.print - - - _Rotate - win.rotate-image - - - _Set as Background… - win.set-background - -
-
- - _Help - app.help - - - _Keyboard Shortcuts - win.show-help-overlay - - - _About Image Viewer - app.about - -
-
diff --git a/src/widgets/image.rs b/src/widgets/image.rs index 3efe767..95863a5 100644 --- a/src/widgets/image.rs +++ b/src/widgets/image.rs @@ -102,6 +102,9 @@ mod imp { fn dispose(&self) { let obj = self.instance(); + + self.rotation_animation.replace(None); + while let Some(child) = obj.first_child() { child.unparent(); } @@ -257,9 +260,9 @@ impl LpImage { gdk::ContentProvider::new_union(contents.as_slice()) } - pub fn rotate(&self) { + pub fn rotate(&self, angle: f64) { let target = &self.imp().rotation_target; - target.set(target.get() + 90.); + target.set(target.get() + angle); let borrow = self.imp().rotation_animation.borrow(); let animation = borrow.as_ref().unwrap(); diff --git a/src/widgets/image_view.rs b/src/widgets/image_view.rs index e0aed01..d0a4241 100644 --- a/src/widgets/image_view.rs +++ b/src/widgets/image_view.rs @@ -385,9 +385,9 @@ impl LpImageView { } } - pub fn rotate_image(&self) { + pub fn rotate_image(&self, angle: f64) { if let Some(current_page) = self.current_page() { - current_page.image().rotate(); + current_page.image().rotate(angle); } } diff --git a/src/window.rs b/src/window.rs index bda858a..5d7e43d 100644 --- a/src/window.rs +++ b/src/window.rs @@ -102,8 +102,8 @@ mod imp { win.open_with(); }); - klass.install_action("win.rotate-image", None, move |win, _, _| { - win.rotate_image(); + klass.install_action("win.rotate", Some("d"), move |win, _, angle| { + win.rotate_image(angle.unwrap().get().unwrap()); }); klass.install_action("win.set-background", None, move |win, _, _| { @@ -290,8 +290,8 @@ impl LpWindow { } } - fn rotate_image(&self) { - self.imp().image_view.rotate_image() + fn rotate_image(&self, angle: f64) { + self.imp().image_view.rotate_image(angle) } fn set_background(&self) { @@ -352,6 +352,7 @@ impl LpWindow { self.action_set_enabled("win.set-background", enabled); self.action_set_enabled("win.toggle-fullscreen", enabled); self.action_set_enabled("win.print", enabled); + self.action_set_enabled("win.rotate", enabled); self.action_set_enabled("win.copy", enabled); }