Skip to content

Commit 49fb9a8

Browse files
examples: Use glib::derived_properties
1 parent 0d46d3f commit 49fb9a8

File tree

9 files changed

+21
-125
lines changed
  • examples

9 files changed

+21
-125
lines changed

examples/custom_editable/custom_tag/imp.rs

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11
use glib::clone;
22
use glib::once_cell::sync::Lazy;
33
use glib::subclass::Signal;
4-
use glib::{ParamSpec, Properties};
54
use gtk::glib;
65
use gtk::prelude::*;
76
use gtk::subclass::prelude::*;
87
use std::cell::{Cell, RefCell};
98

10-
#[derive(Debug, Properties)]
9+
#[derive(Debug, glib::Properties)]
1110
#[properties(wrapper_type = super::CustomTag)]
1211
pub struct CustomTag {
1312
pub container: gtk::Box,
@@ -40,19 +39,8 @@ impl ObjectSubclass for CustomTag {
4039
}
4140
}
4241

42+
#[glib::derived_properties]
4343
impl ObjectImpl for CustomTag {
44-
fn properties() -> &'static [ParamSpec] {
45-
Self::derived_properties()
46-
}
47-
48-
fn property(&self, id: usize, pspec: &ParamSpec) -> glib::Value {
49-
self.derived_property(id, pspec)
50-
}
51-
52-
fn set_property(&self, id: usize, value: &glib::Value, pspec: &ParamSpec) {
53-
self.derived_set_property(id, value, pspec)
54-
}
55-
5644
fn signals() -> &'static [Signal] {
5745
static SIGNALS: Lazy<Vec<Signal>> = Lazy::new(|| {
5846
vec![

examples/custom_layout_manager/custom_layout_child/imp.rs

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
1-
use glib::{ParamSpec, Properties, Value};
21
use gtk::prelude::*;
32
use gtk::subclass::prelude::*;
43
use gtk::{gdk, glib, graphene};
54
use std::cell::RefCell;
65

7-
#[derive(Debug, Properties)]
6+
#[derive(Debug, glib::Properties)]
87
#[properties(wrapper_type = super::CustomLayoutChild)]
98
pub struct CustomLayoutChild {
109
#[property(get, set, construct_only)]
@@ -26,19 +25,8 @@ impl ObjectSubclass for CustomLayoutChild {
2625
type ParentType = gtk::Widget;
2726
}
2827

28+
#[glib::derived_properties]
2929
impl ObjectImpl for CustomLayoutChild {
30-
fn properties() -> &'static [ParamSpec] {
31-
Self::derived_properties()
32-
}
33-
34-
fn property(&self, id: usize, pspec: &ParamSpec) -> Value {
35-
self.derived_property(id, pspec)
36-
}
37-
38-
fn set_property(&self, id: usize, value: &Value, pspec: &ParamSpec) {
39-
self.derived_set_property(id, value, pspec)
40-
}
41-
4230
fn constructed(&self) {
4331
self.parent_constructed();
4432
let widget = self.obj();

examples/custom_orientable/custom_orientable/imp.rs

Lines changed: 6 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,12 @@ use gtk::subclass::prelude::*;
99
pub struct CustomOrientable {
1010
first_label: RefCell<Option<gtk::Widget>>,
1111
second_label: RefCell<Option<gtk::Widget>>,
12+
// Every widget that implements Orientable has to define a "orientation"
13+
// property like below, gtk::Orientation::Horizontal is a placeholder
14+
// for the initial value.
15+
//
16+
// glib::ParamFlags::CONSTRUCT allows us to set that property the moment
17+
// we create a new instance of the widget
1218
#[property(get, set=Self::set_orientation, builder(gtk::Orientation::Horizontal))]
1319
orientation: RefCell<gtk::Orientation>,
1420
}
@@ -66,24 +72,6 @@ impl ObjectImpl for CustomOrientable {
6672
child.unparent();
6773
}
6874
}
69-
70-
// Every widget that implements Orientable has to define a "orientation"
71-
// property like below, gtk::Orientation::Horizontal is a placeholder
72-
// for the initial value.
73-
//
74-
// glib::ParamFlags::CONSTRUCT allows us to set that property the moment
75-
// we create a new instance of the widget
76-
fn properties() -> &'static [glib::ParamSpec] {
77-
Self::derived_properties()
78-
}
79-
80-
fn set_property(&self, id: usize, value: &glib::Value, pspec: &glib::ParamSpec) {
81-
self.derived_set_property(id, value, pspec)
82-
}
83-
84-
fn property(&self, id: usize, pspec: &glib::ParamSpec) -> glib::Value {
85-
self.derived_property(id, pspec)
86-
}
8775
}
8876

8977
impl WidgetImpl for CustomOrientable {}

examples/expressions/metadata/imp.rs

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -28,16 +28,5 @@ impl ObjectSubclass for Metadata {
2828
}
2929
}
3030

31-
impl ObjectImpl for Metadata {
32-
fn properties() -> &'static [glib::ParamSpec] {
33-
Self::derived_properties()
34-
}
35-
36-
fn set_property(&self, id: usize, value: &glib::Value, pspec: &glib::ParamSpec) {
37-
self.derived_set_property(id, value, pspec)
38-
}
39-
40-
fn property(&self, id: usize, pspec: &glib::ParamSpec) -> glib::Value {
41-
self.derived_property(id, pspec)
42-
}
43-
}
31+
#[glib::derived_properties]
32+
impl ObjectImpl for Metadata {}

