[go: up one dir, main page]

gtk4/auto/
constraint.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, ConstraintAttribute, ConstraintRelation, ConstraintTarget};
6use glib::{prelude::*, translate::*};
7
8glib::wrapper! {
9    #[doc(alias = "GtkConstraint")]
10    pub struct Constraint(Object<ffi::GtkConstraint, ffi::GtkConstraintClass>);
11
12    match fn {
13        type_ => || ffi::gtk_constraint_get_type(),
14    }
15}
16
17impl Constraint {
18    #[doc(alias = "gtk_constraint_new")]
19    pub fn new(
20        target: Option<&impl IsA<ConstraintTarget>>,
21        target_attribute: ConstraintAttribute,
22        relation: ConstraintRelation,
23        source: Option<&impl IsA<ConstraintTarget>>,
24        source_attribute: ConstraintAttribute,
25        multiplier: f64,
26        constant: f64,
27        strength: i32,
28    ) -> Constraint {
29        assert_initialized_main_thread!();
30        unsafe {
31            from_glib_full(ffi::gtk_constraint_new(
32                target.map(|p| p.as_ref()).to_glib_none().0,
33                target_attribute.into_glib(),
34                relation.into_glib(),
35                source.map(|p| p.as_ref()).to_glib_none().0,
36                source_attribute.into_glib(),
37                multiplier,
38                constant,
39                strength,
40            ))
41        }
42    }
43
44    #[doc(alias = "gtk_constraint_new_constant")]
45    pub fn new_constant(
46        target: Option<&impl IsA<ConstraintTarget>>,
47        target_attribute: ConstraintAttribute,
48        relation: ConstraintRelation,
49        constant: f64,
50        strength: i32,
51    ) -> Constraint {
52        assert_initialized_main_thread!();
53        unsafe {
54            from_glib_full(ffi::gtk_constraint_new_constant(
55                target.map(|p| p.as_ref()).to_glib_none().0,
56                target_attribute.into_glib(),
57                relation.into_glib(),
58                constant,
59                strength,
60            ))
61        }
62    }
63
64    // rustdoc-stripper-ignore-next
65    /// Creates a new builder-pattern struct instance to construct [`Constraint`] objects.
66    ///
67    /// This method returns an instance of [`ConstraintBuilder`](crate::builders::ConstraintBuilder) which can be used to create [`Constraint`] objects.
68    pub fn builder() -> ConstraintBuilder {
69        ConstraintBuilder::new()
70    }
71
72    #[doc(alias = "gtk_constraint_get_constant")]
73    #[doc(alias = "get_constant")]
74    pub fn constant(&self) -> f64 {
75        unsafe { ffi::gtk_constraint_get_constant(self.to_glib_none().0) }
76    }
77
78    #[doc(alias = "gtk_constraint_get_multiplier")]
79    #[doc(alias = "get_multiplier")]
80    pub fn multiplier(&self) -> f64 {
81        unsafe { ffi::gtk_constraint_get_multiplier(self.to_glib_none().0) }
82    }
83
84    #[doc(alias = "gtk_constraint_get_relation")]
85    #[doc(alias = "get_relation")]
86    pub fn relation(&self) -> ConstraintRelation {
87        unsafe { from_glib(ffi::gtk_constraint_get_relation(self.to_glib_none().0)) }
88    }
89
90    #[doc(alias = "gtk_constraint_get_source")]
91    #[doc(alias = "get_source")]
92    pub fn source(&self) -> Option<ConstraintTarget> {
93        unsafe { from_glib_none(ffi::gtk_constraint_get_source(self.to_glib_none().0)) }
94    }
95
96    #[doc(alias = "gtk_constraint_get_source_attribute")]
97    #[doc(alias = "get_source_attribute")]
98    #[doc(alias = "source-attribute")]
99    pub fn source_attribute(&self) -> ConstraintAttribute {
100        unsafe {
101            from_glib(ffi::gtk_constraint_get_source_attribute(
102                self.to_glib_none().0,
103            ))
104        }
105    }
106
107    #[doc(alias = "gtk_constraint_get_strength")]
108    #[doc(alias = "get_strength")]
109    pub fn strength(&self) -> i32 {
110        unsafe { ffi::gtk_constraint_get_strength(self.to_glib_none().0) }
111    }
112
113    #[doc(alias = "gtk_constraint_get_target")]
114    #[doc(alias = "get_target")]
115    pub fn target(&self) -> Option<ConstraintTarget> {
116        unsafe { from_glib_none(ffi::gtk_constraint_get_target(self.to_glib_none().0)) }
117    }
118
119    #[doc(alias = "gtk_constraint_get_target_attribute")]
120    #[doc(alias = "get_target_attribute")]
121    #[doc(alias = "target-attribute")]
122    pub fn target_attribute(&self) -> ConstraintAttribute {
123        unsafe {
124            from_glib(ffi::gtk_constraint_get_target_attribute(
125                self.to_glib_none().0,
126            ))
127        }
128    }
129
130    #[doc(alias = "gtk_constraint_is_attached")]
131    pub fn is_attached(&self) -> bool {
132        unsafe { from_glib(ffi::gtk_constraint_is_attached(self.to_glib_none().0)) }
133    }
134
135    #[doc(alias = "gtk_constraint_is_constant")]
136    pub fn is_constant(&self) -> bool {
137        unsafe { from_glib(ffi::gtk_constraint_is_constant(self.to_glib_none().0)) }
138    }
139
140    #[doc(alias = "gtk_constraint_is_required")]
141    pub fn is_required(&self) -> bool {
142        unsafe { from_glib(ffi::gtk_constraint_is_required(self.to_glib_none().0)) }
143    }
144}
145
146impl Default for Constraint {
147    fn default() -> Self {
148        glib::object::Object::new::<Self>()
149    }
150}
151
152// rustdoc-stripper-ignore-next
153/// A [builder-pattern] type to construct [`Constraint`] objects.
154///
155/// [builder-pattern]: https://doc.rust-lang.org/1.0.0/style/ownership/builders.html
156#[must_use = "The builder must be built to be used"]
157pub struct ConstraintBuilder {
158    builder: glib::object::ObjectBuilder<'static, Constraint>,
159}
160
161impl ConstraintBuilder {
162    fn new() -> Self {
163        Self {
164            builder: glib::object::Object::builder(),
165        }
166    }
167
168    pub fn constant(self, constant: f64) -> Self {
169        Self {
170            builder: self.builder.property("constant", constant),
171        }
172    }
173
174    pub fn multiplier(self, multiplier: f64) -> Self {
175        Self {
176            builder: self.builder.property("multiplier", multiplier),
177        }
178    }
179
180    pub fn relation(self, relation: ConstraintRelation) -> Self {
181        Self {
182            builder: self.builder.property("relation", relation),
183        }
184    }
185
186    pub fn source(self, source: &impl IsA<ConstraintTarget>) -> Self {
187        Self {
188            builder: self.builder.property("source", source.clone().upcast()),
189        }
190    }
191
192    pub fn source_attribute(self, source_attribute: ConstraintAttribute) -> Self {
193        Self {
194            builder: self.builder.property("source-attribute", source_attribute),
195        }
196    }
197
198    pub fn strength(self, strength: i32) -> Self {
199        Self {
200            builder: self.builder.property("strength", strength),
201        }
202    }
203
204    pub fn target(self, target: &impl IsA<ConstraintTarget>) -> Self {
205        Self {
206            builder: self.builder.property("target", target.clone().upcast()),
207        }
208    }
209
210    pub fn target_attribute(self, target_attribute: ConstraintAttribute) -> Self {
211        Self {
212            builder: self.builder.property("target-attribute", target_attribute),
213        }
214    }
215
216    // rustdoc-stripper-ignore-next
217    /// Build the [`Constraint`].
218    #[must_use = "Building the object from the builder is usually expensive and is not expected to have side effects"]
219    pub fn build(self) -> Constraint {
220        assert_initialized_main_thread!();
221        self.builder.build()
222    }
223}