Skip to content

Commit b627c77

Browse files
author
Deren Vural
committed
GObject properties
Updated SettingsWindow class: - Added custom property functions Updated Processor class: - Added panic when property doesn't exist (get OR set) Updated Property class: - Added panic when property doesn't exist (get OR set) Updated Provider class: - Added panic when property doesn't exist (get OR set) Updated Formatter class: - Added panic when property doesn't exist (get OR set) Updated CustomButton class: - Added custom property functions Signed-off-by: Deren Vural <[email protected]>
1 parent 2b64146 commit b627c77

File tree

6 files changed

+184
-8
lines changed

6 files changed

+184
-8
lines changed

src/custom_button/imp.rs

Lines changed: 89 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
*/
2020

2121
// Imports
22+
use glib::{once_cell::sync::Lazy, ParamSpec, Value};
2223
use gtk::{glib, subclass::prelude::*};
2324

2425
/// Object holding the State and any Template Children
@@ -37,7 +38,94 @@ impl ObjectSubclass for CustomButton {
3738
}
3839

3940
// Trait shared by all GObjects
40-
impl ObjectImpl for CustomButton {}
41+
impl ObjectImpl for CustomButton {
42+
/**
43+
* Name:
44+
* properties
45+
*
46+
* Description:
47+
* Create list of custom properties for our GObject
48+
*
49+
* Made:
50+
* 05/10/2022
51+
*
52+
* Made by:
53+
* Deren Vural
54+
*
55+
* Notes:
56+
* beware that you need to use kebab-case (<https://en.wikipedia.org/wiki/Letter_case#Kebab_case>)
57+
*
58+
* ParamSpec Examples:
59+
* glib::ParamSpecString::builder("icon").build(),
60+
* glib::ParamSpecUInt::builder("gpu_count").build(),
61+
* glib::ParamSpecString::builder("call_extension").build(),
62+
* TODO: these are from property class
63+
* glib::ParamSpecBoxed::builder("processor").build(),
64+
* glib::ParamSpecObject::builder("formatter").build(),
65+
*/
66+
fn properties() -> &'static [ParamSpec] {
67+
static PROPERTIES: Lazy<Vec<ParamSpec>> = Lazy::new(|| {
68+
vec![
69+
//
70+
]
71+
});
72+
73+
//println!("PROPERTIES: {:?}", PROPERTIES);//TEST
74+
//println!("trying to add `base_call`: {:?}", glib::ParamSpecString::builder("base_call").build());//TEST
75+
76+
PROPERTIES.as_ref()
77+
}
78+
79+
/**
80+
* Name:
81+
* set_property
82+
*
83+
* Description:
84+
* Mutator for custom GObject properties
85+
*
86+
* Made:
87+
* 05/10/2022
88+
*
89+
* Made by:
90+
* Deren Vural
91+
*
92+
* Notes:
93+
*
94+
*/
95+
fn set_property(&self, _obj: &Self::Type, _id: usize, _value: &Value, pspec: &ParamSpec) {
96+
//println!("setting: {:?}", pspec.name());//TEST
97+
98+
match pspec.name() {
99+
//
100+
_ => panic!("Property `{}` does not exist..", pspec.name())
101+
}
102+
}
103+
104+
/**
105+
* Name:
106+
* property
107+
*
108+
* Description:
109+
* Accessir for custom GObject properties
110+
*
111+
* Made:
112+
* 05/10/2022
113+
*
114+
* Made by:
115+
* Deren Vural
116+
*
117+
* Notes:
118+
*
119+
*/
120+
fn property(&self, _obj: &Self::Type, _id: usize, pspec: &ParamSpec) -> Value {
121+
//println!("getting: {:?}", pspec.name());//TEST
122+
123+
match pspec.name() {
124+
//
125+
_ => panic!("Property `{}` does not exist..", pspec.name())
126+
}
127+
}
128+
}
41129

42130
// Trait shared by all widgets
43131
impl WidgetImpl for CustomButton {}

src/formatter/imp.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ impl ObjectImpl for Formatter {
115115

116116
match pspec.name() {
117117
//
118-
_ => unimplemented!(), //TODO
118+
_ => panic!("Property `{}` does not exist..", pspec.name())
119119
}
120120
}
121121

@@ -140,7 +140,7 @@ impl ObjectImpl for Formatter {
140140

141141
match pspec.name() {
142142
//
143-
_ => unimplemented!(), //TODO
143+
_ => panic!("Property `{}` does not exist..", pspec.name())
144144
}
145145
}
146146
}

