| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 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 |
} |