Debian Codegraph @

src/ui/drag_overlay.rs

raw ◀ ▶
Source reconstructed at patch state 0 of 1 — not the installed (fully patched) source.
1 Debian patch touch this file
1 // Fragments - drag_overlay.rs
2 // Copyright (C) 2023 Felix Häcker <[email protected]>
3 //
4 // This program is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU General Public License as published by
6 // the Free Software Foundation, either version 3 of the License, or
7 // (at your option) any later version.
8 //
9 // This program is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
13 //
14 // You should have received a copy of the GNU General Public License
15 // along with this program. If not, see <https://www.gnu.org/licenses/>.
16
17 // Inspired by [Loupe](https://gitlab.gnome.org/GNOME/loupe) and
18 // [Amberol](https://gitlab.gnome.org/World/amberol)
19
20 use adw::subclass::prelude::*;
21 use glib::Properties;
22 use gtk::glib;
23 use gtk::prelude::*;
24
25 mod imp {
26 use super::*;
27
28 #[derive(Debug, Default, Properties)]
29 #[properties(wrapper_type = super::FrgDragOverlay)]
30 pub struct FrgDragOverlay {
31 #[property(set = Self::set_child)]
32 pub child: Option<gtk::Widget>,
33 #[property(get)]
34 drop_target: gtk::DropTarget,
35 overlay: gtk::Overlay,
36 revealer: gtk::Revealer,
37 }
38
39 #[glib::object_subclass]
40 impl ObjectSubclass for FrgDragOverlay {
41 const NAME: &'static str = "FrgDragOverlay";
42 type Type = super::FrgDragOverlay;
43 type ParentType = adw::Bin;
44 }
45
46 #[glib::derived_properties]
47 impl ObjectImpl for FrgDragOverlay {
48 fn constructed(&self) {
49 self.parent_constructed();
50
51 self.overlay.set_parent(&*self.obj());
52 self.overlay.add_overlay(&self.revealer);
53
54 self.revealer.set_can_target(false);
55 self.revealer
56 .set_transition_type(gtk::RevealerTransitionType::Crossfade);
57 self.revealer.set_reveal_child(false);
58
59 self.drop_target.set_actions(gtk::gdk::DragAction::COPY);
60 self.drop_target.connect_current_drop_notify(
61 glib::clone!(@weak self.revealer as revealer => move |target| {
62 let reveal = target.current_drop().is_some();
63 revealer.set_reveal_child(reveal);
64 }),
65 );
66
67 let bin = adw::Bin::new();
68 bin.set_can_target(false);
69 bin.add_css_class("dragging-area-highlight");
70
71 self.revealer.set_child(Some(&bin));
72 }
73
74 fn dispose(&self) {
75 self.overlay.unparent();
76 }
77 }
78
79 impl WidgetImpl for FrgDragOverlay {}
80
81 impl BinImpl for FrgDragOverlay {}
82
83 impl FrgDragOverlay {
84 pub fn set_child(&self, child: Option<gtk::Widget>) {
85 self.overlay.set_child(child.as_ref());
86 }
87 }
88 }
89
90 glib::wrapper! {
91 pub struct FrgDragOverlay(
92 ObjectSubclass<imp::FrgDragOverlay>)
93 @extends gtk::Widget, adw::Bin;
94 }