examples/expressions/note/imp.rs

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -19,16 +19,5 @@ impl ObjectSubclass for Note {
1919
type Type = super::Note;
2020
}
2121

22-
impl ObjectImpl for Note {
23-
fn properties() -> &'static [glib::ParamSpec] {
24-
Self::derived_properties()
25-
}
26-
27-
fn set_property(&self, id: usize, value: &glib::Value, pspec: &glib::ParamSpec) {
28-
self.derived_set_property(id, value, pspec)
29-
}
30-
31-
fn property(&self, id: usize, pspec: &glib::ParamSpec) -> glib::Value {
32-
self.derived_property(id, pspec)
33-
}
34-
}
22+
#[glib::derived_properties]
23+
impl ObjectImpl for Note {}

examples/list_box_model/list_box_row/imp.rs

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -23,19 +23,8 @@ impl ObjectSubclass for ListBoxRow {
2323
type Type = super::ListBoxRow;
2424
}
2525

26+
#[glib::derived_properties]
2627
impl ObjectImpl for ListBoxRow {
27-
fn properties() -> &'static [ParamSpec] {
28-
Self::derived_properties()
29-
}
30-
31-
fn set_property(&self, id: usize, value: &Value, pspec: &ParamSpec) {
32-
self.derived_set_property(id, value, pspec)
33-
}
34-
35-
fn property(&self, id: usize, pspec: &ParamSpec) -> Value {
36-
self.derived_property(id, pspec)
37-
}
38-
3928
fn constructed(&self) {
4029
self.parent_constructed();
4130
let obj = self.obj();

examples/list_box_model/row_data/imp.rs

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -29,16 +29,5 @@ impl ObjectSubclass for RowData {
2929
//
3030
// This maps between the GObject properties and our internal storage of the
3131
// corresponding values of the properties.
32-
impl ObjectImpl for RowData {
33-
fn properties() -> &'static [ParamSpec] {
34-
Self::derived_properties()
35-
}
36-
37-
fn set_property(&self, id: usize, value: &Value, pspec: &ParamSpec) {
38-
self.derived_set_property(id, value, pspec)
39-
}
40-
41-
fn property(&self, id: usize, pspec: &ParamSpec) -> Value {
42-
self.derived_property(id, pspec)
43-
}
44-
}
32+
#[glib::derived_properties]
33+
impl ObjectImpl for RowData {}

examples/rotation_bin/rotation_bin/imp.rs

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -22,19 +22,8 @@ impl ObjectSubclass for RotationBin {
2222
type ParentType = gtk::Widget;
2323
}
2424

25+
#[glib::derived_properties]
2526
impl ObjectImpl for RotationBin {
26-
fn properties() -> &'static [glib::ParamSpec] {
27-
Self::derived_properties()
28-
}
29-
30-
fn property(&self, id: usize, pspec: &glib::ParamSpec) -> glib::Value {
31-
self.derived_property(id, pspec)
32-
}
33-
34-
fn set_property(&self, id: usize, value: &glib::Value, pspec: &glib::ParamSpec) {
35-
self.derived_set_property(id, value, pspec)
36-
}
37-
3827
fn dispose(&self) {
3928
if let Some(child) = self.child.borrow_mut().take() {
4029
child.unparent();

examples/squeezer_bin/squeezer_bin/imp.rs

Lines changed: 3 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
1-
use gtk::glib::{self, Properties};
2-
use gtk::glib::{ParamSpec, Value};
3-
use gtk::gsk;
41
use gtk::prelude::*;
52
use gtk::subclass::prelude::*;
3+
use gtk::{glib, gsk};
64

75
use std::cell::{Cell, RefCell};
86

@@ -17,7 +15,7 @@ fn child_size(child: &impl IsA<gtk::Widget>) -> ((i32, i32), (i32, i32)) {
1715
)
1816
}
1917

20-
#[derive(Debug, Default, Properties)]
18+
#[derive(Debug, Default, glib::Properties)]
2119
#[properties(wrapper_type = super::SqueezerBin)]
2220
pub struct SqueezerBin {
2321
#[property(get, explicit_notify)]
@@ -33,19 +31,8 @@ impl ObjectSubclass for SqueezerBin {
3331
type Type = super::SqueezerBin;
3432
}
3533

34+
#[glib::derived_properties]
3635
impl ObjectImpl for SqueezerBin {
37-
fn properties() -> &'static [glib::ParamSpec] {
38-
Self::derived_properties()
39-
}
40-
41-
fn property(&self, id: usize, pspec: &ParamSpec) -> Value {
42-
self.derived_property(id, pspec)
43-
}
44-
45-
fn set_property(&self, id: usize, value: &Value, pspec: &ParamSpec) {
46-
self.derived_set_property(id, value, pspec)
47-
}
48-
4936
fn constructed(&self) {
5037
self.parent_constructed();
5138
let obj = self.obj();

0 commit comments

Comments
 (0)