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