gtk4/auto/property_expression.rs
1// This file was generated by gir (https://github.com/gtk-rs/gir)
2// from gir-files (https://github.com/gtk-rs/gir-files)
3// DO NOT EDIT
4
5use crate::{ffi, Expression};
6use glib::{prelude::*, translate::*};
7
8glib::wrapper! {
9 /// A `GObject` property value in a [`Expression`][crate::Expression].
10 #[doc(alias = "GtkPropertyExpression")]
11 pub struct PropertyExpression(Shared<ffi::GtkPropertyExpression>);
12
13 match fn {
14 ref => |ptr| ffi::gtk_expression_ref(ptr as *mut ffi::GtkExpression),
15 unref => |ptr| ffi::gtk_expression_unref(ptr as *mut ffi::GtkExpression),
16 }
17}
18
19impl StaticType for PropertyExpression {
20 fn static_type() -> glib::Type {
21 unsafe { from_glib(ffi::gtk_property_expression_get_type()) }
22 }
23}
24
25impl PropertyExpression {
26 /// Creates an expression that looks up a property.
27 ///
28 /// The object to use is found by evaluating the `expression`,
29 /// or using the `this` argument when `expression` is `NULL`.
30 ///
31 /// If the resulting object conforms to `this_type`, its property named
32 /// `property_name` will be queried. Otherwise, this expression's
33 /// evaluation will fail.
34 ///
35 /// The given `this_type` must have a property with `property_name`.
36 /// ## `this_type`
37 /// The type to expect for the this type
38 /// ## `expression`
39 /// Expression to
40 /// evaluate to get the object to query or `NULL` to
41 /// query the `this` object
42 /// ## `property_name`
43 /// name of the property
44 ///
45 /// # Returns
46 ///
47 /// a new [`Expression`][crate::Expression]
48 #[doc(alias = "gtk_property_expression_new")]
49 pub fn new(
50 this_type: glib::types::Type,
51 expression: Option<impl AsRef<Expression>>,
52 property_name: &str,
53 ) -> PropertyExpression {
54 assert_initialized_main_thread!();
55 unsafe {
56 from_glib_full(ffi::gtk_property_expression_new(
57 this_type.into_glib(),
58 expression
59 .map(|p| p.as_ref().clone().upcast())
60 .into_glib_ptr(),
61 property_name.to_glib_none().0,
62 ))
63 }
64 }
65
66 /// Creates an expression that looks up a property.
67 ///
68 /// The object to use is found by evaluating the `expression`,
69 /// or using the `this` argument when `expression` is `NULL`.
70 ///
71 /// If the resulting object conforms to `this_type`, its
72 /// property specified by `pspec` will be queried.
73 /// Otherwise, this expression's evaluation will fail.
74 /// ## `expression`
75 /// Expression to
76 /// evaluate to get the object to query or `NULL` to
77 /// query the `this` object
78 /// ## `pspec`
79 /// the `GParamSpec` for the property to query
80 ///
81 /// # Returns
82 ///
83 /// a new [`Expression`][crate::Expression]
84 #[doc(alias = "gtk_property_expression_new_for_pspec")]
85 #[doc(alias = "new_for_pspec")]
86 pub fn for_pspec(
87 expression: Option<impl AsRef<Expression>>,
88 pspec: impl AsRef<glib::ParamSpec>,
89 ) -> PropertyExpression {
90 assert_initialized_main_thread!();
91 unsafe {
92 from_glib_full(ffi::gtk_property_expression_new_for_pspec(
93 expression
94 .map(|p| p.as_ref().clone().upcast())
95 .into_glib_ptr(),
96 pspec.as_ref().to_glib_none().0,
97 ))
98 }
99 }
100
101 /// Gets the expression specifying the object of
102 /// a property expression.
103 ///
104 /// # Returns
105 ///
106 /// the object expression
107 #[doc(alias = "gtk_property_expression_get_expression")]
108 #[doc(alias = "get_expression")]
109 pub fn expression(&self) -> Option<Expression> {
110 unsafe {
111 from_glib_none(ffi::gtk_property_expression_get_expression(
112 self.to_glib_none().0,
113 ))
114 }
115 }
116
117 /// Gets the `GParamSpec` specifying the property of
118 /// a property expression.
119 ///
120 /// # Returns
121 ///
122 /// the `GParamSpec` for the property
123 #[doc(alias = "gtk_property_expression_get_pspec")]
124 #[doc(alias = "get_pspec")]
125 pub fn pspec(&self) -> glib::ParamSpec {
126 unsafe {
127 from_glib_none(ffi::gtk_property_expression_get_pspec(
128 self.to_glib_none().0,
129 ))
130 }
131 }
132}