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
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    #[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            let f: &F = &*(f as *const F);
114            f(&from_glib_borrow(this))
115        }
116        unsafe {
117            let f: Box_<F> = Box_::new(f);
118            connect_raw(
119                self.as_ptr() as *mut _,
120                c"notify::child".as_ptr() as *const _,
121                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
122                    notify_child_trampoline::<F> as *const (),
123                )),
124                Box_::into_raw(f),
125            )
126        }
127    }
128
129    #[doc(alias = "maximum-size")]
130    pub fn connect_maximum_size_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
131        unsafe extern "C" fn notify_maximum_size_trampoline<F: Fn(&Clamp) + 'static>(
132            this: *mut ffi::AdwClamp,
133            _param_spec: glib::ffi::gpointer,
134            f: glib::ffi::gpointer,
135        ) {
136            let f: &F = &*(f as *const F);
137            f(&from_glib_borrow(this))
138        }
139        unsafe {
140            let f: Box_<F> = Box_::new(f);
141            connect_raw(
142                self.as_ptr() as *mut _,
143                c"notify::maximum-size".as_ptr() as *const _,
144                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
145                    notify_maximum_size_trampoline::<F> as *const (),
146                )),
147                Box_::into_raw(f),
148            )
149        }
150    }
151
152    #[doc(alias = "tightening-threshold")]
153    pub fn connect_tightening_threshold_notify<F: Fn(&Self) + 'static>(
154        &self,
155        f: F,
156    ) -> SignalHandlerId {
157        unsafe extern "C" fn notify_tightening_threshold_trampoline<F: Fn(&Clamp) + 'static>(
158            this: *mut ffi::AdwClamp,
159            _param_spec: glib::ffi::gpointer,
160            f: glib::ffi::gpointer,
161        ) {
162            let f: &F = &*(f as *const F);
163            f(&from_glib_borrow(this))
164        }
165        unsafe {
166            let f: Box_<F> = Box_::new(f);
167            connect_raw(
168                self.as_ptr() as *mut _,
169                c"notify::tightening-threshold".as_ptr() as *const _,
170                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
171                    notify_tightening_threshold_trampoline::<F> as *const (),
172                )),
173                Box_::into_raw(f),
174            )
175        }
176    }
177
178    #[cfg(feature = "v1_4")]
179    #[cfg_attr(docsrs, doc(cfg(feature = "v1_4")))]
180    #[doc(alias = "unit")]
181    pub fn connect_unit_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
182        unsafe extern "C" fn notify_unit_trampoline<F: Fn(&Clamp) + 'static>(
183            this: *mut ffi::AdwClamp,
184            _param_spec: glib::ffi::gpointer,
185            f: glib::ffi::gpointer,
186        ) {
187            let f: &F = &*(f as *const F);
188            f(&from_glib_borrow(this))
189        }
190        unsafe {
191            let f: Box_<F> = Box_::new(f);
192            connect_raw(
193                self.as_ptr() as *mut _,
194                c"notify::unit".as_ptr() as *const _,
195                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
196                    notify_unit_trampoline::<F> as *const (),
197                )),
198                Box_::into_raw(f),
199            )
200        }
201    }
202}
203
204impl Default for Clamp {
205    fn default() -> Self {
206        Self::new()
207    }
208}
209
210// rustdoc-stripper-ignore-next
211/// A [builder-pattern] type to construct [`Clamp`] objects.
212///
213/// [builder-pattern]: https://doc.rust-lang.org/1.0.0/style/ownership/builders.html
214#[must_use = "The builder must be built to be used"]
215pub struct ClampBuilder {
216    builder: glib::object::ObjectBuilder<'static, Clamp>,
217}
218
219impl ClampBuilder {
220    fn new() -> Self {
221        Self {
222            builder: glib::object::Object::builder(),
223        }
224    }
225
226    pub fn child(self, child: &impl IsA<gtk::Widget>) -> Self {
227        Self {
228            builder: self.builder.property("child", child.clone().upcast()),
229        }
230    }
231
232    pub fn maximum_size(self, maximum_size: i32) -> Self {
233        Self {
234            builder: self.builder.property("maximum-size", maximum_size),
235        }
236    }
237
238    pub fn tightening_threshold(self, tightening_threshold: i32) -> Self {
239        Self {
240            builder: self
241                .builder
242                .property("tightening-threshold", tightening_threshold),
243        }
244    }
245
246    #[cfg(feature = "v1_4")]
247    #[cfg_attr(docsrs, doc(cfg(feature = "v1_4")))]
248    pub fn unit(self, unit: LengthUnit) -> Self {
249        Self {
250            builder: self.builder.property("unit", unit),
251        }
252    }
253
254    pub fn can_focus(self, can_focus: bool) -> Self {
255        Self {
256            builder: self.builder.property("can-focus", can_focus),
257        }
258    }
259
260    pub fn can_target(self, can_target: bool) -> Self {
261        Self {
262            builder: self.builder.property("can-target", can_target),
263        }
264    }
265
266    pub fn css_classes(self, css_classes: impl Into<glib::StrV>) -> Self {
267        Self {
268            builder: self.builder.property("css-classes", css_classes.into()),
269        }
270    }
271
272    pub fn css_name(self, css_name: impl Into<glib::GString>) -> Self {
273        Self {
274            builder: self.builder.property("css-name", css_name.into()),
275        }
276    }
277
278    pub fn cursor(self, cursor: &gdk::Cursor) -> Self {
279        Self {
280            builder: self.builder.property("cursor", cursor.clone()),
281        }
282    }
283
284    pub fn focus_on_click(self, focus_on_click: bool) -> Self {
285        Self {
286            builder: self.builder.property("focus-on-click", focus_on_click),
287        }
288    }
289
290    pub fn focusable(self, focusable: bool) -> Self {
291        Self {
292            builder: self.builder.property("focusable", focusable),
293        }
294    }
295
296    pub fn halign(self, halign: gtk::Align) -> Self {
297        Self {
298            builder: self.builder.property("halign", halign),
299        }
300    }
301
302    pub fn has_tooltip(self, has_tooltip: bool) -> Self {
303        Self {
304            builder: self.builder.property("has-tooltip", has_tooltip),
305        }
306    }
307
308    pub fn height_request(self, height_request: i32) -> Self {
309        Self {
310            builder: self.builder.property("height-request", height_request),
311        }
312    }
313
314    pub fn hexpand(self, hexpand: bool) -> Self {
315        Self {
316            builder: self.builder.property("hexpand", hexpand),
317        }
318    }
319
320    pub fn hexpand_set(self, hexpand_set: bool) -> Self {
321        Self {
322            builder: self.builder.property("hexpand-set", hexpand_set),
323        }
324    }
325
326    pub fn layout_manager(self, layout_manager: &impl IsA<gtk::LayoutManager>) -> Self {
327        Self {
328            builder: self
329                .builder
330                .property("layout-manager", layout_manager.clone().upcast()),
331        }
332    }
333
334    #[cfg(feature = "gtk_v4_18")]
335    #[cfg_attr(docsrs, doc(cfg(feature = "gtk_v4_18")))]
336    pub fn limit_events(self, limit_events: bool) -> Self {
337        Self {
338            builder: self.builder.property("limit-events", limit_events),
339        }
340    }
341
342    pub fn margin_bottom(self, margin_bottom: i32) -> Self {
343        Self {
344            builder: self.builder.property("margin-bottom", margin_bottom),
345        }
346    }
347
348    pub fn margin_end(self, margin_end: i32) -> Self {
349        Self {
350            builder: self.builder.property("margin-end", margin_end),
351        }
352    }
353
354    pub fn margin_start(self, margin_start: i32) -> Self {
355        Self {
356            builder: self.builder.property("margin-start", margin_start),
357        }
358    }
359
360    pub fn margin_top(self, margin_top: i32) -> Self {
361        Self {
362            builder: self.builder.property("margin-top", margin_top),
363        }
364    }
365
366    pub fn name(self, name: impl Into<glib::GString>) -> Self {
367        Self {
368            builder: self.builder.property("name", name.into()),
369        }
370    }
371
372    pub fn opacity(self, opacity: f64) -> Self {
373        Self {
374            builder: self.builder.property("opacity", opacity),
375        }
376    }
377
378    pub fn overflow(self, overflow: gtk::Overflow) -> Self {
379        Self {
380            builder: self.builder.property("overflow", overflow),
381        }
382    }
383
384    pub fn receives_default(self, receives_default: bool) -> Self {
385        Self {
386            builder: self.builder.property("receives-default", receives_default),
387        }
388    }
389
390    pub fn sensitive(self, sensitive: bool) -> Self {
391        Self {
392            builder: self.builder.property("sensitive", sensitive),
393        }
394    }
395
396    pub fn tooltip_markup(self, tooltip_markup: impl Into<glib::GString>) -> Self {
397        Self {
398            builder: self
399                .builder
400                .property("tooltip-markup", tooltip_markup.into()),
401        }
402    }
403
404    pub fn tooltip_text(self, tooltip_text: impl Into<glib::GString>) -> Self {
405        Self {
406            builder: self.builder.property("tooltip-text", tooltip_text.into()),
407        }
408    }
409
410    pub fn valign(self, valign: gtk::Align) -> Self {
411        Self {
412            builder: self.builder.property("valign", valign),
413        }
414    }
415
416    pub fn vexpand(self, vexpand: bool) -> Self {
417        Self {
418            builder: self.builder.property("vexpand", vexpand),
419        }
420    }
421
422    pub fn vexpand_set(self, vexpand_set: bool) -> Self {
423        Self {
424            builder: self.builder.property("vexpand-set", vexpand_set),
425        }
426    }
427
428    pub fn visible(self, visible: bool) -> Self {
429        Self {
430            builder: self.builder.property("visible", visible),
431        }
432    }
433
434    pub fn width_request(self, width_request: i32) -> Self {
435        Self {
436            builder: self.builder.property("width-request", width_request),
437        }
438    }
439
440    pub fn accessible_role(self, accessible_role: gtk::AccessibleRole) -> Self {
441        Self {
442            builder: self.builder.property("accessible-role", accessible_role),
443        }
444    }
445
446    pub fn orientation(self, orientation: gtk::Orientation) -> Self {
447        Self {
448            builder: self.builder.property("orientation", orientation),
449        }
450    }
451
452    // rustdoc-stripper-ignore-next
453    /// Build the [`Clamp`].
454    #[must_use = "Building the object from the builder is usually expensive and is not expected to have side effects"]
455    pub fn build(self) -> Clamp {
456        assert_initialized_main_thread!();
457        self.builder.build()
458    }
459}