Skip to main content

gtk4/auto/
constraint_layout.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::{Buildable, Constraint, ConstraintGuide, LayoutManager, ffi};
6use glib::{prelude::*, translate::*};
7
8glib::wrapper! {
9    /// =150@required, ==250@medium)]
10    /// ```text
11    ///
12    /// Finally, it's also possible to use simple arithmetic operators:
13    ///
14    /// ```
15    ///   // width of button1 must be equal to width of button2
16    ///   // divided by 2 plus 12
17    ///   [button1(button2 / 2 + 12)]
18    /// ```text
19    ///
20    ///
21    /// # Implements
22    ///
23    /// [`LayoutManagerExt`][trait@crate::prelude::LayoutManagerExt], [`trait@glib::ObjectExt`], [`BuildableExt`][trait@crate::prelude::BuildableExt]
24    #[doc(alias = "GtkConstraintLayout")]
25    pub struct ConstraintLayout(Object<ffi::GtkConstraintLayout, ffi::GtkConstraintLayoutClass>) @extends LayoutManager, @implements Buildable;
26
27    match fn {
28        type_ => || ffi::gtk_constraint_layout_get_type(),
29    }
30}
31
32impl ConstraintLayout {
33    /// Creates a new [`ConstraintLayout`][crate::ConstraintLayout] layout manager.
34    ///
35    /// # Returns
36    ///
37    /// the newly created [`ConstraintLayout`][crate::ConstraintLayout]
38    #[doc(alias = "gtk_constraint_layout_new")]
39    pub fn new() -> ConstraintLayout {
40        assert_initialized_main_thread!();
41        unsafe { LayoutManager::from_glib_full(ffi::gtk_constraint_layout_new()).unsafe_cast() }
42    }
43
44    /// Adds a constraint to the layout manager.
45    ///
46    /// The [`source`][struct@crate::Constraint#source] and [`target`][struct@crate::Constraint#target]
47    /// properties of `constraint` can be:
48    ///
49    ///  - set to `NULL` to indicate that the constraint refers to the
50    ///    widget using `layout`
51    ///  - set to the [`Widget`][crate::Widget] using `layout`
52    ///  - set to a child of the [`Widget`][crate::Widget] using `layout`
53    ///  - set to a [`ConstraintGuide`][crate::ConstraintGuide] that is part of `layout`
54    ///
55    /// The @self acquires the ownership of @constraint after calling
56    /// this function.
57    /// ## `constraint`
58    /// a [`Constraint`][crate::Constraint]
59    #[doc(alias = "gtk_constraint_layout_add_constraint")]
60    pub fn add_constraint(&self, constraint: Constraint) {
61        unsafe {
62            ffi::gtk_constraint_layout_add_constraint(
63                self.to_glib_none().0,
64                constraint.into_glib_ptr(),
65            );
66        }
67    }
68
69    /// Adds a guide to `layout`.
70    ///
71    /// A guide can be used as the source or target of constraints,
72    /// like a widget, but it is not visible.
73    ///
74    /// The `layout` acquires the ownership of `guide` after calling
75    /// this function.
76    /// ## `guide`
77    /// a [`ConstraintGuide`][crate::ConstraintGuide] object
78    #[doc(alias = "gtk_constraint_layout_add_guide")]
79    pub fn add_guide(&self, guide: ConstraintGuide) {
80        unsafe {
81            ffi::gtk_constraint_layout_add_guide(self.to_glib_none().0, guide.into_glib_ptr());
82        }
83    }
84
85    /// Returns a `GListModel` to track the constraints that are
86    /// part of the layout.
87    ///
88    /// Calling this function will enable extra internal bookkeeping
89    /// to track constraints and emit signals on the returned listmodel.
90    /// It may slow down operations a lot.
91    ///
92    /// Applications should try hard to avoid calling this function
93    /// because of the slowdowns.
94    ///
95    /// # Returns
96    ///
97    /// a
98    ///   `GListModel` tracking the layout's constraints
99    #[doc(alias = "gtk_constraint_layout_observe_constraints")]
100    pub fn observe_constraints(&self) -> gio::ListModel {
101        unsafe {
102            from_glib_full(ffi::gtk_constraint_layout_observe_constraints(
103                self.to_glib_none().0,
104            ))
105        }
106    }
107
108    /// Returns a `GListModel` to track the guides that are
109    /// part of the layout.
110    ///
111    /// Calling this function will enable extra internal bookkeeping
112    /// to track guides and emit signals on the returned listmodel.
113    /// It may slow down operations a lot.
114    ///
115    /// Applications should try hard to avoid calling this function
116    /// because of the slowdowns.
117    ///
118    /// # Returns
119    ///
120    /// a
121    ///   `GListModel` tracking the layout's guides
122    #[doc(alias = "gtk_constraint_layout_observe_guides")]
123    pub fn observe_guides(&self) -> gio::ListModel {
124        unsafe {
125            from_glib_full(ffi::gtk_constraint_layout_observe_guides(
126                self.to_glib_none().0,
127            ))
128        }
129    }
130
131    /// Removes all constraints from the layout manager.
132    #[doc(alias = "gtk_constraint_layout_remove_all_constraints")]
133    pub fn remove_all_constraints(&self) {
134        unsafe {
135            ffi::gtk_constraint_layout_remove_all_constraints(self.to_glib_none().0);
136        }
137    }
138
139    /// Removes `constraint` from the layout manager,
140    /// so that it no longer influences the layout.
141    /// ## `constraint`
142    /// a [`Constraint`][crate::Constraint]
143    #[doc(alias = "gtk_constraint_layout_remove_constraint")]
144    pub fn remove_constraint(&self, constraint: &Constraint) {
145        unsafe {
146            ffi::gtk_constraint_layout_remove_constraint(
147                self.to_glib_none().0,
148                constraint.to_glib_none().0,
149            );
150        }
151    }
152
153    /// Removes `guide` from the layout manager,
154    /// so that it no longer influences the layout.
155    /// ## `guide`
156    /// a [`ConstraintGuide`][crate::ConstraintGuide] object
157    #[doc(alias = "gtk_constraint_layout_remove_guide")]
158    pub fn remove_guide(&self, guide: &ConstraintGuide) {
159        unsafe {
160            ffi::gtk_constraint_layout_remove_guide(self.to_glib_none().0, guide.to_glib_none().0);
161        }
162    }
163}
164
165impl Default for ConstraintLayout {
166    fn default() -> Self {
167        Self::new()
168    }
169}