From 48e27739f5fb1380676de70135ab4ff693143923 Mon Sep 17 00:00:00 2001 From: Mukul Joshi Date: Sun, 28 Sep 2025 13:12:36 +0530 Subject: [PATCH] Print preview: Revert to previous width on disabling of fill space Saves the width prior to applying fill space. This saved width is reapplied when fill space is disabled directly through the toggle. Fill space may be disabled indirectly (by changing the width/height). In those cases, the saved width is discarded. Fixes #297 --- src/widgets/print.rs | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/src/widgets/print.rs b/src/widgets/print.rs index 58c8a7f..a429bcd 100644 --- a/src/widgets/print.rs +++ b/src/widgets/print.rs @@ -253,6 +253,8 @@ mod imp { pub(super) orientation: RefCell, pub(super) ui_updates: UiUpdates, + + pub(super) previous_width: Cell>, } #[glib::object_subclass] @@ -583,11 +585,16 @@ impl LpPrint { self.print_settings().resolution() as f64 } + fn indirect_disable_fill_space(&self) { + self.imp().previous_width.set(None); + self.imp().fill_space.set_active(false); + } + pub fn on_width_changed(&self) { if self.ui_updates() { let _ui_updates_disabled = self.disable_ui_updates(); // Disable 'fill space' when manually changing size - self.imp().fill_space.set_active(false); + self.indirect_disable_fill_space(); self.update_height(); self.draw_preview(); } @@ -598,7 +605,7 @@ impl LpPrint { let imp = self.imp(); let _ui_updates_disabled = self.disable_ui_updates(); // Disable 'fill space' when manually changing size - imp.fill_space.set_active(false); + self.indirect_disable_fill_space(); let (orig_width, orig_height) = self.original_size(); let width = self @@ -851,11 +858,18 @@ impl LpPrint { } fn on_fill_space_changed(&self) { + let imp = self.imp(); if self.fill_space() { + imp.previous_width.set(Some(imp.width.value())); let _ui_updates_disabled = self.disable_ui_updates(); self.update_width(); self.update_height(); self.draw_preview(); + } else if let Some(width) = imp.previous_width.get() { + let _ui_updates_disabled = self.disable_ui_updates(); + imp.width.set_value(width); + self.update_height(); + self.draw_preview(); } }