From 1fc9674cb8cd10acae1c3fca7b680686d5127d59 Mon Sep 17 00:00:00 2001 From: Sophie Herold Date: Tue, 17 Sep 2024 21:02:01 +0200 Subject: [PATCH] edit: Init crop view with selecting complete image --- src/widgets/edit/crop.rs | 14 ++++++++------ src/widgets/edit/crop.ui | 1 + src/widgets/edit/crop_selection.rs | 28 ++++++++++++++++++---------- 3 files changed, 27 insertions(+), 16 deletions(-) diff --git a/src/widgets/edit/crop.rs b/src/widgets/edit/crop.rs index 3aa9786..02cd41e 100644 --- a/src/widgets/edit/crop.rs +++ b/src/widgets/edit/crop.rs @@ -103,7 +103,6 @@ mod imp { obj.child().set_parent(obj); - obj.set_layout_manager(None::); self.image.duplicate_from(&obj.original_image()); } @@ -120,12 +119,15 @@ mod imp { obj.child().allocate(width, height, baseline, None); - self.selection.set_size( - image.image_rendering_x() as i32, - image.image_rendering_y() as i32, - image.image_rendering_width() as i32, - image.image_rendering_height() as i32, + let (x, y, width, height) = ( + image.image_rendering_x(), + image.image_rendering_y(), + image.image_rendering_width(), + image.image_rendering_height(), ); + + self.selection.ensure_initialized(x, y, width, height); + self.selection.set_size(x, y, width, height); } fn measure(&self, orientation: gtk::Orientation, for_size: i32) -> (i32, i32, i32, i32) { diff --git a/src/widgets/edit/crop.ui b/src/widgets/edit/crop.ui index 87bb6f9..f84c02d 100644 --- a/src/widgets/edit/crop.ui +++ b/src/widgets/edit/crop.ui @@ -62,6 +62,7 @@ 18 + false diff --git a/src/widgets/edit/crop_selection.rs b/src/widgets/edit/crop_selection.rs index bf8e200..1039593 100644 --- a/src/widgets/edit/crop_selection.rs +++ b/src/widgets/edit/crop_selection.rs @@ -174,6 +174,8 @@ mod imp { #[property(get=Self::total_height, set=Self::set_total_height)] total_height: PhantomData, + pub(super) initialized: Cell, + #[property(get, set=Self::set_crop_x)] crop_x: Cell, #[property(get, set=Self::set_crop_y)] @@ -756,13 +758,19 @@ impl LpEditCropSelection { glib::Object::new() } - pub fn reset(&self, x: i32, y: i32, width: i32, height: i32) { + pub fn ensure_initialized(&self, x: f64, y: f64, width: f64, height: f64) { let imp = self.imp(); - self.set_margin_start(x); - self.set_margin_top(y); - self.set_total_width(width); - self.set_total_height(height); + if imp.initialized.get() { + return; + } + + imp.initialized.set(true); + + self.set_margin_start(x as i32); + self.set_margin_top(y as i32); + self.set_total_width(width as i32); + self.set_total_height(height as i32); imp.set_crop_x(0.); imp.set_crop_y(0.); @@ -770,7 +778,7 @@ impl LpEditCropSelection { imp.set_crop_height(height as f32); } - pub fn set_size(&self, x: i32, y: i32, width: i32, height: i32) { + pub fn set_size(&self, x: f64, y: f64, width: f64, height: f64) { let ratio = width as f32 / self.total_width() as f32; self.set_crop_x(self.crop_x() * ratio); @@ -778,9 +786,9 @@ impl LpEditCropSelection { self.set_crop_width(self.crop_width() * ratio); self.set_crop_height(self.crop_height() * ratio); - self.set_margin_start(x); - self.set_margin_top(y); - self.set_total_width(width); - self.set_total_height(height); + self.set_margin_start(x as i32); + self.set_margin_top(y as i32); + self.set_total_width(width as i32); + self.set_total_height(height as i32); } }