From 7d36c93029ac6a7d2dd6aca7846f550d22f57c2f Mon Sep 17 00:00:00 2001 From: Sophie Herold Date: Wed, 29 Nov 2023 19:28:27 +0100 Subject: [PATCH] slidingView: Use properties macro --- src/widgets/sliding_view.rs | 27 +++++++-------------------- 1 file changed, 7 insertions(+), 20 deletions(-) diff --git a/src/widgets/sliding_view.rs b/src/widgets/sliding_view.rs index 28872a3..725c9e0 100644 --- a/src/widgets/sliding_view.rs +++ b/src/widgets/sliding_view.rs @@ -27,6 +27,7 @@ use crate::widgets::LpImagePage; use adw::prelude::*; use adw::subclass::prelude::*; +use glib::Properties; use indexmap::IndexMap; use once_cell::sync::Lazy; @@ -48,11 +49,13 @@ mod imp { use super::*; use glib::subclass::Signal; - #[derive(Default)] + #[derive(Default, Properties)] + #[properties(wrapper_type = super::LpSlidingView)] pub struct LpSlidingView { /// Pages that can be slided through pub(super) pages: RefCell>, /// Page that is currently shown or the animation is animating towards + #[property(get)] pub(super) current_page: RefCell>, /// Animatable position, 0.0 first image, 1.0 second image etc pub(super) position: Cell, @@ -74,23 +77,11 @@ mod imp { impl ObjectImpl for LpSlidingView { fn properties() -> &'static [glib::ParamSpec] { - static PROPERTIES: Lazy> = Lazy::new(|| { - vec![ - glib::ParamSpecObject::builder::("current-page") - .read_only() - .build(), - ] - }); - - PROPERTIES.as_ref() + Self::derived_properties() } - fn property(&self, _id: usize, pspec: &glib::ParamSpec) -> glib::Value { - let obj = self.obj(); - match pspec.name() { - "current-page" => obj.current_page().to_value(), - name => unimplemented!("property {name}"), - } + fn property(&self, id: usize, pspec: &glib::ParamSpec) -> glib::Value { + self.derived_property(id, pspec) } fn signals() -> &'static [Signal] { @@ -480,10 +471,6 @@ impl LpSlidingView { self.queue_allocate(); } - pub fn current_page(&self) -> Option { - self.imp().current_page.borrow().clone() - } - fn set_current_page(&self, page: Option<&LpImagePage>) { self.imp().current_page.replace(page.cloned()); self.notify("current-page");