libadwaita/auto/clamp_layout.rs
1// This file was generated by gir (https://github.com/gtk-rs/gir)
2// from
3// from gir-files (https://github.com/gtk-rs/gir-files.git)
4// DO NOT EDIT
5
6use crate::ffi;
7#[cfg(feature = "v1_4")]
8#[cfg_attr(docsrs, doc(cfg(feature = "v1_4")))]
9use crate::LengthUnit;
10use glib::{
11 prelude::*,
12 signal::{connect_raw, SignalHandlerId},
13 translate::*,
14};
15use std::boxed::Box as Box_;
16
17glib::wrapper! {
18 /// A layout manager constraining its children to a given size.
19 ///
20 /// <picture>
21 /// <source srcset="clamp-wide-dark.png" media="(prefers-color-scheme: dark)">
22 /// <img src="clamp-wide.png" alt="clamp-wide">
23 /// </picture>
24 /// <picture>
25 /// <source srcset="clamp-narrow-dark.png" media="(prefers-color-scheme: dark)">
26 /// <img src="clamp-narrow.png" alt="clamp-narrow">
27 /// </picture>
28 ///
29 /// [`ClampLayout`][crate::ClampLayout] constraints the size of the widgets it contains to a given
30 /// maximum size. It will constrain the width if it is horizontal, or the height
31 /// if it is vertical. The expansion of the children from their minimum to their
32 /// maximum size is eased out for a smooth transition.
33 ///
34 /// If a child requires more than the requested maximum size, it will be
35 /// allocated the minimum size it can fit in instead.
36 ///
37 /// [`ClampLayout`][crate::ClampLayout] can scale with the text scale factor, use the
38 /// [`unit`][struct@crate::ClampLayout#unit] property to enable that behavior.
39 ///
40 /// See also: [`Clamp`][crate::Clamp], [`ClampScrollable`][crate::ClampScrollable].
41 ///
42 /// ## Properties
43 ///
44 ///
45 /// #### `maximum-size`
46 /// The maximum size to allocate to the children.
47 ///
48 /// It is the width if the layout is horizontal, or the height if it is
49 /// vertical.
50 ///
51 /// Readable | Writeable
52 ///
53 ///
54 /// #### `tightening-threshold`
55 /// The size above which the children are clamped.
56 ///
57 /// Starting from this size, the layout will tighten its grip on the children,
58 /// slowly allocating less and less of the available size up to the maximum
59 /// allocated size. Below that threshold and below the maximum size, the
60 /// children will be allocated all the available size.
61 ///
62 /// If the threshold is greater than the maximum size to allocate to the
63 /// children, they will be allocated the whole size up to the maximum. If the
64 /// threshold is lower than the minimum size to allocate to the children, that
65 /// size will be used as the tightening threshold.
66 ///
67 /// Effectively, tightening the grip on a child before it reaches its maximum
68 /// size makes transitions to and from the maximum size smoother when resizing.
69 ///
70 /// Readable | Writeable
71 ///
72 ///
73 /// #### `unit`
74 /// The length unit for maximum size and tightening threshold.
75 ///
76 /// Allows the sizes to vary depending on the text scale factor.
77 ///
78 /// Readable | Writeable
79 /// <details><summary><h4>Orientable</h4></summary>
80 ///
81 ///
82 /// #### `orientation`
83 /// The orientation of the orientable.
84 ///
85 /// Readable | Writeable
86 /// </details>
87 ///
88 /// # Implements
89 ///
90 /// [`trait@gtk::prelude::LayoutManagerExt`], [`trait@glib::ObjectExt`], [`trait@gtk::prelude::OrientableExt`]
91 #[doc(alias = "AdwClampLayout")]
92 pub struct ClampLayout(Object<ffi::AdwClampLayout, ffi::AdwClampLayoutClass>) @extends gtk::LayoutManager, @implements gtk::Orientable;
93
94 match fn {
95 type_ => || ffi::adw_clamp_layout_get_type(),
96 }
97}
98
99impl ClampLayout {
100 /// Creates a new [`ClampLayout`][crate::ClampLayout].
101 ///
102 /// # Returns
103 ///
104 /// the newly created [`ClampLayout`][crate::ClampLayout]
105 #[doc(alias = "adw_clamp_layout_new")]
106 pub fn new() -> ClampLayout {
107 assert_initialized_main_thread!();
108 unsafe { gtk::LayoutManager::from_glib_full(ffi::adw_clamp_layout_new()).unsafe_cast() }
109 }
110
111 // rustdoc-stripper-ignore-next
112 /// Creates a new builder-pattern struct instance to construct [`ClampLayout`] objects.
113 ///
114 /// This method returns an instance of [`ClampLayoutBuilder`](crate::builders::ClampLayoutBuilder) which can be used to create [`ClampLayout`] objects.
115 pub fn builder() -> ClampLayoutBuilder {
116 ClampLayoutBuilder::new()
117 }
118
119 /// Gets the maximum size allocated to the children.
120 ///
121 /// # Returns
122 ///
123 /// the maximum size to allocate to the children
124 #[doc(alias = "adw_clamp_layout_get_maximum_size")]
125 #[doc(alias = "get_maximum_size")]
126 #[doc(alias = "maximum-size")]
127 pub fn maximum_size(&self) -> i32 {
128 unsafe { ffi::adw_clamp_layout_get_maximum_size(self.to_glib_none().0) }
129 }
130
131 /// Gets the size above which the children are clamped.
132 ///
133 /// # Returns
134 ///
135 /// the size above which the children are clamped
136 #[doc(alias = "adw_clamp_layout_get_tightening_threshold")]
137 #[doc(alias = "get_tightening_threshold")]
138 #[doc(alias = "tightening-threshold")]
139 pub fn tightening_threshold(&self) -> i32 {
140 unsafe { ffi::adw_clamp_layout_get_tightening_threshold(self.to_glib_none().0) }
141 }
142
143 /// Gets the length unit for maximum size and tightening threshold.
144 ///
145 /// # Returns
146 ///
147 /// the length unit
148 #[cfg(feature = "v1_4")]
149 #[cfg_attr(docsrs, doc(cfg(feature = "v1_4")))]
150 #[doc(alias = "adw_clamp_layout_get_unit")]
151 #[doc(alias = "get_unit")]
152 pub fn unit(&self) -> LengthUnit {
153 unsafe { from_glib(ffi::adw_clamp_layout_get_unit(self.to_glib_none().0)) }
154 }
155
156 /// Sets the maximum size allocated to the children.
157 ///
158 /// It is the width if the layout is horizontal, or the height if it is vertical.
159 /// ## `maximum_size`
160 /// the maximum size
161 #[doc(alias = "adw_clamp_layout_set_maximum_size")]
162 #[doc(alias = "maximum-size")]
163 pub fn set_maximum_size(&self, maximum_size: i32) {
164 unsafe {
165 ffi::adw_clamp_layout_set_maximum_size(self.to_glib_none().0, maximum_size);
166 }
167 }
168
169 /// Sets the size above which the children are clamped.
170 ///
171 /// Starting from this size, the layout will tighten its grip on the children,
172 /// slowly allocating less and less of the available size up to the maximum
173 /// allocated size. Below that threshold and below the maximum size, the children
174 /// will be allocated all the available size.
175 ///
176 /// If the threshold is greater than the maximum size to allocate to the
177 /// children, they will be allocated the whole size up to the maximum. If the
178 /// threshold is lower than the minimum size to allocate to the children, that
179 /// size will be used as the tightening threshold.
180 ///
181 /// Effectively, tightening the grip on a child before it reaches its maximum
182 /// size makes transitions to and from the maximum size smoother when resizing.
183 /// ## `tightening_threshold`
184 /// the tightening threshold
185 #[doc(alias = "adw_clamp_layout_set_tightening_threshold")]
186 #[doc(alias = "tightening-threshold")]
187 pub fn set_tightening_threshold(&self, tightening_threshold: i32) {
188 unsafe {
189 ffi::adw_clamp_layout_set_tightening_threshold(
190 self.to_glib_none().0,
191 tightening_threshold,
192 );
193 }
194 }
195
196 /// Sets the length unit for maximum size and tightening threshold.
197 ///
198 /// Allows the sizes to vary depending on the text scale factor.
199 /// ## `unit`
200 /// the length unit
201 #[cfg(feature = "v1_4")]
202 #[cfg_attr(docsrs, doc(cfg(feature = "v1_4")))]
203 #[doc(alias = "adw_clamp_layout_set_unit")]
204 #[doc(alias = "unit")]
205 pub fn set_unit(&self, unit: LengthUnit) {
206 unsafe {
207 ffi::adw_clamp_layout_set_unit(self.to_glib_none().0, unit.into_glib());
208 }
209 }
210
211 #[doc(alias = "maximum-size")]
212 pub fn connect_maximum_size_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
213 unsafe extern "C" fn notify_maximum_size_trampoline<F: Fn(&ClampLayout) + 'static>(
214 this: *mut ffi::AdwClampLayout,
215 _param_spec: glib::ffi::gpointer,
216 f: glib::ffi::gpointer,
217 ) {
218 let f: &F = &*(f as *const F);
219 f(&from_glib_borrow(this))
220 }
221 unsafe {
222 let f: Box_<F> = Box_::new(f);
223 connect_raw(
224 self.as_ptr() as *mut _,
225 c"notify::maximum-size".as_ptr() as *const _,
226 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
227 notify_maximum_size_trampoline::<F> as *const (),
228 )),
229 Box_::into_raw(f),
230 )
231 }
232 }
233
234 #[doc(alias = "tightening-threshold")]
235 pub fn connect_tightening_threshold_notify<F: Fn(&Self) + 'static>(
236 &self,
237 f: F,
238 ) -> SignalHandlerId {
239 unsafe extern "C" fn notify_tightening_threshold_trampoline<
240 F: Fn(&ClampLayout) + 'static,
241 >(
242 this: *mut ffi::AdwClampLayout,
243 _param_spec: glib::ffi::gpointer,
244 f: glib::ffi::gpointer,
245 ) {
246 let f: &F = &*(f as *const F);
247 f(&from_glib_borrow(this))
248 }
249 unsafe {
250 let f: Box_<F> = Box_::new(f);
251 connect_raw(
252 self.as_ptr() as *mut _,
253 c"notify::tightening-threshold".as_ptr() as *const _,
254 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
255 notify_tightening_threshold_trampoline::<F> as *const (),
256 )),
257 Box_::into_raw(f),
258 )
259 }
260 }
261
262 #[cfg(feature = "v1_4")]
263 #[cfg_attr(docsrs, doc(cfg(feature = "v1_4")))]
264 #[doc(alias = "unit")]
265 pub fn connect_unit_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
266 unsafe extern "C" fn notify_unit_trampoline<F: Fn(&ClampLayout) + 'static>(
267 this: *mut ffi::AdwClampLayout,
268 _param_spec: glib::ffi::gpointer,
269 f: glib::ffi::gpointer,
270 ) {
271 let f: &F = &*(f as *const F);
272 f(&from_glib_borrow(this))
273 }
274 unsafe {
275 let f: Box_<F> = Box_::new(f);
276 connect_raw(
277 self.as_ptr() as *mut _,
278 c"notify::unit".as_ptr() as *const _,
279 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
280 notify_unit_trampoline::<F> as *const (),
281 )),
282 Box_::into_raw(f),
283 )
284 }
285 }
286}
287
288impl Default for ClampLayout {
289 fn default() -> Self {
290 Self::new()
291 }
292}
293
294// rustdoc-stripper-ignore-next
295/// A [builder-pattern] type to construct [`ClampLayout`] objects.
296///
297/// [builder-pattern]: https://doc.rust-lang.org/1.0.0/style/ownership/builders.html
298#[must_use = "The builder must be built to be used"]
299pub struct ClampLayoutBuilder {
300 builder: glib::object::ObjectBuilder<'static, ClampLayout>,
301}
302
303impl ClampLayoutBuilder {
304 fn new() -> Self {
305 Self {
306 builder: glib::object::Object::builder(),
307 }
308 }
309
310 /// The maximum size to allocate to the children.
311 ///
312 /// It is the width if the layout is horizontal, or the height if it is
313 /// vertical.
314 pub fn maximum_size(self, maximum_size: i32) -> Self {
315 Self {
316 builder: self.builder.property("maximum-size", maximum_size),
317 }
318 }
319
320 /// The size above which the children are clamped.
321 ///
322 /// Starting from this size, the layout will tighten its grip on the children,
323 /// slowly allocating less and less of the available size up to the maximum
324 /// allocated size. Below that threshold and below the maximum size, the
325 /// children will be allocated all the available size.
326 ///
327 /// If the threshold is greater than the maximum size to allocate to the
328 /// children, they will be allocated the whole size up to the maximum. If the
329 /// threshold is lower than the minimum size to allocate to the children, that
330 /// size will be used as the tightening threshold.
331 ///
332 /// Effectively, tightening the grip on a child before it reaches its maximum
333 /// size makes transitions to and from the maximum size smoother when resizing.
334 pub fn tightening_threshold(self, tightening_threshold: i32) -> Self {
335 Self {
336 builder: self
337 .builder
338 .property("tightening-threshold", tightening_threshold),
339 }
340 }
341
342 /// The length unit for maximum size and tightening threshold.
343 ///
344 /// Allows the sizes to vary depending on the text scale factor.
345 #[cfg(feature = "v1_4")]
346 #[cfg_attr(docsrs, doc(cfg(feature = "v1_4")))]
347 pub fn unit(self, unit: LengthUnit) -> Self {
348 Self {
349 builder: self.builder.property("unit", unit),
350 }
351 }
352
353 /// The orientation of the orientable.
354 pub fn orientation(self, orientation: gtk::Orientation) -> Self {
355 Self {
356 builder: self.builder.property("orientation", orientation),
357 }
358 }
359
360 // rustdoc-stripper-ignore-next
361 /// Build the [`ClampLayout`].
362 #[must_use = "Building the object from the builder is usually expensive and is not expected to have side effects"]
363 pub fn build(self) -> ClampLayout {
364 assert_initialized_main_thread!();
365 self.builder.build()
366 }
367}