imagePage: Use properties macro
This commit is contained in:
parent
390f16792a
commit
4ca7c71538
1 changed files with 13 additions and 19 deletions
|
|
@ -25,14 +25,15 @@ use crate::widgets::LpImage;
|
||||||
|
|
||||||
use adw::subclass::prelude::*;
|
use adw::subclass::prelude::*;
|
||||||
use glib::clone;
|
use glib::clone;
|
||||||
|
use glib::Properties;
|
||||||
use gtk::prelude::*;
|
use gtk::prelude::*;
|
||||||
use gtk::CompositeTemplate;
|
use gtk::CompositeTemplate;
|
||||||
use once_cell::sync::Lazy;
|
|
||||||
|
|
||||||
mod imp {
|
mod imp {
|
||||||
use super::*;
|
use super::*;
|
||||||
|
|
||||||
#[derive(Debug, Default, CompositeTemplate)]
|
#[derive(Debug, Default, CompositeTemplate, Properties)]
|
||||||
|
#[properties(wrapper_type = super::LpImagePage)]
|
||||||
#[template(file = "image_page.ui")]
|
#[template(file = "image_page.ui")]
|
||||||
pub struct LpImagePage {
|
pub struct LpImagePage {
|
||||||
#[template_child]
|
#[template_child]
|
||||||
|
|
@ -48,6 +49,7 @@ mod imp {
|
||||||
#[template_child]
|
#[template_child]
|
||||||
pub(super) scrolled_window: TemplateChild<gtk::ScrolledWindow>,
|
pub(super) scrolled_window: TemplateChild<gtk::ScrolledWindow>,
|
||||||
#[template_child]
|
#[template_child]
|
||||||
|
#[property(type = LpImage, get = Self::image)]
|
||||||
pub(super) image: TemplateChild<LpImage>,
|
pub(super) image: TemplateChild<LpImage>,
|
||||||
#[template_child]
|
#[template_child]
|
||||||
pub(super) popover: TemplateChild<gtk::PopoverMenu>,
|
pub(super) popover: TemplateChild<gtk::PopoverMenu>,
|
||||||
|
|
@ -74,21 +76,11 @@ mod imp {
|
||||||
|
|
||||||
impl ObjectImpl for LpImagePage {
|
impl ObjectImpl for LpImagePage {
|
||||||
fn properties() -> &'static [glib::ParamSpec] {
|
fn properties() -> &'static [glib::ParamSpec] {
|
||||||
static PROPERTIES: Lazy<Vec<glib::ParamSpec>> = Lazy::new(|| {
|
Self::derived_properties()
|
||||||
vec![glib::ParamSpecObject::builder::<LpImage>("image")
|
|
||||||
.read_only()
|
|
||||||
.build()]
|
|
||||||
});
|
|
||||||
|
|
||||||
PROPERTIES.as_ref()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn property(&self, _id: usize, pspec: &glib::ParamSpec) -> glib::Value {
|
fn property(&self, id: usize, pspec: &glib::ParamSpec) -> glib::Value {
|
||||||
let obj = self.obj();
|
self.derived_property(id, pspec)
|
||||||
match pspec.name() {
|
|
||||||
"image" => obj.image().to_value(),
|
|
||||||
name => unimplemented!("property {name}"),
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn constructed(&self) {
|
fn constructed(&self) {
|
||||||
|
|
@ -143,6 +135,12 @@ mod imp {
|
||||||
|
|
||||||
impl WidgetImpl for LpImagePage {}
|
impl WidgetImpl for LpImagePage {}
|
||||||
impl BinImpl for LpImagePage {}
|
impl BinImpl for LpImagePage {}
|
||||||
|
|
||||||
|
impl LpImagePage {
|
||||||
|
pub fn image(&self) -> LpImage {
|
||||||
|
self.image.get()
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
glib::wrapper! {
|
glib::wrapper! {
|
||||||
|
|
@ -173,10 +171,6 @@ impl LpImagePage {
|
||||||
self.imp().scrolled_window.clone()
|
self.imp().scrolled_window.clone()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn image(&self) -> LpImage {
|
|
||||||
self.imp().image.get()
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn content_provider(&self) -> Option<gdk::ContentProvider> {
|
pub fn content_provider(&self) -> Option<gdk::ContentProvider> {
|
||||||
self.imp().image.content_provider()
|
self.imp().image.content_provider()
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue