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::{ConstraintAttribute, ConstraintRelation, ConstraintTarget, ffi};
6use glib::{prelude::*, translate::*};
7
8glib::wrapper! {
9 /// multiplier + constant
10 /// ```text
11 ///
12 /// Each [`Constraint`][crate::Constraint] is part of a system that will be solved by a
13 /// [`ConstraintLayout`][crate::ConstraintLayout] in order to allocate and position each
14 /// child widget or guide.
15 ///
16 /// The source and target, as well as their attributes, of a [`Constraint`][crate::Constraint]
17 /// instance are immutable after creation.
18 ///
19 /// ## Properties
20 ///
21 ///
22 /// #### `constant`
23 /// The constant value to be added to the [`source-attribute`][struct@crate::Constraint#source-attribute].
24 ///
25 /// Readable | Writable | Construct Only
26 ///
27 ///
28 /// #### `multiplier`
29 /// The multiplication factor to be applied to
30 /// the [`source-attribute`][struct@crate::Constraint#source-attribute].
31 ///
32 /// Readable | Writable | Construct Only
33 ///
34 ///
35 /// #### `relation`
36 /// The order relation between the terms of the constraint.
37 ///
38 /// Readable | Writable | Construct Only
39 ///
40 ///
41 /// #### `source`
42 /// The source of the constraint.
43 ///
44 /// The constraint will set the [`target-attribute`][struct@crate::Constraint#target-attribute]
45 /// property of the target using the [`source-attribute`][struct@crate::Constraint#source-attribute]
46 /// property of the source.
47 ///
48 /// Readable | Writable | Construct Only
49 ///
50 ///
51 /// #### `source-attribute`
52 /// The attribute of the [`source`][struct@crate::Constraint#source] read by the
53 /// constraint.
54 ///
55 /// Readable | Writable | Construct Only
56 ///
57 ///
58 /// #### `strength`
59 /// The strength of the constraint.
60 ///
61 /// The strength can be expressed either using one of the symbolic values
62 /// of the [`ConstraintStrength`][crate::ConstraintStrength] enumeration, or any positive integer
63 /// value.
64 ///
65 /// Readable | Writable | Construct Only
66 ///
67 ///
68 /// #### `target`
69 /// The target of the constraint.
70 ///
71 /// The constraint will set the [`target-attribute`][struct@crate::Constraint#target-attribute]
72 /// property of the target using the [`source-attribute`][struct@crate::Constraint#source-attribute]
73 /// property of the source widget.
74 ///
75 /// Readable | Writable | Construct Only
76 ///
77 ///
78 /// #### `target-attribute`
79 /// The attribute of the [`target`][struct@crate::Constraint#target] set by the constraint.
80 ///
81 /// Readable | Writable | Construct Only
82 ///
83 /// # Implements
84 ///
85 /// [`trait@glib::ObjectExt`]
86 #[doc(alias = "GtkConstraint")]
87 pub struct Constraint(Object<ffi::GtkConstraint, ffi::GtkConstraintClass>);
88
89 match fn {
90 type_ => || ffi::gtk_constraint_get_type(),
91 }
92}
93
94impl Constraint {
95 /// Creates a new constraint representing a relation between a layout
96 /// attribute on a source and a layout attribute on a target.
97 /// ## `target`
98 /// the target of the constraint
99 /// ## `target_attribute`
100 /// the attribute of `target` to be set
101 /// ## `relation`
102 /// the relation equivalence between `target_attribute` and `source_attribute`
103 /// ## `source`
104 /// the source of the constraint
105 /// ## `source_attribute`
106 /// the attribute of `source` to be read
107 /// ## `multiplier`
108 /// a multiplication factor to be applied to `source_attribute`
109 /// ## `constant`
110 /// a constant factor to be added to `source_attribute`
111 /// ## `strength`
112 /// the strength of the constraint
113 ///
114 /// # Returns
115 ///
116 /// the newly created constraint
117 #[doc(alias = "gtk_constraint_new")]
118 pub fn new(
119 target: Option<&impl IsA<ConstraintTarget>>,
120 target_attribute: ConstraintAttribute,
121 relation: ConstraintRelation,
122 source: Option<&impl IsA<ConstraintTarget>>,
123 source_attribute: ConstraintAttribute,
124 multiplier: f64,
125 constant: f64,
126 strength: i32,
127 ) -> Constraint {
128 assert_initialized_main_thread!();
129 unsafe {
130 from_glib_full(ffi::gtk_constraint_new(
131 target.map(|p| p.as_ref()).to_glib_none().0,
132 target_attribute.into_glib(),
133 relation.into_glib(),
134 source.map(|p| p.as_ref()).to_glib_none().0,
135 source_attribute.into_glib(),
136 multiplier,
137 constant,
138 strength,
139 ))
140 }
141 }
142
143 /// Creates a new constraint representing a relation between a layout
144 /// attribute on a target and a constant value.
145 /// ## `target`
146 /// a the target of the constraint
147 /// ## `target_attribute`
148 /// the attribute of `target` to be set
149 /// ## `relation`
150 /// the relation equivalence between `target_attribute` and `constant`
151 /// ## `constant`
152 /// a constant factor to be set on `target_attribute`
153 /// ## `strength`
154 /// the strength of the constraint
155 ///
156 /// # Returns
157 ///
158 /// the newly created constraint
159 #[doc(alias = "gtk_constraint_new_constant")]
160 pub fn new_constant(
161 target: Option<&impl IsA<ConstraintTarget>>,
162 target_attribute: ConstraintAttribute,
163 relation: ConstraintRelation,
164 constant: f64,
165 strength: i32,
166 ) -> Constraint {
167 assert_initialized_main_thread!();
168 unsafe {
169 from_glib_full(ffi::gtk_constraint_new_constant(
170 target.map(|p| p.as_ref()).to_glib_none().0,
171 target_attribute.into_glib(),
172 relation.into_glib(),
173 constant,
174 strength,
175 ))
176 }
177 }
178
179 // rustdoc-stripper-ignore-next
180 /// Creates a new builder-pattern struct instance to construct [`Constraint`] objects.
181 ///
182 /// This method returns an instance of [`ConstraintBuilder`](crate::builders::ConstraintBuilder) which can be used to create [`Constraint`] objects.
183 pub fn builder() -> ConstraintBuilder {
184 ConstraintBuilder::new()
185 }
186
187 /// Retrieves the constant factor added to the source attributes' value.
188 ///
189 /// # Returns
190 ///
191 /// a constant factor
192 #[doc(alias = "gtk_constraint_get_constant")]
193 #[doc(alias = "get_constant")]
194 pub fn constant(&self) -> f64 {
195 unsafe { ffi::gtk_constraint_get_constant(self.to_glib_none().0) }
196 }
197
198 /// Retrieves the multiplication factor applied to the source
199 /// attribute's value.
200 ///
201 /// # Returns
202 ///
203 /// a multiplication factor
204 #[doc(alias = "gtk_constraint_get_multiplier")]
205 #[doc(alias = "get_multiplier")]
206 pub fn multiplier(&self) -> f64 {
207 unsafe { ffi::gtk_constraint_get_multiplier(self.to_glib_none().0) }
208 }
209
210 /// The order relation between the terms of the constraint.
211 ///
212 /// # Returns
213 ///
214 /// a relation type
215 #[doc(alias = "gtk_constraint_get_relation")]
216 #[doc(alias = "get_relation")]
217 pub fn relation(&self) -> ConstraintRelation {
218 unsafe { from_glib(ffi::gtk_constraint_get_relation(self.to_glib_none().0)) }
219 }
220
221 /// Retrieves the [`ConstraintTarget`][crate::ConstraintTarget] used as the source for the
222 /// constraint.
223 ///
224 /// If the source is set to `NULL` at creation, the constraint will use
225 /// the widget using the [`ConstraintLayout`][crate::ConstraintLayout] as the source.
226 ///
227 /// # Returns
228 ///
229 /// the source of the constraint
230 #[doc(alias = "gtk_constraint_get_source")]
231 #[doc(alias = "get_source")]
232 pub fn source(&self) -> Option<ConstraintTarget> {
233 unsafe { from_glib_none(ffi::gtk_constraint_get_source(self.to_glib_none().0)) }
234 }
235
236 /// Retrieves the attribute of the source to be read by the constraint.
237 ///
238 /// # Returns
239 ///
240 /// the source's attribute
241 #[doc(alias = "gtk_constraint_get_source_attribute")]
242 #[doc(alias = "get_source_attribute")]
243 #[doc(alias = "source-attribute")]
244 pub fn source_attribute(&self) -> ConstraintAttribute {
245 unsafe {
246 from_glib(ffi::gtk_constraint_get_source_attribute(
247 self.to_glib_none().0,
248 ))
249 }
250 }
251
252 /// Retrieves the strength of the constraint.
253 ///
254 /// # Returns
255 ///
256 /// the strength value
257 #[doc(alias = "gtk_constraint_get_strength")]
258 #[doc(alias = "get_strength")]
259 pub fn strength(&self) -> i32 {
260 unsafe { ffi::gtk_constraint_get_strength(self.to_glib_none().0) }
261 }
262
263 /// Retrieves the [`ConstraintTarget`][crate::ConstraintTarget] used as the target for
264 /// the constraint.
265 ///
266 /// If the targe is set to `NULL` at creation, the constraint will use
267 /// the widget using the [`ConstraintLayout`][crate::ConstraintLayout] as the target.
268 ///
269 /// # Returns
270 ///
271 /// a [`ConstraintTarget`][crate::ConstraintTarget]
272 #[doc(alias = "gtk_constraint_get_target")]
273 #[doc(alias = "get_target")]
274 pub fn target(&self) -> Option<ConstraintTarget> {
275 unsafe { from_glib_none(ffi::gtk_constraint_get_target(self.to_glib_none().0)) }
276 }
277
278 /// Retrieves the attribute of the target to be set by the constraint.
279 ///
280 /// # Returns
281 ///
282 /// the target's attribute
283 #[doc(alias = "gtk_constraint_get_target_attribute")]
284 #[doc(alias = "get_target_attribute")]
285 #[doc(alias = "target-attribute")]
286 pub fn target_attribute(&self) -> ConstraintAttribute {
287 unsafe {
288 from_glib(ffi::gtk_constraint_get_target_attribute(
289 self.to_glib_none().0,
290 ))
291 }
292 }
293
294 /// Checks whether the constraint is attached to a [`ConstraintLayout`][crate::ConstraintLayout],
295 /// and it is contributing to the layout.
296 ///
297 /// # Returns
298 ///
299 /// `TRUE` if the constraint is attached
300 #[doc(alias = "gtk_constraint_is_attached")]
301 pub fn is_attached(&self) -> bool {
302 unsafe { from_glib(ffi::gtk_constraint_is_attached(self.to_glib_none().0)) }
303 }
304
305 /// Checks whether the constraint describes a relation between an attribute
306 /// on the [`target`][struct@crate::Constraint#target] and a constant value.
307 ///
308 /// # Returns
309 ///
310 /// `TRUE` if the constraint is a constant relation
311 #[doc(alias = "gtk_constraint_is_constant")]
312 pub fn is_constant(&self) -> bool {
313 unsafe { from_glib(ffi::gtk_constraint_is_constant(self.to_glib_none().0)) }
314 }
315
316 /// Checks whether the constraint is a required relation for solving the
317 /// constraint layout.
318 ///
319 /// # Returns
320 ///
321 /// [`true`] if the constraint is required
322 #[doc(alias = "gtk_constraint_is_required")]
323 pub fn is_required(&self) -> bool {
324 unsafe { from_glib(ffi::gtk_constraint_is_required(self.to_glib_none().0)) }
325 }
326}
327
328impl Default for Constraint {
329 fn default() -> Self {
330 glib::object::Object::new::<Self>()
331 }
332}
333
334// rustdoc-stripper-ignore-next
335/// A [builder-pattern] type to construct [`Constraint`] objects.
336///
337/// [builder-pattern]: https://doc.rust-lang.org/1.0.0/style/ownership/builders.html
338#[must_use = "The builder must be built to be used"]
339pub struct ConstraintBuilder {
340 builder: glib::object::ObjectBuilder<'static, Constraint>,
341}
342
343impl ConstraintBuilder {
344 fn new() -> Self {
345 Self {
346 builder: glib::object::Object::builder(),
347 }
348 }
349
350 /// The constant value to be added to the [`source-attribute`][struct@crate::Constraint#source-attribute].
351 pub fn constant(self, constant: f64) -> Self {
352 Self {
353 builder: self.builder.property("constant", constant),
354 }
355 }
356
357 /// The multiplication factor to be applied to
358 /// the [`source-attribute`][struct@crate::Constraint#source-attribute].
359 pub fn multiplier(self, multiplier: f64) -> Self {
360 Self {
361 builder: self.builder.property("multiplier", multiplier),
362 }
363 }
364
365 /// The order relation between the terms of the constraint.
366 pub fn relation(self, relation: ConstraintRelation) -> Self {
367 Self {
368 builder: self.builder.property("relation", relation),
369 }
370 }
371
372 /// The source of the constraint.
373 ///
374 /// The constraint will set the [`target-attribute`][struct@crate::Constraint#target-attribute]
375 /// property of the target using the [`source-attribute`][struct@crate::Constraint#source-attribute]
376 /// property of the source.
377 pub fn source(self, source: &impl IsA<ConstraintTarget>) -> Self {
378 Self {
379 builder: self.builder.property("source", source.clone().upcast()),
380 }
381 }
382
383 /// The attribute of the [`source`][struct@crate::Constraint#source] read by the
384 /// constraint.
385 pub fn source_attribute(self, source_attribute: ConstraintAttribute) -> Self {
386 Self {
387 builder: self.builder.property("source-attribute", source_attribute),
388 }
389 }
390
391 /// The strength of the constraint.
392 ///
393 /// The strength can be expressed either using one of the symbolic values
394 /// of the [`ConstraintStrength`][crate::ConstraintStrength] enumeration, or any positive integer
395 /// value.
396 pub fn strength(self, strength: i32) -> Self {
397 Self {
398 builder: self.builder.property("strength", strength),
399 }
400 }
401
402 /// The target of the constraint.
403 ///
404 /// The constraint will set the [`target-attribute`][struct@crate::Constraint#target-attribute]
405 /// property of the target using the [`source-attribute`][struct@crate::Constraint#source-attribute]
406 /// property of the source widget.
407 pub fn target(self, target: &impl IsA<ConstraintTarget>) -> Self {
408 Self {
409 builder: self.builder.property("target", target.clone().upcast()),
410 }
411 }
412
413 /// The attribute of the [`target`][struct@crate::Constraint#target] set by the constraint.
414 pub fn target_attribute(self, target_attribute: ConstraintAttribute) -> Self {
415 Self {
416 builder: self.builder.property("target-attribute", target_attribute),
417 }
418 }
419
420 // rustdoc-stripper-ignore-next
421 /// Build the [`Constraint`].
422 #[must_use = "Building the object from the builder is usually expensive and is not expected to have side effects"]
423 pub fn build(self) -> Constraint {
424 assert_initialized_main_thread!();
425 self.builder.build()
426 }
427}