From dd359235cf9b1b6cdf0b5f02bb31f29d6f3d5152 Mon Sep 17 00:00:00 2001 From: Sophie Herold Date: Thu, 19 Dec 2024 23:25:50 +0100 Subject: [PATCH] properties: Remove usage of breakpoints --- po/POTFILES.in | 3 +- src/widgets.rs | 2 - src/widgets/image_window.rs | 67 ++++++- src/widgets/image_window.ui | 320 +++++++++++++++------------------- src/widgets/window.rs | 6 +- src/widgets/window.ui | 9 +- src/widgets/window_content.rs | 161 ----------------- src/widgets/window_content.ui | 27 --- 8 files changed, 210 insertions(+), 385 deletions(-) delete mode 100644 src/widgets/window_content.rs delete mode 100644 src/widgets/window_content.ui diff --git a/po/POTFILES.in b/po/POTFILES.in index 47933fd..bcef182 100644 --- a/po/POTFILES.in +++ b/po/POTFILES.in @@ -19,6 +19,7 @@ src/metadata.rs src/metadata/file.rs src/util.rs src/util/gettext.rs +src/util/root.rs src/widgets.rs src/widgets/drag_overlay.rs src/widgets/drag_overlay.ui @@ -61,5 +62,3 @@ src/widgets/shy_bin.rs src/widgets/sliding_view.rs src/widgets/window.rs src/widgets/window.ui -src/widgets/window_content.rs -src/widgets/window_content.ui diff --git a/src/widgets.rs b/src/widgets.rs index 081712b..9804eaa 100644 --- a/src/widgets.rs +++ b/src/widgets.rs @@ -32,7 +32,6 @@ mod properties_view; mod shy_bin; mod sliding_view; mod window; -mod window_content; pub use drag_overlay::LpDragOverlay; pub use edit_window::LpEditWindow; @@ -47,4 +46,3 @@ pub use properties_view::LpPropertiesView; pub use shy_bin::LpShyBin; pub use sliding_view::LpSlidingView; pub use window::LpWindow; -pub use window_content::LpWindowContent; diff --git a/src/widgets/image_window.rs b/src/widgets/image_window.rs index 121d022..0e2a10d 100644 --- a/src/widgets/image_window.rs +++ b/src/widgets/image_window.rs @@ -45,7 +45,7 @@ use crate::util::gettext::*; use crate::util::root::ParentWindow; use crate::util::Direction; use crate::widgets::window::ActionPartGlobal; -use crate::widgets::{LpDragOverlay, LpImage, LpImageView, LpPropertiesView, LpWindowContent}; +use crate::widgets::{LpDragOverlay, LpImage, LpImageView, LpPropertiesView}; /// Animation duration for showing overlay buttons in milliseconds const SHOW_CONTROLS_ANIMATION_DURATION: u32 = 200; @@ -61,9 +61,6 @@ mod imp { #[properties(wrapper_type = super::LpImageWindow)] #[template(file = "image_window.ui")] pub struct LpImageWindow { - #[template_child] - pub(super) window_content: TemplateChild, - #[template_child] pub(super) headerbar: TemplateChild, #[template_child] @@ -77,6 +74,9 @@ mod imp { #[template_child] pub(super) primary_menu: TemplateChild, + #[template_child] + pub(super) toolbar_view: TemplateChild, + #[template_child] pub(super) stack: TemplateChild, #[template_child] @@ -98,9 +98,6 @@ mod imp { #[property(get = Self::is_showing_image)] pub(super) is_showing_image: PhantomData, - /// Set via binding to HeaderBar - #[property(get, set)] - headerbar_opacity: Cell, /// Motion controller for complete window pub(super) motion_controller: gtk::EventControllerMotion, @@ -293,6 +290,18 @@ mod imp { ), ); + obj.connect_is_showing_image_notify(|obj| { + obj.update_headerbar_style(); + }); + + self.properties_button.connect_active_notify(glib::clone!( + #[weak] + obj, + move |_| { + obj.update_headerbar_style(); + } + )); + // action win.previous status self.image_view .connect_is_previous_available_notify(glib::clone!( @@ -880,6 +889,8 @@ impl LpImageWindow { }; self.imp().fullscreen_button.set_icon_name(icon); + self.update_headerbar_style(); + if !self.window().is_fullscreen() { self.set_cursor(None); self.show_controls(); @@ -888,11 +899,14 @@ impl LpImageWindow { } fn is_headerbar_flat(&self) -> bool { - self.imp().window_content.is_headerbar_flat() + matches!( + self.imp().toolbar_view.top_bar_style(), + adw::ToolbarStyle::Flat + ) } fn is_content_extended_to_top(&self) -> bool { - self.imp().window_content.is_content_extended_to_top() + self.window().is_fullscreen() && !self.imp().properties_button.is_active() } fn update_accel_status(&self) { @@ -917,4 +931,39 @@ impl LpImageWindow { pub fn properties_button(&self) -> gtk::ToggleButton { self.imp().properties_button.clone() } + + fn update_header_opacity(&self) { + let imp = self.imp(); + + if self.is_headerbar_flat() && self.is_showing_image() { + // Bring headerbar opacity in sync with controls + imp.headerbar.set_opacity(self.headerbar_opacity()); + } else { + imp.headerbar.set_opacity(1.); + } + } + + fn update_headerbar_style(&self) { + let imp = self.imp(); + + imp.toolbar_view + .set_extend_content_to_top_edge(self.is_content_extended_to_top()); + + let style = if !self.is_showing_image() || self.is_content_extended_to_top() { + // Flat headerbar for empty state and fullscreen without properties enabled + adw::ToolbarStyle::Flat + } else { + // Use the border variant of raised to avoid shadows over images + adw::ToolbarStyle::RaisedBorder + }; + + if style != imp.toolbar_view.top_bar_style() { + imp.toolbar_view.set_top_bar_style(style); + self.update_header_opacity(); + } + } + + fn headerbar_opacity(&self) -> f64 { + self.imp().headerbar.opacity() + } } diff --git a/src/widgets/image_window.ui b/src/widgets/image_window.ui index 4dc68b6..26d9f05 100644 --- a/src/widgets/image_window.ui +++ b/src/widgets/image_window.ui @@ -58,57 +58,120 @@ diff --git a/src/widgets/window.rs b/src/widgets/window.rs index 480868c..d487231 100644 --- a/src/widgets/window.rs +++ b/src/widgets/window.rs @@ -34,7 +34,7 @@ use crate::widgets::{LpEditWindow, LpImageView, LpImageWindow}; const SHOW_WINDOW_AFTER: u64 = 2000; mod imp { - use std::cell::Cell; + use std::cell::{Cell, RefCell}; use super::*; @@ -70,6 +70,10 @@ mod imp { narrow_layout: Cell, #[property(get, set)] wide_layout: Cell, + #[property(get, set)] + layout_name: RefCell, + #[property(get, set)] + not_fullscreened: Cell, } #[glib::object_subclass] diff --git a/src/widgets/window.ui b/src/widgets/window.ui index 0dbac78..f524bea 100644 --- a/src/widgets/window.ui +++ b/src/widgets/window.ui @@ -5,18 +5,23 @@ 498 360 294 + wide + + + min-width: 590sp + wide false - true + max-width: 590sp + narrow true - false diff --git a/src/widgets/window_content.rs b/src/widgets/window_content.rs deleted file mode 100644 index 799d066..0000000 --- a/src/widgets/window_content.rs +++ /dev/null @@ -1,161 +0,0 @@ -// Copyright (c) 2024 Sophie Herold -// -// This program is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with this program. If not, see . -// -// SPDX-License-Identifier: GPL-3.0-or-later -// -// Copyright (c) 2024 Christopher Davis - -//! Contains the main structure inside the window -//! -//! This is it's own widget since it's reused inside different layouts for -//! different positions of the image properties. - -use std::cell::{Cell, RefCell}; - -use adw::prelude::*; -use adw::subclass::prelude::*; -use glib::Properties; -use gtk::CompositeTemplate; - -use crate::deps::*; - -mod imp { - use super::*; - - #[derive(Default, Debug, Properties, CompositeTemplate)] - #[properties(wrapper_type = super::LpWindowContent)] - #[template(file = "window_content.ui")] - pub struct LpWindowContent { - #[template_child] - pub(super) toolbar_view: TemplateChild, - - #[property(get, set, nullable)] - headerbar: RefCell>, - #[property(get, set, nullable)] - content: RefCell>, - - // Set via binding to window - #[property(get, set)] - fullscreened: Cell, - // Set via binding to properties toggle button - #[property(get, set)] - show_properties: Cell, - // Set via binding to window - #[property(get, set)] - is_showing_image: Cell, - } - - impl LpWindowContent { - fn update_header_opacity(&self) { - let obj = self.obj(); - - if let Some(headerbar) = obj.headerbar() { - if obj.is_headerbar_flat() && obj.is_showing_image() { - // Bring headerbar opacity in sync with controls - headerbar.set_opacity(self.headerbar_opacity()); - } else { - headerbar.set_opacity(1.); - }; - } - } - - fn update_headerbar_style(&self) { - let obj = self.obj(); - - self.toolbar_view - .set_extend_content_to_top_edge(obj.is_content_extended_to_top()); - - let style = if !obj.is_showing_image() || obj.is_content_extended_to_top() { - // Flat headerbar for empty state and fullscreen without properties enabled - adw::ToolbarStyle::Flat - } else { - // Use the border variant of raised to avoid shadows over images - adw::ToolbarStyle::RaisedBorder - }; - - let toolbar_view = self.toolbar_view.get(); - if style != toolbar_view.top_bar_style() { - toolbar_view.set_top_bar_style(style); - self.update_header_opacity(); - } - } - - fn headerbar_opacity(&self) -> f64 { - self.headerbar - .borrow() - .as_ref() - .map(|x| x.opacity()) - .unwrap_or(1.) - } - } - - #[glib::object_subclass] - impl ObjectSubclass for LpWindowContent { - const NAME: &'static str = "LpWindowContent"; - type Type = super::LpWindowContent; - type ParentType = adw::Bin; - - fn class_init(klass: &mut Self::Class) { - klass.bind_template(); - } - - fn instance_init(obj: &gio::glib::subclass::InitializingObject) { - obj.init_template(); - } - } - - #[glib::derived_properties] - impl ObjectImpl for LpWindowContent { - fn constructed(&self) { - self.parent_constructed(); - - let obj = self.obj(); - - obj.connect_is_showing_image_notify(|obj| { - obj.imp().update_headerbar_style(); - }); - - obj.connect_fullscreened_notify(|obj| { - obj.imp().update_headerbar_style(); - }); - - obj.connect_show_properties_notify(|obj| { - obj.imp().update_headerbar_style(); - }); - } - } - - impl WidgetImpl for LpWindowContent {} - impl BinImpl for LpWindowContent {} -} - -glib::wrapper! { - pub struct LpWindowContent(ObjectSubclass) - @extends gtk::Widget, adw::Bin, - @implements gtk::Buildable, gtk::ConstraintTarget; -} - -impl LpWindowContent { - pub fn is_headerbar_flat(&self) -> bool { - matches!( - self.imp().toolbar_view.top_bar_style(), - adw::ToolbarStyle::Flat - ) - } - - pub fn is_content_extended_to_top(&self) -> bool { - self.fullscreened() && self.show_properties() - } -} diff --git a/src/widgets/window_content.ui b/src/widgets/window_content.ui deleted file mode 100644 index 25b14ac..0000000 --- a/src/widgets/window_content.ui +++ /dev/null @@ -1,27 +0,0 @@ - - - -