Skip to main content

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::{ConstraintStrength, ConstraintTarget, ffi};
6use glib::{
7    prelude::*,
8    signal::{SignalHandlerId, connect_raw},
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            unsafe {
284                let f: &F = &*(f as *const F);
285                f(&from_glib_borrow(this))
286            }
287        }
288        unsafe {
289            let f: Box_<F> = Box_::new(f);
290            connect_raw(
291                self.as_ptr() as *mut _,
292                c"notify::max-height".as_ptr() as *const _,
293                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
294                    notify_max_height_trampoline::<F> as *const (),
295                )),
296                Box_::into_raw(f),
297            )
298        }
299    }
300
301    #[doc(alias = "max-width")]
302    pub fn connect_max_width_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
303        unsafe extern "C" fn notify_max_width_trampoline<F: Fn(&ConstraintGuide) + 'static>(
304            this: *mut ffi::GtkConstraintGuide,
305            _param_spec: glib::ffi::gpointer,
306            f: glib::ffi::gpointer,
307        ) {
308            unsafe {
309                let f: &F = &*(f as *const F);
310                f(&from_glib_borrow(this))
311            }
312        }
313        unsafe {
314            let f: Box_<F> = Box_::new(f);
315            connect_raw(
316                self.as_ptr() as *mut _,
317                c"notify::max-width".as_ptr() as *const _,
318                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
319                    notify_max_width_trampoline::<F> as *const (),
320                )),
321                Box_::into_raw(f),
322            )
323        }
324    }
325
326    #[doc(alias = "min-height")]
327    pub fn connect_min_height_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
328        unsafe extern "C" fn notify_min_height_trampoline<F: Fn(&ConstraintGuide) + 'static>(
329            this: *mut ffi::GtkConstraintGuide,
330            _param_spec: glib::ffi::gpointer,
331            f: glib::ffi::gpointer,
332        ) {
333            unsafe {
334                let f: &F = &*(f as *const F);
335                f(&from_glib_borrow(this))
336            }
337        }
338        unsafe {
339            let f: Box_<F> = Box_::new(f);
340            connect_raw(
341                self.as_ptr() as *mut _,
342                c"notify::min-height".as_ptr() as *const _,
343                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
344                    notify_min_height_trampoline::<F> as *const (),
345                )),
346                Box_::into_raw(f),
347            )
348        }
349    }
350
351    #[doc(alias = "min-width")]
352    pub fn connect_min_width_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
353        unsafe extern "C" fn notify_min_width_trampoline<F: Fn(&ConstraintGuide) + 'static>(
354            this: *mut ffi::GtkConstraintGuide,
355            _param_spec: glib::ffi::gpointer,
356            f: glib::ffi::gpointer,
357        ) {
358            unsafe {
359                let f: &F = &*(f as *const F);
360                f(&from_glib_borrow(this))
361            }
362        }
363        unsafe {
364            let f: Box_<F> = Box_::new(f);
365            connect_raw(
366                self.as_ptr() as *mut _,
367                c"notify::min-width".as_ptr() as *const _,
368                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
369                    notify_min_width_trampoline::<F> as *const (),
370                )),
371                Box_::into_raw(f),
372            )
373        }
374    }
375
376    #[doc(alias = "name")]
377    pub fn connect_name_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
378        unsafe extern "C" fn notify_name_trampoline<F: Fn(&ConstraintGuide) + 'static>(
379            this: *mut ffi::GtkConstraintGuide,
380            _param_spec: glib::ffi::gpointer,
381            f: glib::ffi::gpointer,
382        ) {
383            unsafe {
384                let f: &F = &*(f as *const F);
385                f(&from_glib_borrow(this))
386            }
387        }
388        unsafe {
389            let f: Box_<F> = Box_::new(f);
390            connect_raw(
391                self.as_ptr() as *mut _,
392                c"notify::name".as_ptr() as *const _,
393                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
394                    notify_name_trampoline::<F> as *const (),
395                )),
396                Box_::into_raw(f),
397            )
398        }
399    }
400
401    #[doc(alias = "nat-height")]
402    pub fn connect_nat_height_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
403        unsafe extern "C" fn notify_nat_height_trampoline<F: Fn(&ConstraintGuide) + 'static>(
404            this: *mut ffi::GtkConstraintGuide,
405            _param_spec: glib::ffi::gpointer,
406            f: glib::ffi::gpointer,
407        ) {
408            unsafe {
409                let f: &F = &*(f as *const F);
410                f(&from_glib_borrow(this))
411            }
412        }
413        unsafe {
414            let f: Box_<F> = Box_::new(f);
415            connect_raw(
416                self.as_ptr() as *mut _,
417                c"notify::nat-height".as_ptr() as *const _,
418                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
419                    notify_nat_height_trampoline::<F> as *const (),
420                )),
421                Box_::into_raw(f),
422            )
423        }
424    }
425
426    #[doc(alias = "nat-width")]
427    pub fn connect_nat_width_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
428        unsafe extern "C" fn notify_nat_width_trampoline<F: Fn(&ConstraintGuide) + 'static>(
429            this: *mut ffi::GtkConstraintGuide,
430            _param_spec: glib::ffi::gpointer,
431            f: glib::ffi::gpointer,
432        ) {
433            unsafe {
434                let f: &F = &*(f as *const F);
435                f(&from_glib_borrow(this))
436            }
437        }
438        unsafe {
439            let f: Box_<F> = Box_::new(f);
440            connect_raw(
441                self.as_ptr() as *mut _,
442                c"notify::nat-width".as_ptr() as *const _,
443                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
444                    notify_nat_width_trampoline::<F> as *const (),
445                )),
446                Box_::into_raw(f),
447            )
448        }
449    }
450
451    #[doc(alias = "strength")]
452    pub fn connect_strength_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
453        unsafe extern "C" fn notify_strength_trampoline<F: Fn(&ConstraintGuide) + 'static>(
454            this: *mut ffi::GtkConstraintGuide,
455            _param_spec: glib::ffi::gpointer,
456            f: glib::ffi::gpointer,
457        ) {
458            unsafe {
459                let f: &F = &*(f as *const F);
460                f(&from_glib_borrow(this))
461            }
462        }
463        unsafe {
464            let f: Box_<F> = Box_::new(f);
465            connect_raw(
466                self.as_ptr() as *mut _,
467                c"notify::strength".as_ptr() as *const _,
468                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
469                    notify_strength_trampoline::<F> as *const (),
470                )),
471                Box_::into_raw(f),
472            )
473        }
474    }
475}
476
477impl Default for ConstraintGuide {
478    fn default() -> Self {
479        Self::new()
480    }
481}
482
483// rustdoc-stripper-ignore-next
484/// A [builder-pattern] type to construct [`ConstraintGuide`] objects.
485///
486/// [builder-pattern]: https://doc.rust-lang.org/1.0.0/style/ownership/builders.html
487#[must_use = "The builder must be built to be used"]
488pub struct ConstraintGuideBuilder {
489    builder: glib::object::ObjectBuilder<'static, ConstraintGuide>,
490}
491
492impl ConstraintGuideBuilder {
493    fn new() -> Self {
494        Self {
495            builder: glib::object::Object::builder(),
496        }
497    }
498
499    /// The maximum height of the guide.
500    pub fn max_height(self, max_height: i32) -> Self {
501        Self {
502            builder: self.builder.property("max-height", max_height),
503        }
504    }
505
506    /// The maximum width of the guide.
507    pub fn max_width(self, max_width: i32) -> Self {
508        Self {
509            builder: self.builder.property("max-width", max_width),
510        }
511    }
512
513    /// The minimum height of the guide.
514    pub fn min_height(self, min_height: i32) -> Self {
515        Self {
516            builder: self.builder.property("min-height", min_height),
517        }
518    }
519
520    /// The minimum width of the guide.
521    pub fn min_width(self, min_width: i32) -> Self {
522        Self {
523            builder: self.builder.property("min-width", min_width),
524        }
525    }
526
527    /// A name that identifies the [`ConstraintGuide`][crate::ConstraintGuide], for debugging.
528    pub fn name(self, name: impl Into<glib::GString>) -> Self {
529        Self {
530            builder: self.builder.property("name", name.into()),
531        }
532    }
533
534    /// The preferred, or natural, height of the guide.
535    pub fn nat_height(self, nat_height: i32) -> Self {
536        Self {
537            builder: self.builder.property("nat-height", nat_height),
538        }
539    }
540
541    /// The preferred, or natural, width of the guide.
542    pub fn nat_width(self, nat_width: i32) -> Self {
543        Self {
544            builder: self.builder.property("nat-width", nat_width),
545        }
546    }
547
548    /// The [`ConstraintStrength`][crate::ConstraintStrength] to be used for the constraint on
549    /// the natural size of the guide.
550    pub fn strength(self, strength: ConstraintStrength) -> Self {
551        Self {
552            builder: self.builder.property("strength", strength),
553        }
554    }
555
556    // rustdoc-stripper-ignore-next
557    /// Build the [`ConstraintGuide`].
558    #[must_use = "Building the object from the builder is usually expensive and is not expected to have side effects"]
559    pub fn build(self) -> ConstraintGuide {
560        assert_initialized_main_thread!();
561        self.builder.build()
562    }
563}