From 446ae5063ad492f794a442d2507b1bf5ec7ebace Mon Sep 17 00:00:00 2001 From: Sophie Herold Date: Tue, 9 Jan 2024 15:56:23 +0100 Subject: [PATCH] window: Limit HeaderBar to min width as nat width Before we were doing the same with just the title in the HeaderBar. This gave problems with correctly measuring for ADW_CENTERING_POLICY_LOOSE. --- po/POTFILES.in | 2 +- src/application.rs | 6 + src/widgets/image/rotation.rs | 2 +- src/widgets/mod.rs | 4 +- src/widgets/{window_title.rs => shy_bin.rs} | 58 +++------ src/window.rs | 3 - src/window.ui | 127 ++++++++++---------- 7 files changed, 93 insertions(+), 109 deletions(-) rename src/widgets/{window_title.rs => shy_bin.rs} (51%) diff --git a/po/POTFILES.in b/po/POTFILES.in index 93c8704..fc42903 100644 --- a/po/POTFILES.in +++ b/po/POTFILES.in @@ -39,8 +39,8 @@ src/widgets/print.ui src/widgets/print_preview.rs src/widgets/properties_view.rs src/widgets/properties_view.ui +src/widgets/shy_bin.rs src/widgets/sliding_view.rs -src/widgets/window_title.rs src/window.rs src/window.ui src/window/controls.rs diff --git a/src/application.rs b/src/application.rs index 34ea9fa..c1ec73c 100644 --- a/src/application.rs +++ b/src/application.rs @@ -29,6 +29,7 @@ use crate::{about, config}; mod imp { use super::*; + use crate::widgets::LpShyBin; // The basic struct that holds our // state and widgets @@ -73,6 +74,11 @@ mod imp { // Overrides GApplication vfuncs impl ApplicationImpl for LpApplication { + fn startup(&self) { + self.parent_startup(); + LpShyBin::ensure_type(); + } + fn activate(&self) { let application = self.obj(); let window = LpWindow::new(&*application); diff --git a/src/widgets/image/rotation.rs b/src/widgets/image/rotation.rs index 66d4f4b..298d9f6 100644 --- a/src/widgets/image/rotation.rs +++ b/src/widgets/image/rotation.rs @@ -26,7 +26,7 @@ impl imp::LpImage { } self.rotation.set(rotation); - obj.configure_adjustments(); + self.configure_adjustments(); obj.notify_rotation(); obj.queue_draw(); } diff --git a/src/widgets/mod.rs b/src/widgets/mod.rs index 4f3d013..0a03ab4 100644 --- a/src/widgets/mod.rs +++ b/src/widgets/mod.rs @@ -24,8 +24,8 @@ mod image_view; mod print; mod print_preview; mod properties_view; +mod shy_bin; mod sliding_view; -mod window_title; pub use drag_overlay::LpDragOverlay; pub use image::LpImage; @@ -34,5 +34,5 @@ pub use image_view::LpImageView; pub use print::LpPrint; pub use print_preview::LpPrintPreview; pub use properties_view::LpPropertiesView; +pub use shy_bin::LpShyBin; pub use sliding_view::LpSlidingView; -pub use window_title::LpWindowTitle; diff --git a/src/widgets/window_title.rs b/src/widgets/shy_bin.rs similarity index 51% rename from src/widgets/window_title.rs rename to src/widgets/shy_bin.rs index b55f7fa..f372938 100644 --- a/src/widgets/window_title.rs +++ b/src/widgets/shy_bin.rs @@ -15,11 +15,12 @@ // // SPDX-License-Identifier: GPL-3.0-or-later -//! A window title +//! A bin that only has min width as natural width //! -//! This window title does not claim its complete width as natural width. This -//! avoids the window to grow to a large file name title instead of just -//! fittingly for the image size. +//! This bin does not claim its complete width as natural width. The HeaderBar +//! is wrapped in with this widget. This prevents the window from growing based +//! on a long file name in the title instead of just fitting to the image +//! size. use adw::prelude::*; use adw::subclass::prelude::*; @@ -29,46 +30,29 @@ use crate::deps::*; mod imp { use super::*; - #[derive(Debug, Default, glib::Properties)] - #[properties(wrapper_type = super::LpWindowTitle)] - pub struct LpWindowTitle { - #[property(type = String, set = Self::set_title)] - _title: (), - window_title: adw::WindowTitle, - } + #[derive(Debug, Default)] + pub struct LpShyBin {} #[glib::object_subclass] - impl ObjectSubclass for LpWindowTitle { - const NAME: &'static str = "LpWindowTitle"; - type Type = super::LpWindowTitle; + impl ObjectSubclass for LpShyBin { + const NAME: &'static str = "LpShyBin"; + type Type = super::LpShyBin; type ParentType = adw::Bin; } - impl ObjectImpl for LpWindowTitle { + impl ObjectImpl for LpShyBin { fn constructed(&self) { self.parent_constructed(); let obj = self.obj(); obj.set_layout_manager(None::); - obj.set_child(Some(&self.window_title)); obj.set_hexpand(true); } - - fn properties() -> &'static [glib::ParamSpec] { - Self::derived_properties() - } - - fn set_property(&self, id: usize, value: &glib::Value, pspec: &glib::ParamSpec) { - self.derived_set_property(id, value, pspec) - } - - fn property(&self, id: usize, pspec: &glib::ParamSpec) -> glib::Value { - self.derived_property(id, pspec) - } } - impl WidgetImpl for LpWindowTitle { + + impl WidgetImpl for LpShyBin { fn measure(&self, orientation: gtk::Orientation, for_size: i32) -> (i32, i32, i32, i32) { - let mut measure = self.window_title.measure(orientation, for_size); + let mut measure = self.obj().child().unwrap().measure(orientation, for_size); if orientation == gtk::Orientation::Horizontal { // Set natural size to minimal size @@ -79,19 +63,17 @@ mod imp { } fn size_allocate(&self, width: i32, height: i32, baseline: i32) { - self.window_title.allocate(width, height, baseline, None); + self.obj() + .child() + .unwrap() + .allocate(width, height, baseline, None); } } - impl BinImpl for LpWindowTitle {} - impl LpWindowTitle { - fn set_title(&self, title: String) { - self.window_title.set_title(&title); - } - } + impl BinImpl for LpShyBin {} } glib::wrapper! { - pub struct LpWindowTitle(ObjectSubclass) + pub struct LpShyBin(ObjectSubclass) @extends gtk::Widget, adw::Bin; } diff --git a/src/window.rs b/src/window.rs index f8cac62..62c0e31 100644 --- a/src/window.rs +++ b/src/window.rs @@ -53,7 +53,6 @@ const HIDE_CONTROLS_IDLE_TIMEOUT: u64 = 3000; mod imp { use super::*; - use crate::widgets::LpWindowTitle; // To use composite templates, you need // to use derive macro. Derive macros generate @@ -80,8 +79,6 @@ mod imp { #[template_child] pub(super) headerbar: TemplateChild, #[template_child] - pub(super) title: TemplateChild, - #[template_child] pub(super) headerbar_events: TemplateChild, #[template_child] pub(super) properties_button: TemplateChild, diff --git a/src/window.ui b/src/window.ui index cdb2e25..634662e 100644 --- a/src/window.ui +++ b/src/window.ui @@ -70,72 +70,71 @@ - - - - - - + + + + + + + + + edit-copy-symbolic + win.copy-image + Copy to Clipboard + + + + + user-trash-symbolic + win.trash + Move to Trash + + + + + open-menu-symbolic + Main Menu + True + + + primary_menu + + + object-rotate-left-symbolic + Rotate Left + win.rotate_ccw + + + + + + object-rotate-right-symbolic + Rotate Right + win.rotate_cw + + + + + + + + + + info-outline-symbolic + Image Properties + + + + + - - - - edit-copy-symbolic - win.copy-image - Copy to Clipboard - - - - - user-trash-symbolic - win.trash - Move to Trash - - - - - open-menu-symbolic - Main Menu - True - - - primary_menu - - - object-rotate-left-symbolic - Rotate Left - win.rotate_ccw - - - - - - object-rotate-right-symbolic - Rotate Right - win.rotate_cw - - - - - - - - - - info-outline-symbolic - Image Properties - - - - -