slidingView: Use properties macro
This commit is contained in:
parent
4ca7c71538
commit
7d36c93029
1 changed files with 7 additions and 20 deletions
|
|
@ -27,6 +27,7 @@ use crate::widgets::LpImagePage;
|
||||||
|
|
||||||
use adw::prelude::*;
|
use adw::prelude::*;
|
||||||
use adw::subclass::prelude::*;
|
use adw::subclass::prelude::*;
|
||||||
|
use glib::Properties;
|
||||||
use indexmap::IndexMap;
|
use indexmap::IndexMap;
|
||||||
use once_cell::sync::Lazy;
|
use once_cell::sync::Lazy;
|
||||||
|
|
||||||
|
|
@ -48,11 +49,13 @@ mod imp {
|
||||||
use super::*;
|
use super::*;
|
||||||
use glib::subclass::Signal;
|
use glib::subclass::Signal;
|
||||||
|
|
||||||
#[derive(Default)]
|
#[derive(Default, Properties)]
|
||||||
|
#[properties(wrapper_type = super::LpSlidingView)]
|
||||||
pub struct LpSlidingView {
|
pub struct LpSlidingView {
|
||||||
/// Pages that can be slided through
|
/// Pages that can be slided through
|
||||||
pub(super) pages: RefCell<Vec<LpImagePage>>,
|
pub(super) pages: RefCell<Vec<LpImagePage>>,
|
||||||
/// Page that is currently shown or the animation is animating towards
|
/// Page that is currently shown or the animation is animating towards
|
||||||
|
#[property(get)]
|
||||||
pub(super) current_page: RefCell<Option<LpImagePage>>,
|
pub(super) current_page: RefCell<Option<LpImagePage>>,
|
||||||
/// Animatable position, 0.0 first image, 1.0 second image etc
|
/// Animatable position, 0.0 first image, 1.0 second image etc
|
||||||
pub(super) position: Cell<f64>,
|
pub(super) position: Cell<f64>,
|
||||||
|
|
@ -74,23 +77,11 @@ mod imp {
|
||||||
|
|
||||||
impl ObjectImpl for LpSlidingView {
|
impl ObjectImpl for LpSlidingView {
|
||||||
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::<LpImagePage>("current-page")
|
|
||||||
.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() {
|
|
||||||
"current-page" => obj.current_page().to_value(),
|
|
||||||
name => unimplemented!("property {name}"),
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn signals() -> &'static [Signal] {
|
fn signals() -> &'static [Signal] {
|
||||||
|
|
@ -480,10 +471,6 @@ impl LpSlidingView {
|
||||||
self.queue_allocate();
|
self.queue_allocate();
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn current_page(&self) -> Option<LpImagePage> {
|
|
||||||
self.imp().current_page.borrow().clone()
|
|
||||||
}
|
|
||||||
|
|
||||||
fn set_current_page(&self, page: Option<&LpImagePage>) {
|
fn set_current_page(&self, page: Option<&LpImagePage>) {
|
||||||
self.imp().current_page.replace(page.cloned());
|
self.imp().current_page.replace(page.cloned());
|
||||||
self.notify("current-page");
|
self.notify("current-page");
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue