Skip to content

Commit

Permalink
properties: impl HasParamSpec for Vec<String> and StrV
Browse files Browse the repository at this point in the history
  • Loading branch information
pbor committed Feb 14, 2023
1 parent 9839ec6 commit 3931f06
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 2 deletions.
11 changes: 9 additions & 2 deletions glib-macros/tests/properties.rs
Expand Up @@ -99,6 +99,8 @@ mod foo {
bar: Mutex<String>,
#[property(get, set)]
double: RefCell<f64>,
#[property(get, set)]
string_vec: RefCell<Vec<String>>,
#[property(get = |_| 42.0, set)]
infer_inline_type: RefCell<f64>,
// The following property doesn't store any data. The value of the property is calculated
Expand Down Expand Up @@ -197,14 +199,19 @@ mod foo {
fn props() {
let myfoo: foo::Foo = glib::object::Object::new();

// Read bar
// Read values
let bar: String = myfoo.property("bar");
assert_eq!(bar, "".to_string());
let string_vec: Vec<String> = myfoo.property("string-vec");
assert!(string_vec.is_empty());

// Set bar
// Set values
myfoo.set_property("bar", "epic".to_value());
let bar: String = myfoo.property("bar");
assert_eq!(bar, "epic".to_string());
myfoo.set_property("string-vec", ["epic", "more epic"].to_value());
let string_vec: Vec<String> = myfoo.property("string-vec");
assert_eq!(string_vec, vec!["epic".to_string(), "more epic".to_string()]);

// Custom getter
let buzz: String = myfoo.property("buzz");
Expand Down
18 changes: 18 additions & 0 deletions glib/src/param_spec.rs
Expand Up @@ -2115,6 +2115,24 @@ impl HasParamSpec for String {
Self::ParamSpec::builder
}
}
impl HasParamSpec for crate::StrV {
type ParamSpec = ParamSpecBoxed;
type SetValue = Self;
type BuilderFn = fn(&str) -> ParamSpecBoxedBuilder<Self>;

fn param_spec_builder() -> Self::BuilderFn {
Self::ParamSpec::builder
}
}
impl HasParamSpec for Vec<String> {
type ParamSpec = ParamSpecBoxed;
type SetValue = Self;
type BuilderFn = fn(&str) -> ParamSpecBoxedBuilder<Self>;

fn param_spec_builder() -> Self::BuilderFn {
Self::ParamSpec::builder
}
}
impl HasParamSpec for char {
type ParamSpec = ParamSpecUnichar;
type SetValue = Self;
Expand Down

0 comments on commit 3931f06

Please sign in to comment.