Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

impl HasParamSpec on glib::Variant #1022

Merged
merged 1 commit into from
Feb 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions glib-macros/tests/properties.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,8 @@ mod foo {
double: RefCell<f64>,
#[property(get, set)]
string_vec: RefCell<Vec<String>>,
#[property(get, set, builder(glib::VariantTy::DOUBLE))]
variant: RefCell<Option<glib::Variant>>,
#[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 @@ -204,6 +206,8 @@ fn props() {
assert_eq!(bar, "".to_string());
let string_vec: Vec<String> = myfoo.property("string-vec");
assert!(string_vec.is_empty());
let var: Option<glib::Variant> = myfoo.property("variant");
assert!(var.is_none());

// Set values
myfoo.set_property("bar", "epic".to_value());
Expand All @@ -215,6 +219,10 @@ fn props() {
string_vec,
vec!["epic".to_string(), "more epic".to_string()]
);
let myv = Some(2.0f64.to_variant());
myfoo.set_property("variant", &myv);
let var: Option<glib::Variant> = myfoo.property("variant");
assert_eq!(var, myv);

// Custom getter
let buzz: String = myfoo.property("buzz");
Expand Down
11 changes: 11 additions & 0 deletions glib/src/param_spec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2224,6 +2224,17 @@ impl HasParamSpec for bool {
}
}

impl HasParamSpec for crate::Variant {
type ParamSpec = ParamSpecVariant;
type SetValue = Self;
type BuilderFn =
fn(&'static str, ty: &'static crate::VariantTy) -> ParamSpecVariantBuilder<'static>;

fn param_spec_builder() -> Self::BuilderFn {
Self::ParamSpec::builder
}
}

#[cfg(test)]
mod tests {
use super::*;
Expand Down