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