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
This commit is contained in:
Mukul Joshi 2025-09-28 13:12:36 +05:30 • committed by Sophie Herold
parent 80fb07db03
commit 48e27739f5

View file

@ -253,6 +253,8 @@ mod imp {
pub(super) orientation: RefCell<String>,
pub(super) ui_updates: UiUpdates,
pub(super) previous_width: Cell<Option<f64>>,
}
#[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();
}
}