Skip to content

Commit

Permalink
Updated src/custom_button/imp.rs:
Browse files Browse the repository at this point in the history
- 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 <[email protected]>
  • Loading branch information
derenv committed May 20, 2024
1 parent 882c0e3 commit c939ac0
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 14 deletions.
35 changes: 26 additions & 9 deletions src/custom_button/imp.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// SPDX-FileCopyrightText: 2022 Deren Vural
// SPDX-FileCopyrightText: 2024 Deren Vural
// SPDX-License-Identifier: GPL-3.0-or-later

/**
Expand All @@ -18,8 +18,17 @@
*
*/
// Imports
use glib::{once_cell::sync::Lazy, ParamSpec, Value};
use gtk::{glib, subclass::prelude::*};
// std
use std::sync::OnceLock;
// gtk-rs
use gtk::{
glib,
subclass::prelude::*
};
use glib::{
ParamSpec,
value::Value
};

/// Object holding the State and any Template Children
#[derive(Default)]
Expand Down Expand Up @@ -63,16 +72,15 @@ impl ObjectImpl for CustomButton {
* glib::ParamSpecObject::builder("formatter").build(),
*/
fn properties() -> &'static [ParamSpec] {
static PROPERTIES: Lazy<Vec<ParamSpec>> = Lazy::new(|| {
static PROPERTIES: OnceLock<Vec<ParamSpec>> = OnceLock::new();
PROPERTIES.get_or_init(|| {
vec![
//
]
});
})

//println!("PROPERTIES: {:?}", PROPERTIES);//TEST
//println!("trying to add `base_call`: {:?}", glib::ParamSpecString::builder("base_call").build());//TEST

PROPERTIES.as_ref()
}

/**
Expand All @@ -91,7 +99,12 @@ impl ObjectImpl for CustomButton {
* Notes:
*
*/
fn set_property(&self, _obj: &Self::Type, _id: usize, _value: &Value, pspec: &ParamSpec) {
fn set_property(
&self,
_id: usize,
_value: &Value,
pspec: &ParamSpec
) {
//println!("setting: {:?}", pspec.name());//TEST

match pspec.name() {
Expand All @@ -116,7 +129,11 @@ impl ObjectImpl for CustomButton {
* Notes:
*
*/
fn property(&self, _obj: &Self::Type, _id: usize, pspec: &ParamSpec) -> Value {
fn property(
&self,
_id: usize,
pspec: &ParamSpec
) -> Value {
//println!("getting: {:?}", pspec.name());//TEST

match pspec.name() {
Expand Down
14 changes: 9 additions & 5 deletions src/custom_button/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// SPDX-FileCopyrightText: 2022 Deren Vural
// SPDX-FileCopyrightText: 2024 Deren Vural
// SPDX-License-Identifier: GPL-3.0-or-later

/**
Expand All @@ -21,6 +21,9 @@
mod imp;

// Imports
// std
//
// gtk-rs
use glib::Object;
use gtk::glib;

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

impl CustomButton {
pub fn new() -> Self {
Object::new(&[]).expect("Failed to create `CustomButton`.")
}
pub fn with_label(label: &str) -> Self {
Object::new(&[("label", &label)]).expect("Failed to create `CustomButton`.")
// Create Object
Object::builder::<CustomButton>().build()
}
// pub fn with_label(label: &str) -> Self {
// Object::with_label(&[("label", &label)]).expect("Failed to create `CustomButton`.")
// }
}

0 comments on commit c939ac0

Please sign in to comment.