gtk4/auto/layout_manager.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, LayoutChild, Orientation, SizeRequestMode, Widget};
6use glib::{prelude::*, translate::*};
7
8glib::wrapper! {
9 /// Layout managers are delegate classes that handle the preferred size
10 /// and the allocation of a widget.
11 ///
12 /// You typically subclass [`LayoutManager`][crate::LayoutManager] if you want to implement a
13 /// layout policy for the children of a widget, or if you want to determine
14 /// the size of a widget depending on its contents.
15 ///
16 /// Each [`Widget`][crate::Widget] can only have a [`LayoutManager`][crate::LayoutManager] instance associated
17 /// to it at any given time; it is possible, though, to replace the layout
18 /// manager instance using [`WidgetExt::set_layout_manager()`][crate::prelude::WidgetExt::set_layout_manager()].
19 ///
20 /// ## Layout properties
21 ///
22 /// A layout manager can expose properties for controlling the layout of
23 /// each child, by creating an object type derived from [`LayoutChild`][crate::LayoutChild]
24 /// and installing the properties on it as normal `GObject` properties.
25 ///
26 /// Each [`LayoutChild`][crate::LayoutChild] instance storing the layout properties for a
27 /// specific child is created through the [`LayoutManagerExt::layout_child()`][crate::prelude::LayoutManagerExt::layout_child()]
28 /// method; a [`LayoutManager`][crate::LayoutManager] controls the creation of its [`LayoutChild`][crate::LayoutChild]
29 /// instances by overriding the GtkLayoutManagerClass.create_layout_child()
30 /// virtual function. The typical implementation should look like:
31 ///
32 /// **⚠️ The following code is in c ⚠️**
33 ///
34 /// ```c
35 /// static GtkLayoutChild *
36 /// create_layout_child (GtkLayoutManager *manager,
37 /// GtkWidget *container,
38 /// GtkWidget *child)
39 /// {
40 /// return g_object_new (your_layout_child_get_type (),
41 /// "layout-manager", manager,
42 /// "child-widget", child,
43 /// NULL);
44 /// }
45 /// ```
46 ///
47 /// The [`layout-manager`][struct@crate::LayoutChild#layout-manager] and
48 /// [`child-widget`][struct@crate::LayoutChild#child-widget] properties
49 /// on the newly created [`LayoutChild`][crate::LayoutChild] instance are mandatory. The
50 /// [`LayoutManager`][crate::LayoutManager] will cache the newly created [`LayoutChild`][crate::LayoutChild] instance
51 /// until the widget is removed from its parent, or the parent removes the
52 /// layout manager.
53 ///
54 /// Each [`LayoutManager`][crate::LayoutManager] instance creating a [`LayoutChild`][crate::LayoutChild] should use
55 /// [`LayoutManagerExt::layout_child()`][crate::prelude::LayoutManagerExt::layout_child()] every time it needs to query
56 /// the layout properties; each [`LayoutChild`][crate::LayoutChild] instance should call
57 /// [`LayoutManagerExt::layout_changed()`][crate::prelude::LayoutManagerExt::layout_changed()] every time a property is
58 /// updated, in order to queue a new size measuring and allocation.
59 ///
60 /// This is an Abstract Base Class, you cannot instantiate it.
61 ///
62 /// # Implements
63 ///
64 /// [`LayoutManagerExt`][trait@crate::prelude::LayoutManagerExt], [`trait@glib::ObjectExt`]
65 #[doc(alias = "GtkLayoutManager")]
66 pub struct LayoutManager(Object<ffi::GtkLayoutManager, ffi::GtkLayoutManagerClass>);
67
68 match fn {
69 type_ => || ffi::gtk_layout_manager_get_type(),
70 }
71}
72
73impl LayoutManager {
74 pub const NONE: Option<&'static LayoutManager> = None;
75}
76
77mod sealed {
78 pub trait Sealed {}
79 impl<T: super::IsA<super::LayoutManager>> Sealed for T {}
80}
81
82/// Trait containing all [`struct@LayoutManager`] methods.
83///
84/// # Implementors
85///
86/// [`BinLayout`][struct@crate::BinLayout], [`BoxLayout`][struct@crate::BoxLayout], [`CenterLayout`][struct@crate::CenterLayout], [`ConstraintLayout`][struct@crate::ConstraintLayout], [`FixedLayout`][struct@crate::FixedLayout], [`GridLayout`][struct@crate::GridLayout], [`LayoutManager`][struct@crate::LayoutManager], [`OverlayLayout`][struct@crate::OverlayLayout]
87pub trait LayoutManagerExt: IsA<LayoutManager> + sealed::Sealed + 'static {
88 /// Assigns the given @width, @height, and @baseline to
89 /// a @widget, and computes the position and sizes of the children of
90 /// the @widget using the layout management policy of @self.
91 /// ## `widget`
92 /// the [`Widget`][crate::Widget] using @self
93 /// ## `width`
94 /// the new width of the @widget
95 /// ## `height`
96 /// the new height of the @widget
97 /// ## `baseline`
98 /// the baseline position of the @widget, or -1
99 #[doc(alias = "gtk_layout_manager_allocate")]
100 fn allocate(&self, widget: &impl IsA<Widget>, width: i32, height: i32, baseline: i32) {
101 unsafe {
102 ffi::gtk_layout_manager_allocate(
103 self.as_ref().to_glib_none().0,
104 widget.as_ref().to_glib_none().0,
105 width,
106 height,
107 baseline,
108 );
109 }
110 }
111
112 /// Retrieves a [`LayoutChild`][crate::LayoutChild] instance for the [`LayoutManager`][crate::LayoutManager],
113 /// creating one if necessary.
114 ///
115 /// The @child widget must be a child of the widget using @self.
116 ///
117 /// The [`LayoutChild`][crate::LayoutChild] instance is owned by the [`LayoutManager`][crate::LayoutManager],
118 /// and is guaranteed to exist as long as @child is a child of the
119 /// [`Widget`][crate::Widget] using the given [`LayoutManager`][crate::LayoutManager].
120 /// ## `child`
121 /// a [`Widget`][crate::Widget]
122 ///
123 /// # Returns
124 ///
125 /// a [`LayoutChild`][crate::LayoutChild]
126 #[doc(alias = "gtk_layout_manager_get_layout_child")]
127 #[doc(alias = "get_layout_child")]
128 fn layout_child(&self, child: &impl IsA<Widget>) -> LayoutChild {
129 unsafe {
130 from_glib_none(ffi::gtk_layout_manager_get_layout_child(
131 self.as_ref().to_glib_none().0,
132 child.as_ref().to_glib_none().0,
133 ))
134 }
135 }
136
137 /// Retrieves the request mode of @self.
138 ///
139 /// # Returns
140 ///
141 /// a [`SizeRequestMode`][crate::SizeRequestMode]
142 #[doc(alias = "gtk_layout_manager_get_request_mode")]
143 #[doc(alias = "get_request_mode")]
144 fn request_mode(&self) -> SizeRequestMode {
145 unsafe {
146 from_glib(ffi::gtk_layout_manager_get_request_mode(
147 self.as_ref().to_glib_none().0,
148 ))
149 }
150 }
151
152 /// Retrieves the [`Widget`][crate::Widget] using the given [`LayoutManager`][crate::LayoutManager].
153 ///
154 /// # Returns
155 ///
156 /// a [`Widget`][crate::Widget]
157 #[doc(alias = "gtk_layout_manager_get_widget")]
158 #[doc(alias = "get_widget")]
159 fn widget(&self) -> Option<Widget> {
160 unsafe {
161 from_glib_none(ffi::gtk_layout_manager_get_widget(
162 self.as_ref().to_glib_none().0,
163 ))
164 }
165 }
166
167 /// Queues a resize on the [`Widget`][crate::Widget] using @self, if any.
168 ///
169 /// This function should be called by subclasses of [`LayoutManager`][crate::LayoutManager]
170 /// in response to changes to their layout management policies.
171 #[doc(alias = "gtk_layout_manager_layout_changed")]
172 fn layout_changed(&self) {
173 unsafe {
174 ffi::gtk_layout_manager_layout_changed(self.as_ref().to_glib_none().0);
175 }
176 }
177
178 /// Measures the size of the @widget using @self, for the
179 /// given @orientation and size.
180 ///
181 /// See the [`Widget`][crate::Widget] documentation on layout management for
182 /// more details.
183 /// ## `widget`
184 /// the [`Widget`][crate::Widget] using @self
185 /// ## `orientation`
186 /// the orientation to measure
187 /// ## `for_size`
188 /// Size for the opposite of @orientation; for instance, if
189 /// the @orientation is [`Orientation::Horizontal`][crate::Orientation::Horizontal], this is the height
190 /// of the widget; if the @orientation is [`Orientation::Vertical`][crate::Orientation::Vertical], this
191 /// is the width of the widget. This allows to measure the height for the
192 /// given width, and the width for the given height. Use -1 if the size
193 /// is not known
194 ///
195 /// # Returns
196 ///
197 ///
198 /// ## `minimum`
199 /// the minimum size for the given size and
200 /// orientation
201 ///
202 /// ## `natural`
203 /// the natural, or preferred size for the
204 /// given size and orientation
205 ///
206 /// ## `minimum_baseline`
207 /// the baseline position for the
208 /// minimum size
209 ///
210 /// ## `natural_baseline`
211 /// the baseline position for the
212 /// natural size
213 #[doc(alias = "gtk_layout_manager_measure")]
214 fn measure(
215 &self,
216 widget: &impl IsA<Widget>,
217 orientation: Orientation,
218 for_size: i32,
219 ) -> (i32, i32, i32, i32) {
220 unsafe {
221 let mut minimum = std::mem::MaybeUninit::uninit();
222 let mut natural = std::mem::MaybeUninit::uninit();
223 let mut minimum_baseline = std::mem::MaybeUninit::uninit();
224 let mut natural_baseline = std::mem::MaybeUninit::uninit();
225 ffi::gtk_layout_manager_measure(
226 self.as_ref().to_glib_none().0,
227 widget.as_ref().to_glib_none().0,
228 orientation.into_glib(),
229 for_size,
230 minimum.as_mut_ptr(),
231 natural.as_mut_ptr(),
232 minimum_baseline.as_mut_ptr(),
233 natural_baseline.as_mut_ptr(),
234 );
235 (
236 minimum.assume_init(),
237 natural.assume_init(),
238 minimum_baseline.assume_init(),
239 natural_baseline.assume_init(),
240 )
241 }
242 }
243}
244
245impl<O: IsA<LayoutManager>> LayoutManagerExt for O {}