Skip to main content

libadwaita/auto/
clamp.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
6#[cfg(feature = "v1_4")]
7#[cfg_attr(docsrs, doc(cfg(feature = "v1_4")))]
8use crate::LengthUnit;
9use crate::ffi;
10use glib::{
11    prelude::*,
12    signal::{SignalHandlerId, connect_raw},
13    translate::*,
14};
15use std::boxed::Box as Box_;
16
17glib::wrapper! {
18    #[doc(alias = "AdwClamp")]
19    pub struct Clamp(Object<ffi::AdwClamp, ffi::AdwClampClass>) @extends gtk::Widget, @implements gtk::Accessible, gtk::Buildable, gtk::ConstraintTarget, gtk::Orientable;
20
21    match fn {
22        type_ => || ffi::adw_clamp_get_type(),
23    }
24}
25
26impl Clamp {
27    #[doc(alias = "adw_clamp_new")]
28    pub fn new() -> Clamp {
29        assert_initialized_main_thread!();
30        unsafe { gtk::Widget::from_glib_none(ffi::adw_clamp_new()).unsafe_cast() }
31    }
32
33    // rustdoc-stripper-ignore-next
34    /// Creates a new builder-pattern struct instance to construct [`Clamp`] objects.
35    ///
36    /// This method returns an instance of [`ClampBuilder`](crate::builders::ClampBuilder) which can be used to create [`Clamp`] objects.
37    pub fn builder() -> ClampBuilder {
38        ClampBuilder::new()
39    }
40
41    #[doc(alias = "adw_clamp_get_child")]
42    #[doc(alias = "get_child")]
43    pub fn child(&self) -> Option<gtk::Widget> {
44        unsafe { from_glib_none(ffi::adw_clamp_get_child(self.to_glib_none().0)) }
45    }
46
47    #[doc(alias = "adw_clamp_get_maximum_size")]
48    #[doc(alias = "get_maximum_size")]
49    #[doc(alias = "maximum-size")]
50    pub fn maximum_size(&self) -> i32 {
51        unsafe { ffi::adw_clamp_get_maximum_size(self.to_glib_none().0) }
52    }
53
54    #[doc(alias = "adw_clamp_get_tightening_threshold")]
55    #[doc(alias = "get_tightening_threshold")]
56    #[doc(alias = "tightening-threshold")]
57    pub fn tightening_threshold(&self) -> i32 {
58        unsafe { ffi::adw_clamp_get_tightening_threshold(self.to_glib_none().0) }
59    }
60
61    #[cfg(feature = "v1_4")]
62    #[cfg_attr(docsrs, doc(cfg(feature = "v1_4")))]
63    #[doc(alias = "adw_clamp_get_unit")]
64    #[doc(alias = "get_unit")]
65    pub fn unit(&self) -> LengthUnit {
66        unsafe { from_glib(ffi::adw_clamp_get_unit(self.to_glib_none().0)) }
67    }
68
69    #[doc(alias = "adw_clamp_set_child")]
70    #[doc(alias = "child")]
71    pub fn set_child(&self, child: Option<&impl IsA<gtk::Widget>>) {
72        unsafe {
73            ffi::adw_clamp_set_child(
74                self.to_glib_none().0,
75                child.map(|p| p.as_ref()).to_glib_none().0,
76            );
77        }
78    }
79
80    #[doc(alias = "adw_clamp_set_maximum_size")]
81    #[doc(alias = "maximum-size")]
82    pub fn set_maximum_size(&self, maximum_size: i32) {
83        unsafe {
84            ffi::adw_clamp_set_maximum_size(self.to_glib_none().0, maximum_size);
85        }
86    }
87
88    #[doc(alias = "adw_clamp_set_tightening_threshold")]
89    #[doc(alias = "tightening-threshold")]
90    pub fn set_tightening_threshold(&self, tightening_threshold: i32) {
91        unsafe {
92            ffi::adw_clamp_set_tightening_threshold(self.to_glib_none().0, tightening_threshold);
93        }
94    }
95
96    #[cfg(feature = "v1_4")]
97    #[cfg_attr(docsrs, doc(cfg(feature = "v1_4")))]
98    #[doc(alias = "adw_clamp_set_unit")]
99    #[doc(alias = "unit")]
100    pub fn set_unit(&self, unit: LengthUnit) {
101        unsafe {
102            ffi::adw_clamp_set_unit(self.to_glib_none().0, unit.into_glib());
103        }
104    }
105
106    #[doc(alias = "child")]
107    pub fn connect_child_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
108        unsafe extern "C" fn notify_child_trampoline<F: Fn(&Clamp) + 'static>(
109            this: *mut ffi::AdwClamp,
110            _param_spec: glib::ffi::gpointer,
111            f: glib::ffi::gpointer,
112        ) {
113            unsafe {
114                let f: &F = &*(f as *const F);
115                f(&from_glib_borrow(this))
116            }
117        }
118        unsafe {
119            let f: Box_<F> = Box_::new(f);
120            connect_raw(
121                self.as_ptr() as *mut _,
122                c"notify::child".as_ptr(),
123                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
124                    notify_child_trampoline::<F> as *const (),
125                )),
126                Box_::into_raw(f),
127            )
128        }
129    }
130
131    #[doc(alias = "maximum-size")]
132    pub fn connect_maximum_size_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
133        unsafe extern "C" fn notify_maximum_size_trampoline<F: Fn(&Clamp) + 'static>(
134            this: *mut ffi::AdwClamp,
135            _param_spec: glib::ffi::gpointer,
136            f: glib::ffi::gpointer,
137        ) {
138            unsafe {
139                let f: &F = &*(f as *const F);
140                f(&from_glib_borrow(this))
141            }
142        }
143        unsafe {
144            let f: Box_<F> = Box_::new(f);
145            connect_raw(
146                self.as_ptr() as *mut _,
147                c"notify::maximum-size".as_ptr(),
148                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
149                    notify_maximum_size_trampoline::<F> as *const (),
150                )),
151                Box_::into_raw(f),
152            )
153        }
154    }
155
156    #[doc(alias = "tightening-threshold")]
157    pub fn connect_tightening_threshold_notify<F: Fn(&Self) + 'static>(
158        &self,
159        f: F,
160    ) -> SignalHandlerId {
161        unsafe extern "C" fn notify_tightening_threshold_trampoline<F: Fn(&Clamp) + 'static>(
162            this: *mut ffi::AdwClamp,
163            _param_spec: glib::ffi::gpointer,
164            f: glib::ffi::gpointer,
165        ) {
166            unsafe {
167                let f: &F = &*(f as *const F);
168                f(&from_glib_borrow(this))
169            }
170        }
171        unsafe {
172            let f: Box_<F> = Box_::new(f);
173            connect_raw(
174                self.as_ptr() as *mut _,
175                c"notify::tightening-threshold".as_ptr(),
176                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
177                    notify_tightening_threshold_trampoline::<F> as *const (),
178                )),
179                Box_::into_raw(f),
180            )
181        }
182    }
183
184    #[cfg(feature = "v1_4")]
185    #[cfg_attr(docsrs, doc(cfg(feature = "v1_4")))]
186    #[doc(alias = "unit")]
187    pub fn connect_unit_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
188        unsafe extern "C" fn notify_unit_trampoline<F: Fn(&Clamp) + 'static>(
189            this: *mut ffi::AdwClamp,
190            _param_spec: glib::ffi::gpointer,
191            f: glib::ffi::gpointer,
192        ) {
193            unsafe {
194                let f: &F = &*(f as *const F);
195                f(&from_glib_borrow(this))
196            }
197        }
198        unsafe {
199            let f: Box_<F> = Box_::new(f);
200            connect_raw(
201                self.as_ptr() as *mut _,
202                c"notify::unit".as_ptr(),
203                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
204                    notify_unit_trampoline::<F> as *const (),
205                )),
206                Box_::into_raw(f),
207            )
208        }
209    }
210}
211
212impl Default for Clamp {
213    fn default() -> Self {
214        Self::new()
215    }
216}
217
218// rustdoc-stripper-ignore-next
219/// A [builder-pattern] type to construct [`Clamp`] objects.
220///
221/// [builder-pattern]: https://doc.rust-lang.org/1.0.0/style/ownership/builders.html
222#[must_use = "The builder must be built to be used"]
223pub struct ClampBuilder {
224    builder: glib::object::ObjectBuilder<'static, Clamp>,
225}
226
227impl ClampBuilder {
228    fn new() -> Self {
229        Self {
230            builder: glib::object::Object::builder(),
231        }
232    }
233
234    pub fn child(self, child: &impl IsA<gtk::Widget>) -> Self {
235        Self {
236            builder: self.builder.property("child", child.clone().upcast()),
237        }
238    }
239
240    pub fn maximum_size(self, maximum_size: i32) -> Self {
241        Self {
242            builder: self.builder.property("maximum-size", maximum_size),
243        }
244    }
245
246    pub fn tightening_threshold(self, tightening_threshold: i32) -> Self {
247        Self {
248            builder: self
249                .builder
250                .property("tightening-threshold", tightening_threshold),
251        }
252    }
253
254    #[cfg(feature = "v1_4")]
255    #[cfg_attr(docsrs, doc(cfg(feature = "v1_4")))]
256    pub fn unit(self, unit: LengthUnit) -> Self {
257        Self {
258            builder: self.builder.property("unit", unit),
259        }
260    }
261
262    pub fn can_focus(self, can_focus: bool) -> Self {
263        Self {
264            builder: self.builder.property("can-focus", can_focus),
265        }
266    }
267
268    pub fn can_target(self, can_target: bool) -> Self {
269        Self {
270            builder: self.builder.property("can-target", can_target),
271        }
272    }
273
274    pub fn css_classes(self, css_classes: impl Into<glib::StrV>) -> Self {
275        Self {
276            builder: self.builder.property("css-classes", css_classes.into()),
277        }
278    }
279
280    pub fn css_name(self, css_name: impl Into<glib::GString>) -> Self {
281        Self {
282            builder: self.builder.property("css-name", css_name.into()),
283        }
284    }
285
286    pub fn cursor(self, cursor: &gdk::Cursor) -> Self {
287        Self {
288            builder: self.builder.property("cursor", cursor.clone()),
289        }
290    }
291
292    pub fn focus_on_click(self, focus_on_click: bool) -> Self {
293        Self {
294            builder: self.builder.property("focus-on-click", focus_on_click),
295        }
296    }
297
298    pub fn focusable(self, focusable: bool) -> Self {
299        Self {
300            builder: self.builder.property("focusable", focusable),
301        }
302    }
303
304    pub fn halign(self, halign: gtk::Align) -> Self {
305        Self {
306            builder: self.builder.property("halign", halign),
307        }
308    }
309
310    pub fn has_tooltip(self, has_tooltip: bool) -> Self {
311        Self {
312            builder: self.builder.property("has-tooltip", has_tooltip),
313        }
314    }
315
316    pub fn height_request(self, height_request: i32) -> Self {
317        Self {
318            builder: self.builder.property("height-request", height_request),
319        }
320    }
321
322    pub fn hexpand(self, hexpand: bool) -> Self {
323        Self {
324            builder: self.builder.property("hexpand", hexpand),
325        }
326    }
327
328    pub fn hexpand_set(self, hexpand_set: bool) -> Self {
329        Self {
330            builder: self.builder.property("hexpand-set", hexpand_set),
331        }
332    }
333
334    pub fn layout_manager(self, layout_manager: &impl IsA<gtk::LayoutManager>) -> Self {
335        Self {
336            builder: self
337                .builder
338                .property("layout-manager", layout_manager.clone().upcast()),
339        }
340    }
341
342    #[cfg(feature = "gtk_v4_18")]
343    #[cfg_attr(docsrs, doc(cfg(feature = "gtk_v4_18")))]
344    pub fn limit_events(self, limit_events: bool) -> Self {
345        Self {
346            builder: self.builder.property("limit-events", limit_events),
347        }
348    }
349
350    pub fn margin_bottom(self, margin_bottom: i32) -> Self {
351        Self {
352            builder: self.builder.property("margin-bottom", margin_bottom),
353        }
354    }
355
356    pub fn margin_end(self, margin_end: i32) -> Self {
357        Self {
358            builder: self.builder.property("margin-end", margin_end),
359        }
360    }
361
362    pub fn margin_start(self, margin_start: i32) -> Self {
363        Self {
364            builder: self.builder.property("margin-start", margin_start),
365        }
366    }
367
368    pub fn margin_top(self, margin_top: i32) -> Self {
369        Self {
370            builder: self.builder.property("margin-top", margin_top),
371        }
372    }
373
374    pub fn name(self, name: impl Into<glib::GString>) -> Self {
375        Self {
376            builder: self.builder.property("name", name.into()),
377        }
378    }
379
380    pub fn opacity(self, opacity: f64) -> Self {
381        Self {
382            builder: self.builder.property("opacity", opacity),
383        }
384    }
385
386    pub fn overflow(self, overflow: gtk::Overflow) -> Self {
387        Self {
388            builder: self.builder.property("overflow", overflow),
389        }
390    }
391
392    pub fn receives_default(self, receives_default: bool) -> Self {
393        Self {
394            builder: self.builder.property("receives-default", receives_default),
395        }
396    }
397
398    pub fn sensitive(self, sensitive: bool) -> Self {
399        Self {
400            builder: self.builder.property("sensitive", sensitive),
401        }
402    }
403
404    pub fn tooltip_markup(self, tooltip_markup: impl Into<glib::GString>) -> Self {
405        Self {
406            builder: self
407                .builder
408                .property("tooltip-markup", tooltip_markup.into()),
409        }
410    }
411
412    pub fn tooltip_text(self, tooltip_text: impl Into<glib::GString>) -> Self {
413        Self {
414            builder: self.builder.property("tooltip-text", tooltip_text.into()),
415        }
416    }
417
418    pub fn valign(self, valign: gtk::Align) -> Self {
419        Self {
420            builder: self.builder.property("valign", valign),
421        }
422    }
423
424    pub fn vexpand(self, vexpand: bool) -> Self {
425        Self {
426            builder: self.builder.property("vexpand", vexpand),
427        }
428    }
429
430    pub fn vexpand_set(self, vexpand_set: bool) -> Self {
431        Self {
432            builder: self.builder.property("vexpand-set", vexpand_set),
433        }
434    }
435
436    pub fn visible(self, visible: bool) -> Self {
437        Self {
438            builder: self.builder.property("visible", visible),
439        }
440    }
441
442    pub fn width_request(self, width_request: i32) -> Self {
443        Self {
444            builder: self.builder.property("width-request", width_request),
445        }
446    }
447
448    pub fn accessible_role(self, accessible_role: gtk::AccessibleRole) -> Self {
449        Self {
450            builder: self.builder.property("accessible-role", accessible_role),
451        }
452    }
453
454    pub fn orientation(self, orientation: gtk::Orientation) -> Self {
455        Self {
456            builder: self.builder.property("orientation", orientation),
457        }
458    }
459
460    // rustdoc-stripper-ignore-next
461    /// Build the [`Clamp`].
462    #[must_use = "Building the object from the builder is usually expensive and is not expected to have side effects"]
463    pub fn build(self) -> Clamp {
464        assert_initialized_main_thread!();
465        self.builder.build()
466    }
467}