gtk4/auto/
constraint_guide.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, ConstraintStrength, ConstraintTarget};
6use glib::{
7    prelude::*,
8    signal::{connect_raw, SignalHandlerId},
9    translate::*,
10};
11use std::boxed::Box as Box_;
12
13glib::wrapper! {
14    /// An invisible layout element in a [`ConstraintLayout`][crate::ConstraintLayout].
15    ///
16    /// The [`ConstraintLayout`][crate::ConstraintLayout] treats guides like widgets. They
17    /// can be used as the source or target of a [`Constraint`][crate::Constraint].
18    ///
19    /// Guides have a minimum, maximum and natural size. Depending
20    /// on the constraints that are applied, they can act like a
21    /// guideline that widgets can be aligned to, or like *flexible
22    /// space*.
23    ///
24    /// Unlike a [`Widget`][crate::Widget], a [`ConstraintGuide`][crate::ConstraintGuide] will not be drawn.
25    ///
26    /// ## Properties
27    ///
28    ///
29    /// #### `max-height`
30    ///  The maximum height of the guide.
31    ///
32    /// Readable | Writeable
33    ///
34    ///
35    /// #### `max-width`
36    ///  The maximum width of the guide.
37    ///
38    /// Readable | Writeable
39    ///
40    ///
41    /// #### `min-height`
42    ///  The minimum height of the guide.
43    ///
44    /// Readable | Writeable
45    ///
46    ///
47    /// #### `min-width`
48    ///  The minimum width of the guide.
49    ///
50    /// Readable | Writeable
51    ///
52    ///
53    /// #### `name`
54    ///  A name that identifies the [`ConstraintGuide`][crate::ConstraintGuide], for debugging.
55    ///
56    /// Readable | Writeable
57    ///
58    ///
59    /// #### `nat-height`
60    ///  The preferred, or natural, height of the guide.
61    ///
62    /// Readable | Writeable
63    ///
64    ///
65    /// #### `nat-width`
66    ///  The preferred, or natural, width of the guide.
67    ///
68    /// Readable | Writeable
69    ///
70    ///
71    /// #### `strength`
72    ///  The [`ConstraintStrength`][crate::ConstraintStrength] to be used for the constraint on
73    /// the natural size of the guide.
74    ///
75    /// Readable | Writeable
76    ///
77    /// # Implements
78    ///
79    /// [`trait@glib::ObjectExt`], [`ConstraintTargetExt`][trait@crate::prelude::ConstraintTargetExt]
80    #[doc(alias = "GtkConstraintGuide")]
81    pub struct ConstraintGuide(Object<ffi::GtkConstraintGuide, ffi::GtkConstraintGuideClass>) @implements ConstraintTarget;
82
83    match fn {
84        type_ => || ffi::gtk_constraint_guide_get_type(),
85    }
86}
87
88impl ConstraintGuide {
89    /// Creates a new [`ConstraintGuide`][crate::ConstraintGuide] object.
90    ///
91    /// # Returns
92    ///
93    /// a new [`ConstraintGuide`][crate::ConstraintGuide] object.
94    #[doc(alias = "gtk_constraint_guide_new")]
95    pub fn new() -> ConstraintGuide {
96        assert_initialized_main_thread!();
97        unsafe { from_glib_full(ffi::gtk_constraint_guide_new()) }
98    }
99
100    // rustdoc-stripper-ignore-next
101    /// Creates a new builder-pattern struct instance to construct [`ConstraintGuide`] objects.
102    ///
103    /// This method returns an instance of [`ConstraintGuideBuilder`](crate::builders::ConstraintGuideBuilder) which can be used to create [`ConstraintGuide`] objects.
104    pub fn builder() -> ConstraintGuideBuilder {
105        ConstraintGuideBuilder::new()
106    }
107
108    /// Retrieves the name set using gtk_constraint_guide_set_name().
109    ///
110    /// # Returns
111    ///
112    /// the name of the guide
113    #[doc(alias = "gtk_constraint_guide_get_name")]
114    #[doc(alias = "get_name")]
115    pub fn name(&self) -> Option<glib::GString> {
116        unsafe { from_glib_none(ffi::gtk_constraint_guide_get_name(self.to_glib_none().0)) }
117    }
118
119    /// Retrieves the strength set using gtk_constraint_guide_set_strength().
120    ///
121    /// # Returns
122    ///
123    /// the strength of the constraint on the natural size
124    #[doc(alias = "gtk_constraint_guide_get_strength")]
125    #[doc(alias = "get_strength")]
126    pub fn strength(&self) -> ConstraintStrength {
127        unsafe {
128            from_glib(ffi::gtk_constraint_guide_get_strength(
129                self.to_glib_none().0,
130            ))
131        }
132    }
133
134    /// Sets the maximum size of @self.
135    ///
136    /// If @self is attached to a [`ConstraintLayout`][crate::ConstraintLayout],
137    /// the constraints will be updated to reflect the new size.
138    /// ## `width`
139    /// the new maximum width, or -1 to not change it
140    /// ## `height`
141    /// the new maximum height, or -1 to not change it
142    #[doc(alias = "gtk_constraint_guide_set_max_size")]
143    pub fn set_max_size(&self, width: i32, height: i32) {
144        unsafe {
145            ffi::gtk_constraint_guide_set_max_size(self.to_glib_none().0, width, height);
146        }
147    }
148
149    /// Sets the minimum size of @self.
150    ///
151    /// If @self is attached to a [`ConstraintLayout`][crate::ConstraintLayout],
152    /// the constraints will be updated to reflect the new size.
153    /// ## `width`
154    /// the new minimum width, or -1 to not change it
155    /// ## `height`
156    /// the new minimum height, or -1 to not change it
157    #[doc(alias = "gtk_constraint_guide_set_min_size")]
158    pub fn set_min_size(&self, width: i32, height: i32) {
159        unsafe {
160            ffi::gtk_constraint_guide_set_min_size(self.to_glib_none().0, width, height);
161        }
162    }
163
164    /// Sets a name for the given [`ConstraintGuide`][crate::ConstraintGuide].
165    ///
166    /// The name is useful for debugging purposes.
167    /// ## `name`
168    /// a name for the @self
169    #[doc(alias = "gtk_constraint_guide_set_name")]
170    #[doc(alias = "name")]
171    pub fn set_name(&self, name: Option<&str>) {
172        unsafe {
173            ffi::gtk_constraint_guide_set_name(self.to_glib_none().0, name.to_glib_none().0);
174        }
175    }
176
177    /// Sets the natural size of @self.
178    ///
179    /// If @self is attached to a [`ConstraintLayout`][crate::ConstraintLayout],
180    /// the constraints will be updated to reflect the new size.
181    /// ## `width`
182    /// the new natural width, or -1 to not change it
183    /// ## `height`
184    /// the new natural height, or -1 to not change it
185    #[doc(alias = "gtk_constraint_guide_set_nat_size")]
186    pub fn set_nat_size(&self, width: i32, height: i32) {
187        unsafe {
188            ffi::gtk_constraint_guide_set_nat_size(self.to_glib_none().0, width, height);
189        }
190    }
191
192    /// Sets the strength of the constraint on the natural size of the
193    /// given [`ConstraintGuide`][crate::ConstraintGuide].
194    /// ## `strength`
195    /// the strength of the constraint
196    #[doc(alias = "gtk_constraint_guide_set_strength")]
197    #[doc(alias = "strength")]
198    pub fn set_strength(&self, strength: ConstraintStrength) {
199        unsafe {
200            ffi::gtk_constraint_guide_set_strength(self.to_glib_none().0, strength.into_glib());
201        }
202    }
203
204    /// The maximum height of the guide.
205    #[doc(alias = "max-height")]
206    pub fn max_height(&self) -> i32 {
207        ObjectExt::property(self, "max-height")
208    }
209
210    /// The maximum height of the guide.
211    #[doc(alias = "max-height")]
212    pub fn set_max_height(&self, max_height: i32) {
213        ObjectExt::set_property(self, "max-height", max_height)
214    }
215
216    /// The maximum width of the guide.
217    #[doc(alias = "max-width")]
218    pub fn max_width(&self) -> i32 {
219        ObjectExt::property(self, "max-width")
220    }
221
222    /// The maximum width of the guide.
223    #[doc(alias = "max-width")]
224    pub fn set_max_width(&self, max_width: i32) {
225        ObjectExt::set_property(self, "max-width", max_width)
226    }
227
228    /// The minimum height of the guide.
229    #[doc(alias = "min-height")]
230    pub fn min_height(&self) -> i32 {
231        ObjectExt::property(self, "min-height")
232    }
233
234    /// The minimum height of the guide.
235    #[doc(alias = "min-height")]
236    pub fn set_min_height(&self, min_height: i32) {
237        ObjectExt::set_property(self, "min-height", min_height)
238    }
239
240    /// The minimum width of the guide.
241    #[doc(alias = "min-width")]
242    pub fn min_width(&self) -> i32 {
243        ObjectExt::property(self, "min-width")
244    }
245
246    /// The minimum width of the guide.
247    #[doc(alias = "min-width")]
248    pub fn set_min_width(&self, min_width: i32) {
249        ObjectExt::set_property(self, "min-width", min_width)
250    }
251
252    /// The preferred, or natural, height of the guide.
253    #[doc(alias = "nat-height")]
254    pub fn nat_height(&self) -> i32 {
255        ObjectExt::property(self, "nat-height")
256    }
257
258    /// The preferred, or natural, height of the guide.
259    #[doc(alias = "nat-height")]
260    pub fn set_nat_height(&self, nat_height: i32) {
261        ObjectExt::set_property(self, "nat-height", nat_height)
262    }
263
264    /// The preferred, or natural, width of the guide.
265    #[doc(alias = "nat-width")]
266    pub fn nat_width(&self) -> i32 {
267        ObjectExt::property(self, "nat-width")
268    }
269
270    /// The preferred, or natural, width of the guide.
271    #[doc(alias = "nat-width")]
272    pub fn set_nat_width(&self, nat_width: i32) {
273        ObjectExt::set_property(self, "nat-width", nat_width)
274    }
275
276    #[doc(alias = "max-height")]
277    pub fn connect_max_height_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
278        unsafe extern "C" fn notify_max_height_trampoline<F: Fn(&ConstraintGuide) + 'static>(
279            this: *mut ffi::GtkConstraintGuide,
280            _param_spec: glib::ffi::gpointer,
281            f: glib::ffi::gpointer,
282        ) {
283            let f: &F = &*(f as *const F);
284            f(&from_glib_borrow(this))
285        }
286        unsafe {
287            let f: Box_<F> = Box_::new(f);
288            connect_raw(
289                self.as_ptr() as *mut _,
290                c"notify::max-height".as_ptr() as *const _,
291                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
292                    notify_max_height_trampoline::<F> as *const (),
293                )),
294                Box_::into_raw(f),
295            )
296        }
297    }
298
299    #[doc(alias = "max-width")]
300    pub fn connect_max_width_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
301        unsafe extern "C" fn notify_max_width_trampoline<F: Fn(&ConstraintGuide) + 'static>(
302            this: *mut ffi::GtkConstraintGuide,
303            _param_spec: glib::ffi::gpointer,
304            f: glib::ffi::gpointer,
305        ) {
306            let f: &F = &*(f as *const F);
307            f(&from_glib_borrow(this))
308        }
309        unsafe {
310            let f: Box_<F> = Box_::new(f);
311            connect_raw(
312                self.as_ptr() as *mut _,
313                c"notify::max-width".as_ptr() as *const _,
314                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
315                    notify_max_width_trampoline::<F> as *const (),
316                )),
317                Box_::into_raw(f),
318            )
319        }
320    }
321
322    #[doc(alias = "min-height")]
323    pub fn connect_min_height_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
324        unsafe extern "C" fn notify_min_height_trampoline<F: Fn(&ConstraintGuide) + 'static>(
325            this: *mut ffi::GtkConstraintGuide,
326            _param_spec: glib::ffi::gpointer,
327            f: glib::ffi::gpointer,
328        ) {
329            let f: &F = &*(f as *const F);
330            f(&from_glib_borrow(this))
331        }
332        unsafe {
333            let f: Box_<F> = Box_::new(f);
334            connect_raw(
335                self.as_ptr() as *mut _,
336                c"notify::min-height".as_ptr() as *const _,
337                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
338                    notify_min_height_trampoline::<F> as *const (),
339                )),
340                Box_::into_raw(f),
341            )
342        }
343    }
344
345    #[doc(alias = "min-width")]
346    pub fn connect_min_width_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
347        unsafe extern "C" fn notify_min_width_trampoline<F: Fn(&ConstraintGuide) + 'static>(
348            this: *mut ffi::GtkConstraintGuide,
349            _param_spec: glib::ffi::gpointer,
350            f: glib::ffi::gpointer,
351        ) {
352            let f: &F = &*(f as *const F);
353            f(&from_glib_borrow(this))
354        }
355        unsafe {
356            let f: Box_<F> = Box_::new(f);
357            connect_raw(
358                self.as_ptr() as *mut _,
359                c"notify::min-width".as_ptr() as *const _,
360                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
361                    notify_min_width_trampoline::<F> as *const (),
362                )),
363                Box_::into_raw(f),
364            )
365        }
366    }
367
368    #[doc(alias = "name")]
369    pub fn connect_name_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
370        unsafe extern "C" fn notify_name_trampoline<F: Fn(&ConstraintGuide) + 'static>(
371            this: *mut ffi::GtkConstraintGuide,
372            _param_spec: glib::ffi::gpointer,
373            f: glib::ffi::gpointer,
374        ) {
375            let f: &F = &*(f as *const F);
376            f(&from_glib_borrow(this))
377        }
378        unsafe {
379            let f: Box_<F> = Box_::new(f);
380            connect_raw(
381                self.as_ptr() as *mut _,
382                c"notify::name".as_ptr() as *const _,
383                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
384                    notify_name_trampoline::<F> as *const (),
385                )),
386                Box_::into_raw(f),
387            )
388        }
389    }
390
391    #[doc(alias = "nat-height")]
392    pub fn connect_nat_height_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
393        unsafe extern "C" fn notify_nat_height_trampoline<F: Fn(&ConstraintGuide) + 'static>(
394            this: *mut ffi::GtkConstraintGuide,
395            _param_spec: glib::ffi::gpointer,
396            f: glib::ffi::gpointer,
397        ) {
398            let f: &F = &*(f as *const F);
399            f(&from_glib_borrow(this))
400        }
401        unsafe {
402            let f: Box_<F> = Box_::new(f);
403            connect_raw(
404                self.as_ptr() as *mut _,
405                c"notify::nat-height".as_ptr() as *const _,
406                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
407                    notify_nat_height_trampoline::<F> as *const (),
408                )),
409                Box_::into_raw(f),
410            )
411        }
412    }
413
414    #[doc(alias = "nat-width")]
415    pub fn connect_nat_width_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
416        unsafe extern "C" fn notify_nat_width_trampoline<F: Fn(&ConstraintGuide) + 'static>(
417            this: *mut ffi::GtkConstraintGuide,
418            _param_spec: glib::ffi::gpointer,
419            f: glib::ffi::gpointer,
420        ) {
421            let f: &F = &*(f as *const F);
422            f(&from_glib_borrow(this))
423        }
424        unsafe {
425            let f: Box_<F> = Box_::new(f);
426            connect_raw(
427                self.as_ptr() as *mut _,
428                c"notify::nat-width".as_ptr() as *const _,
429                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
430                    notify_nat_width_trampoline::<F> as *const (),
431                )),
432                Box_::into_raw(f),
433            )
434        }
435    }
436
437    #[doc(alias = "strength")]
438    pub fn connect_strength_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
439        unsafe extern "C" fn notify_strength_trampoline<F: Fn(&ConstraintGuide) + 'static>(
440            this: *mut ffi::GtkConstraintGuide,
441            _param_spec: glib::ffi::gpointer,
442            f: glib::ffi::gpointer,
443        ) {
444            let f: &F = &*(f as *const F);
445            f(&from_glib_borrow(this))
446        }
447        unsafe {
448            let f: Box_<F> = Box_::new(f);
449            connect_raw(
450                self.as_ptr() as *mut _,
451                c"notify::strength".as_ptr() as *const _,
452                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
453                    notify_strength_trampoline::<F> as *const (),
454                )),
455                Box_::into_raw(f),
456            )
457        }
458    }
459}
460
461impl Default for ConstraintGuide {
462    fn default() -> Self {
463        Self::new()
464    }
465}
466
467// rustdoc-stripper-ignore-next
468/// A [builder-pattern] type to construct [`ConstraintGuide`] objects.
469///
470/// [builder-pattern]: https://doc.rust-lang.org/1.0.0/style/ownership/builders.html
471#[must_use = "The builder must be built to be used"]
472pub struct ConstraintGuideBuilder {
473    builder: glib::object::ObjectBuilder<'static, ConstraintGuide>,
474}
475
476impl ConstraintGuideBuilder {
477    fn new() -> Self {
478        Self {
479            builder: glib::object::Object::builder(),
480        }
481    }
482
483    /// The maximum height of the guide.
484    pub fn max_height(self, max_height: i32) -> Self {
485        Self {
486            builder: self.builder.property("max-height", max_height),
487        }
488    }
489
490    /// The maximum width of the guide.
491    pub fn max_width(self, max_width: i32) -> Self {
492        Self {
493            builder: self.builder.property("max-width", max_width),
494        }
495    }
496
497    /// The minimum height of the guide.
498    pub fn min_height(self, min_height: i32) -> Self {
499        Self {
500            builder: self.builder.property("min-height", min_height),
501        }
502    }
503
504    /// The minimum width of the guide.
505    pub fn min_width(self, min_width: i32) -> Self {
506        Self {
507            builder: self.builder.property("min-width", min_width),
508        }
509    }
510
511    /// A name that identifies the [`ConstraintGuide`][crate::ConstraintGuide], for debugging.
512    pub fn name(self, name: impl Into<glib::GString>) -> Self {
513        Self {
514            builder: self.builder.property("name", name.into()),
515        }
516    }
517
518    /// The preferred, or natural, height of the guide.
519    pub fn nat_height(self, nat_height: i32) -> Self {
520        Self {
521            builder: self.builder.property("nat-height", nat_height),
522        }
523    }
524
525    /// The preferred, or natural, width of the guide.
526    pub fn nat_width(self, nat_width: i32) -> Self {
527        Self {
528            builder: self.builder.property("nat-width", nat_width),
529        }
530    }
531
532    /// The [`ConstraintStrength`][crate::ConstraintStrength] to be used for the constraint on
533    /// the natural size of the guide.
534    pub fn strength(self, strength: ConstraintStrength) -> Self {
535        Self {
536            builder: self.builder.property("strength", strength),
537        }
538    }
539
540    // rustdoc-stripper-ignore-next
541    /// Build the [`ConstraintGuide`].
542    #[must_use = "Building the object from the builder is usually expensive and is not expected to have side effects"]
543    pub fn build(self) -> ConstraintGuide {
544        assert_initialized_main_thread!();
545        self.builder.build()
546    }
547}