window: Prefer wide window over properties overlay

This commit is contained in:
Sophie Herold 2024-08-05 23:28:01 +02:00
parent e61b3357ea
commit 8ddaf34e87
4 changed files with 29 additions and 6 deletions

View file

@ -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.

View file

@ -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::*;

View file

@ -291,7 +291,6 @@ impl LpImage {
}
pub async fn reload(&self) {
dbg!("reloadking");
if let Some(file) = self.file() {
self.load(&file).await;
} else {

View file

@ -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);
}
}