From 8ddaf34e8715f101f0512dec6a4d942b6385ab57 Mon Sep 17 00:00:00 2001 From: Sophie Herold Date: Mon, 5 Aug 2024 23:28:01 +0200 Subject: [PATCH] window: Prefer wide window over properties overlay --- ...ndow-can-open-with-overlaying-bottom-sheet | 1 + src/metadata.rs | 3 +- src/widgets/image/loading.rs | 1 - src/window.rs | 30 +++++++++++++++++-- 4 files changed, 29 insertions(+), 6 deletions(-) create mode 100644 news.d/47.rc/fixed-window-can-open-with-overlaying-bottom-sheet diff --git a/news.d/47.rc/fixed-window-can-open-with-overlaying-bottom-sheet b/news.d/47.rc/fixed-window-can-open-with-overlaying-bottom-sheet new file mode 100644 index 0000000..29b87a8 --- /dev/null +++ b/news.d/47.rc/fixed-window-can-open-with-overlaying-bottom-sheet @@ -0,0 +1 @@ +Make the window wider when it would open with a bottom-sheet overlay for properties. That way, the properties can be shown in a sidebar. diff --git a/src/metadata.rs b/src/metadata.rs index 85858d6..0634fed 100644 --- a/src/metadata.rs +++ b/src/metadata.rs @@ -25,8 +25,7 @@ mod file; mod gps; pub use file::FileInfo; -use glycin::{Frame, MemoryFormat}; -use glycin::{FrameDetails, ImageInfoDetails}; +use glycin::{Frame, FrameDetails, ImageInfoDetails, MemoryFormat}; pub use gps::GPSLocation; use crate::deps::*; diff --git a/src/widgets/image/loading.rs b/src/widgets/image/loading.rs index 699a781..9a13978 100644 --- a/src/widgets/image/loading.rs +++ b/src/widgets/image/loading.rs @@ -291,7 +291,6 @@ impl LpImage { } pub async fn reload(&self) { - dbg!("reloadking"); if let Some(file) = self.file() { self.load(&file).await; } else { diff --git a/src/window.rs b/src/window.rs index cca9bc8..c4cb9c8 100644 --- a/src/window.rs +++ b/src/window.rs @@ -780,7 +780,8 @@ impl LpWindow { self.action_set_enabled(&Action::ZoomInCursor, can_zoom_in && enabled_shown); self.action_set_enabled(&Action::ZoomInCenter, can_zoom_in && enabled_shown); - // Actions that are available if there is an current image, even if it's not shown + // Actions that are available if there is an current image, even if it's not + // shown const ACTIONS_CURRENT: &[Action] = &[ Action::OpenWith, Action::CopyImage, @@ -894,13 +895,36 @@ impl LpWindow { } pub fn resize_default(&self) { + let imp = self.imp(); + if self .image_view() .current_image() .is_some_and(|img| img.image_size_available()) { - // this let's the window determine the default size from LpImage's natural size - self.set_default_size(-1, -1); + let shows_properties = imp.properties_button.is_active(); + + let (_, window_natural_width, _, _) = self.measure(gtk::Orientation::Horizontal, -1); + let (_, window_natural_height, _, _) = self.measure(gtk::Orientation::Vertical, -1); + + // These have to be in sync with the "conditions" for the "overlay-properties" + // breakpoint + let min_width_for_overlay = adw::LengthUnit::Sp.to_px(590., None).ceil() as i32; + let min_height_for_overlay = adw::LengthUnit::Sp.to_px(550., None).ceil() as i32; + + let (width, height) = if shows_properties + && window_natural_width < min_width_for_overlay + && window_natural_height < min_height_for_overlay + { + // Avoid overlaying bottom sheet being triggered for the image properties by + // using a window wide enough to allow for a sidebar + (min_width_for_overlay.saturating_add(1), -1) + } else { + // this lets the window determine the default size from LpImage's natural size + (-1, -1) + }; + + self.set_default_size(width, height); } }