Skip to content

Commit c939ac0

Browse files
committed
Updated src/custom_button/imp.rs:
- Updated reuse copyright year - Added clearer import headers - Refactored to now import std::sync::OncelLock as it has been [merged into std](rust-lang/rust#105587) - Refactored "properties()" function to reflect OnceLock changes - Refactored to import Value from glib::value as it now has its own module in glib - Removed now unused "_obj" parameter to "property()" and "set_property()" functions Updated src/custom_button/mod.rs: - Updated reuse copyright year - Added clearer import headers - Updated "new()" function to use "Object::builder::<CustomButton>().build()" instead of untyped "Obect::new()"" - Commented out "with_label()" function as this seems to be deprecated Signed-off-by: Deren Vural <35734401+derenv@users.noreply.github.com>
1 parent 882c0e3 commit c939ac0

File tree

2 files changed

+35
-14
lines changed

2 files changed

+35
-14
lines changed

src/custom_button/imp.rs

+26-9
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// SPDX-FileCopyrightText: 2022 Deren Vural
1+
// SPDX-FileCopyrightText: 2024 Deren Vural
22
// SPDX-License-Identifier: GPL-3.0-or-later
33

44
/**
@@ -18,8 +18,17 @@
1818
*
1919
*/
2020
// Imports
21-
use glib::{once_cell::sync::Lazy, ParamSpec, Value};
22-
use gtk::{glib, subclass::prelude::*};
21+
// std
22+
use std::sync::OnceLock;
23+
// gtk-rs
24+
use gtk::{
25+
glib,
26+
subclass::prelude::*
27+
};
28+
use glib::{
29+
ParamSpec,
30+
value::Value
31+
};
2332

2433
/// Object holding the State and any Template Children
2534
#[derive(Default)]
@@ -63,16 +72,15 @@ impl ObjectImpl for CustomButton {
6372
* glib::ParamSpecObject::builder("formatter").build(),
6473
*/
6574
fn properties() -> &'static [ParamSpec] {
66-
static PROPERTIES: Lazy<Vec<ParamSpec>> = Lazy::new(|| {
75+
static PROPERTIES: OnceLock<Vec<ParamSpec>> = OnceLock::new();
76+
PROPERTIES.get_or_init(|| {
6777
vec![
6878
//
6979
]
70-
});
80+
})
7181

7282
//println!("PROPERTIES: {:?}", PROPERTIES);//TEST
7383
//println!("trying to add `base_call`: {:?}", glib::ParamSpecString::builder("base_call").build());//TEST
74-
75-
PROPERTIES.as_ref()
7684
}
7785

7886
/**
@@ -91,7 +99,12 @@ impl ObjectImpl for CustomButton {
9199
* Notes:
92100
*
93101
*/
94-
fn set_property(&self, _obj: &Self::Type, _id: usize, _value: &Value, pspec: &ParamSpec) {
102+
fn set_property(
103+
&self,
104+
_id: usize,
105+
_value: &Value,
106+
pspec: &ParamSpec
107+
) {
95108
//println!("setting: {:?}", pspec.name());//TEST
96109

97110
match pspec.name() {
@@ -116,7 +129,11 @@ impl ObjectImpl for CustomButton {
116129
* Notes:
117130
*
118131
*/
119-
fn property(&self, _obj: &Self::Type, _id: usize, pspec: &ParamSpec) -> Value {
132+
fn property(
133+
&self,
134+
_id: usize,
135+
pspec: &ParamSpec
136+
) -> Value {
120137
//println!("getting: {:?}", pspec.name());//TEST
121138

122139
match pspec.name() {

src/custom_button/mod.rs

+9-5
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// SPDX-FileCopyrightText: 2022 Deren Vural
1+
// SPDX-FileCopyrightText: 2024 Deren Vural
22
// SPDX-License-Identifier: GPL-3.0-or-later
33

44
/**
@@ -21,6 +21,9 @@
2121
mod imp;
2222

2323
// Imports
24+
// std
25+
//
26+
// gtk-rs
2427
use glib::Object;
2528
use gtk::glib;
2629

@@ -32,9 +35,10 @@ glib::wrapper! {
3235

3336
impl CustomButton {
3437
pub fn new() -> Self {
35-
Object::new(&[]).expect("Failed to create `CustomButton`.")
36-
}
37-
pub fn with_label(label: &str) -> Self {
38-
Object::new(&[("label", &label)]).expect("Failed to create `CustomButton`.")
38+
// Create Object
39+
Object::builder::<CustomButton>().build()
3940
}
41+
// pub fn with_label(label: &str) -> Self {
42+
// Object::with_label(&[("label", &label)]).expect("Failed to create `CustomButton`.")
43+
// }
4044
}

0 commit comments

Comments
 (0)