src/processor/imp.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ impl ObjectImpl for Processor {
140140
.expect("The value needs to be of type `String`.");
141141
self.tail_call.replace(input_tail_call);
142142
}
143-
_ => unimplemented!(), //TODO
143+
_ => panic!("Property `{}` does not exist..", pspec.name())
144144
}
145145
}
146146

@@ -188,7 +188,7 @@ impl ObjectImpl for Processor {
188188

189189
value.to_value()
190190
}
191-
_ => unimplemented!(), //TODO
191+
_ => panic!("Property `{}` does not exist..", pspec.name())
192192
}
193193
}
194194
}

src/property/imp.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ impl ObjectImpl for Property {
148148
.expect("The value needs to be of type `Formatter`.");
149149
self.formatter.replace(input_formatter);
150150
}
151-
_ => unimplemented!(), //TODO
151+
_ => panic!("Property `{}` does not exist..", pspec.name())
152152
}
153153
}
154154

@@ -212,7 +212,7 @@ impl ObjectImpl for Property {
212212

213213
value.to_value()
214214
}
215-
_ => unimplemented!(), //TODO
215+
_ => panic!("Property `{}` does not exist..", pspec.name())
216216
}
217217
}
218218
}

src/provider/imp.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,7 @@ impl ObjectImpl for Provider {
235235

236236
value.to_value()
237237
}
238-
_ => unimplemented!(), //TODO
238+
_ => panic!("Property `{}` does not exist..", pspec.name())
239239
}
240240
}
241241
}

src/settingswindow/imp.rs

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
*/
2020

2121
// Imports
22+
use glib::{once_cell::sync::Lazy, ParamSpec, Value};
2223
use adwaita::{gio, glib, prelude::*, subclass::prelude::*, ComboRow};
2324
use gio::Settings;
2425
use glib::{once_cell::sync::OnceCell, signal::Inhibit, subclass::InitializingObject};
@@ -193,6 +194,93 @@ impl ObjectImpl for SettingsWindow {
193194
obj.setup_callbacks();
194195
obj.setup_actions();
195196
}
197+
198+
/**
199+
* Name:
200+
* properties
201+
*
202+
* Description:
203+
* Create list of custom properties for our GObject
204+
*
205+
* Made:
206+
* 05/10/2022
207+
*
208+
* Made by:
209+
* Deren Vural
210+
*
211+
* Notes:
212+
* beware that you need to use kebab-case (<https://en.wikipedia.org/wiki/Letter_case#Kebab_case>)
213+
*
214+
* ParamSpec Examples:
215+
* glib::ParamSpecString::builder("icon").build(),
216+
* glib::ParamSpecUInt::builder("gpu_count").build(),
217+
* glib::ParamSpecString::builder("call_extension").build(),
218+
* TODO: these are from property class
219+
* glib::ParamSpecBoxed::builder("processor").build(),
220+
* glib::ParamSpecObject::builder("formatter").build(),
221+
*/
222+
fn properties() -> &'static [ParamSpec] {
223+
static PROPERTIES: Lazy<Vec<ParamSpec>> = Lazy::new(|| {
224+
vec![
225+
//
226+
]
227+
});
228+
229+
//println!("PROPERTIES: {:?}", PROPERTIES);//TEST
230+
//println!("trying to add `base_call`: {:?}", glib::ParamSpecString::builder("base_call").build());//TEST
231+
232+
PROPERTIES.as_ref()
233+
}
234+
235+
/**
236+
* Name:
237+
* set_property
238+
*
239+
* Description:
240+
* Mutator for custom GObject properties
241+
*
242+
* Made:
243+
* 05/10/2022
244+
*
245+
* Made by:
246+
* Deren Vural
247+
*
248+
* Notes:
249+
*
250+
*/
251+
fn set_property(&self, _obj: &Self::Type, _id: usize, _value: &Value, pspec: &ParamSpec) {
252+
//println!("setting: {:?}", pspec.name());//TEST
253+
254+
match pspec.name() {
255+
//
256+
_ => panic!("Property `{}` does not exist..", pspec.name())
257+
}
258+
}
259+
260+
/**
261+
* Name:
262+
* property
263+
*
264+
* Description:
265+
* Accessir for custom GObject properties
266+
*
267+
* Made:
268+
* 05/10/2022
269+
*
270+
* Made by:
271+
* Deren Vural
272+
*
273+
* Notes:
274+
*
275+
*/
276+
fn property(&self, _obj: &Self::Type, _id: usize, pspec: &ParamSpec) -> Value {
277+
//println!("getting: {:?}", pspec.name());//TEST
278+
279+
match pspec.name() {
280+
//
281+
_ => panic!("Property `{}` does not exist..", pspec.name())
282+
}
283+
}
196284
}
197285

198286
/**

0 commit comments

Comments
 (0)