Debian Codegraph @

podcasts-gtk/src/widgets/base_view.rs

raw symbols SCIP
1 // base_view.rs
2 //
3 // Copyright 2017 Jordan Petridis <[email protected]>
4 //
5 // This program is free software: you can redistribute it and/or modify
6 // it under the terms of the GNU General Public License as published by
7 // the Free Software Foundation, either version 3 of the License, or
8 // (at your option) any later version.
9 //
10 // This program is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
14 //
15 // You should have received a copy of the GNU General Public License
16 // along with this program. If not, see <http://www.gnu.org/licenses/>.
17 //
18 // SPDX-License-Identifier: GPL-3.0-or-later
19
20 use gtk::PolicyType;
21 use gtk::glib;
22 use gtk::prelude::*;
23 use gtk::subclass::prelude::*;
24
25 use adw::prelude::*;
26 use adw::subclass::prelude::*;
27
28 use std::sync::LazyLock;
29
30 #[derive(Debug, Default)]
31 pub struct BaseViewPriv {
32 pub scrolled_window: gtk::ScrolledWindow,
33 }
34
35 #[glib::object_subclass]
36 impl ObjectSubclass for BaseViewPriv {
37 const NAME: &'static str = "PdBaseView";
38 type Type = super::BaseView;
39 type ParentType = adw::Bin;
40 }
41
42 impl ObjectImpl for BaseViewPriv {
43 fn constructed(&self) {
44 self.parent_constructed();
45
46 let obj = self.obj();
47
48 self.scrolled_window
49 .set_policy(PolicyType::Never, PolicyType::Automatic);
50 obj.set_size_request(360, -1);
51 obj.set_child(Some(&self.scrolled_window));
52 }
53
54 fn properties() -> &'static [glib::ParamSpec] {
55 static PROPERTIES: LazyLock<Vec<glib::ParamSpec>> = LazyLock::new(|| {
56 vec![
57 glib::ParamSpecObject::builder::<gtk::Widget>("child")
58 .readwrite()
59 .build(),
60 ]
61 });
62 PROPERTIES.as_ref()
63 }
64
65 fn property(&self, _id: usize, pspec: &glib::ParamSpec) -> glib::Value {
66 match pspec.name() {
67 "child" => self.scrolled_window.child().to_value(),
68 _ => unimplemented!(),
69 }
70 }
71
72 fn set_property(&self, _id: usize, value: &glib::Value, pspec: &glib::ParamSpec) {
73 match pspec.name() {
74 "child" => self
75 .scrolled_window
76 .set_child(value.get::<gtk::Widget>().ok().as_ref()),
77 _ => unimplemented!(),
78 };
79 }
80 }
81
82 impl WidgetImpl for BaseViewPriv {}
83 impl BinImpl for BaseViewPriv {}
84
85 glib::wrapper! {
86 pub struct BaseView(ObjectSubclass<BaseViewPriv>)
87 @extends gtk::Widget, adw::Bin,
88 @implements gtk::ConstraintTarget, gtk::Buildable, gtk::Accessible;
89 }
90
91 impl Default for BaseView {
92 fn default() -> Self {
93 glib::Object::new()
94 }
95 }
96
97 impl BaseView {
98 pub(crate) fn set_content<T: IsA<gtk::Widget>>(&self, widget: &T) {
99 self.imp().scrolled_window.set_child(Some(widget));
100 }
101 }