diff --git a/data/resources/edit_crop.css b/data/resources/edit_crop.css index 87f342d..53ff4d1 100644 --- a/data/resources/edit_crop.css +++ b/data/resources/edit_crop.css @@ -1,3 +1,12 @@ +/* Icon orientation for GtkToggleButtons for aspect ratios */ +.has-orientation image { + transition: transform 300ms; +} + +.button-icons-portrait .has-orientation image { + transform: rotate(90deg); +} + lpcrop { --discarded-background: rgba(50, 50, 50, 0.7); --selection-border-color: rgb(240, 240, 240); diff --git a/src/widgets/edit/crop.rs b/src/widgets/edit/crop.rs index 8bb7928..8ecac7b 100644 --- a/src/widgets/edit/crop.rs +++ b/src/widgets/edit/crop.rs @@ -24,6 +24,7 @@ use adw::subclass::prelude::*; use adw::{glib, gtk}; use glycin::Operation; +use crate::deps::*; use crate::editing::preview::EditingError; use crate::util::gettext::*; use crate::util::root::ParentWindow; @@ -59,9 +60,6 @@ pub enum LpOrientation { } mod imp { - - use gtk::gdk; - use super::*; #[derive(Debug, Default, gtk::CompositeTemplate, glib::Properties)] @@ -72,6 +70,8 @@ mod imp { pub(super) image: TemplateChild, #[template_child] pub(super) selection: TemplateChild, + #[template_child] + aspect_ratio_buttons: TemplateChild, #[property(get, construct_only)] original_image: OnceCell, @@ -198,6 +198,16 @@ mod imp { obj.action_set_enabled("edit-crop.reset", obj.imp().is_reset_enabled()); } )); + + self.selection.connect_orientation_notify(glib::clone!( + #[weak] + obj, + move |_| { + obj.imp().asepect_ratio_orientation_changed(); + } + )); + + self.asepect_ratio_orientation_changed(); } fn dispose(&self) { @@ -303,6 +313,19 @@ mod imp { fn is_reset_enabled(&self) -> bool { self.obj().edit_window().operations().is_some() || self.selection.cropped() } + + fn asepect_ratio_orientation_changed(&self) { + match self.selection.orientation() { + LpOrientation::Landscape => { + self.aspect_ratio_buttons + .remove_css_class("button-icons-portrait"); + } + LpOrientation::Portrait => { + self.aspect_ratio_buttons + .add_css_class("button-icons-portrait"); + } + } + } } } diff --git a/src/widgets/edit/crop.ui b/src/widgets/edit/crop.ui index 7b363a8..360085a 100644 --- a/src/widgets/edit/crop.ui +++ b/src/widgets/edit/crop.ui @@ -76,7 +76,7 @@ Aspect Ratio - + true 6 6 @@ -144,6 +144,9 @@ aspect-ratio-5to4-symbolic _5:4 true + @@ -162,6 +165,9 @@ aspect-ratio-4to3-symbolic _4:3 true + @@ -180,6 +186,9 @@ aspect-ratio-3to2-symbolic _3:2 true + @@ -198,6 +207,9 @@ aspect-ratio-16to9-symbolic _16:9 true +