From b72811bb9cf41d17e53af98900d32346f1af79bb Mon Sep 17 00:00:00 2001 From: Sophie Herold Date: Thu, 19 Sep 2024 22:11:03 +0200 Subject: [PATCH] dragOverlay: Try out new design proposal Teams/Design/os-mockups#186 --- .../scalable/actions/image-round-symbolic.svg | 2 + data/resources/style.css | 16 +++-- po/POTFILES.in | 1 + src/util.rs | 2 +- src/widgets/drag_overlay.rs | 65 ++++++++----------- src/widgets/drag_overlay.ui | 29 +++++++++ src/window.ui | 10 +-- 7 files changed, 72 insertions(+), 53 deletions(-) create mode 100644 data/resources/icons/scalable/actions/image-round-symbolic.svg create mode 100644 src/widgets/drag_overlay.ui diff --git a/data/resources/icons/scalable/actions/image-round-symbolic.svg b/data/resources/icons/scalable/actions/image-round-symbolic.svg new file mode 100644 index 0000000..0f687ca --- /dev/null +++ b/data/resources/icons/scalable/actions/image-round-symbolic.svg @@ -0,0 +1,2 @@ + + diff --git a/data/resources/style.css b/data/resources/style.css index 617a069..d4bc7dc 100644 --- a/data/resources/style.css +++ b/data/resources/style.css @@ -39,10 +39,18 @@ outline { } /* Drag overlay */ -.lp-dragging-area-highlight { - border-radius: 8px; - background-color: color-mix(in srgb, var(--accent-bg-color) 35%, transparent); - margin: 24px; +lpdragoverlay .overlay-status { + color: var(--accent-color); + background-color: color-mix(in srgb, var(--accent-bg-color) 8%, transparent); + /* Same color for border as for icon and label */ + /* Probably due to a GTK bug, this currently does not give the exact same color */ + border: 2px dashed color-mix(in srgb, currentColor var(--dim-opacity), transparent); + border-radius: 2px; + margin: 12px; +} + +lpdragoverlay .overlay-status label { + opacity: var(--dim-opacity); } lpprintpreview { diff --git a/po/POTFILES.in b/po/POTFILES.in index 72fffc5..7c0098d 100644 --- a/po/POTFILES.in +++ b/po/POTFILES.in @@ -20,6 +20,7 @@ src/util.rs src/util/gettext.rs src/widgets.rs src/widgets/drag_overlay.rs +src/widgets/drag_overlay.ui src/widgets/error_details.rs src/widgets/error_details.ui src/widgets/image.rs diff --git a/src/util.rs b/src/util.rs index 99c513f..1155c57 100644 --- a/src/util.rs +++ b/src/util.rs @@ -1,5 +1,5 @@ // Copyright (c) 2021-2023 Christopher Davis -// Copyright (c) 2022-2023 Sophie Herold +// Copyright (c) 2022-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 diff --git a/src/widgets/drag_overlay.rs b/src/widgets/drag_overlay.rs index c476c6d..8e7b1d4 100644 --- a/src/widgets/drag_overlay.rs +++ b/src/widgets/drag_overlay.rs @@ -20,29 +20,31 @@ //! //! This implementation is inspired by [Amberol](https://gitlab.gnome.org/World/amberol) +use std::cell::OnceCell; +use std::marker::PhantomData; + use adw::prelude::*; +use adw::subclass::prelude::*; +use glib::Properties; +use gtk::CompositeTemplate; use crate::deps::*; mod imp { - use std::cell::OnceCell; - - use adw::subclass::prelude::*; - use glib::{ParamSpec, Properties, Value}; use super::*; - #[derive(Debug, Default, Properties)] + #[derive(Debug, Default, CompositeTemplate, Properties)] #[properties(wrapper_type = super::LpDragOverlay)] + #[template(file = "drag_overlay.ui")] pub struct LpDragOverlay { - /// Usual content - #[property(set = Self::set_child)] - pub child: Option, /// Widget overplayed when dragging over child - #[property(set = Self::set_overlayed)] - pub overlayed: Option, - pub overlay: gtk::Overlay, - pub revealer: gtk::Revealer, + #[property(set = Self::set_content)] + pub content: PhantomData>, + #[template_child] + pub overlay: TemplateChild, + #[template_child] + pub revealer: TemplateChild, #[property(set = Self::set_drop_target, get, explicit_notify, construct_only)] pub drop_target: OnceCell, } @@ -54,49 +56,30 @@ mod imp { type ParentType = adw::Bin; fn class_init(klass: &mut Self::Class) { + Self::bind_template(klass); klass.set_css_name("lpdragoverlay"); } + + fn instance_init(obj: &glib::subclass::InitializingObject) { + obj.init_template(); + } } + #[glib::derived_properties] impl ObjectImpl for LpDragOverlay { - fn properties() -> &'static [ParamSpec] { - Self::derived_properties() - } - - fn set_property(&self, id: usize, value: &Value, pspec: &ParamSpec) { - self.derived_set_property(id, value, pspec) - } - - fn property(&self, id: usize, pspec: &ParamSpec) -> Value { - self.derived_property(id, pspec) - } - fn constructed(&self) { - self.overlay.set_parent(&*self.obj()); - self.overlay.add_overlay(&self.revealer); + self.parent_constructed(); self.revealer.set_can_target(false); self.revealer .set_transition_type(gtk::RevealerTransitionType::Crossfade); - self.revealer.set_reveal_child(false); - } - - fn dispose(&self) { - self.overlay.unparent(); + //self.revealer.set_reveal_child(false); } } impl WidgetImpl for LpDragOverlay {} impl BinImpl for LpDragOverlay {} impl LpDragOverlay { - pub fn set_child(&self, child: Option) { - self.overlay.set_child(child.as_ref()); - } - - pub fn set_overlayed(&self, overlayed: Option) { - self.revealer.set_child(overlayed.as_ref()); - } - pub fn set_drop_target(&self, drop_target: gtk::DropTarget) { drop_target.connect_current_drop_notify(glib::clone!( #[weak(rename_to = revealer)] @@ -111,6 +94,10 @@ mod imp { self.obj().notify("drop-target"); } + + pub fn set_content(&self, child: Option) { + self.overlay.set_child(child.as_ref()); + } } } diff --git a/src/widgets/drag_overlay.ui b/src/widgets/drag_overlay.ui new file mode 100644 index 0000000..faace03 --- /dev/null +++ b/src/widgets/drag_overlay.ui @@ -0,0 +1,29 @@ + + + + diff --git a/src/window.ui b/src/window.ui index 7dc03da..eb1c917 100644 --- a/src/window.ui +++ b/src/window.ui @@ -250,15 +250,7 @@ drop_target - - - false - - - - + status_page