gtk4/auto/size_group.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::{Buildable, SizeGroupMode, Widget, ffi};
6use glib::{
7 prelude::*,
8 signal::{SignalHandlerId, connect_raw},
9 translate::*,
10};
11use std::boxed::Box as Box_;
12
13glib::wrapper! {
14 ///
15 /// ```text
16 ///
17 ///
18 /// ## Properties
19 ///
20 ///
21 /// #### `mode`
22 /// The direction in which the size group affects requested sizes.
23 ///
24 /// Readable | Writable
25 ///
26 /// # Implements
27 ///
28 /// [`trait@glib::ObjectExt`], [`BuildableExt`][trait@crate::prelude::BuildableExt]
29 #[doc(alias = "GtkSizeGroup")]
30 pub struct SizeGroup(Object<ffi::GtkSizeGroup>) @implements Buildable;
31
32 match fn {
33 type_ => || ffi::gtk_size_group_get_type(),
34 }
35}
36
37impl SizeGroup {
38 /// Create a new [`SizeGroup`][crate::SizeGroup].
39 /// ## `mode`
40 /// the mode for the new size group.
41 ///
42 /// # Returns
43 ///
44 /// a newly created [`SizeGroup`][crate::SizeGroup]
45 #[doc(alias = "gtk_size_group_new")]
46 pub fn new(mode: SizeGroupMode) -> SizeGroup {
47 assert_initialized_main_thread!();
48 unsafe { from_glib_full(ffi::gtk_size_group_new(mode.into_glib())) }
49 }
50
51 /// Adds a widget to a [`SizeGroup`][crate::SizeGroup].
52 ///
53 /// In the future, the requisition
54 /// of the widget will be determined as the maximum of its requisition
55 /// and the requisition of the other widgets in the size group.
56 /// Whether this applies horizontally, vertically, or in both directions
57 /// depends on the mode of the size group.
58 /// See [`set_mode()`][Self::set_mode()].
59 ///
60 /// When the widget is destroyed or no longer referenced elsewhere, it
61 /// will be removed from the size group.
62 /// ## `widget`
63 /// the [`Widget`][crate::Widget] to add
64 #[doc(alias = "gtk_size_group_add_widget")]
65 pub fn add_widget(&self, widget: &impl IsA<Widget>) {
66 unsafe {
67 ffi::gtk_size_group_add_widget(self.to_glib_none().0, widget.as_ref().to_glib_none().0);
68 }
69 }
70
71 /// Gets the current mode of the size group.
72 ///
73 /// # Returns
74 ///
75 /// the current mode of the size group.
76 #[doc(alias = "gtk_size_group_get_mode")]
77 #[doc(alias = "get_mode")]
78 pub fn mode(&self) -> SizeGroupMode {
79 unsafe { from_glib(ffi::gtk_size_group_get_mode(self.to_glib_none().0)) }
80 }
81
82 /// Returns the list of widgets associated with @self.
83 ///
84 /// # Returns
85 ///
86 /// a `GSList` of
87 /// widgets. The list is owned by GTK and should not be modified.
88 #[doc(alias = "gtk_size_group_get_widgets")]
89 #[doc(alias = "get_widgets")]
90 pub fn widgets(&self) -> Vec<Widget> {
91 unsafe {
92 FromGlibPtrContainer::from_glib_none(ffi::gtk_size_group_get_widgets(
93 self.to_glib_none().0,
94 ))
95 }
96 }
97
98 /// Removes a widget from a [`SizeGroup`][crate::SizeGroup].
99 /// ## `widget`
100 /// the [`Widget`][crate::Widget] to remove
101 #[doc(alias = "gtk_size_group_remove_widget")]
102 pub fn remove_widget(&self, widget: &impl IsA<Widget>) {
103 unsafe {
104 ffi::gtk_size_group_remove_widget(
105 self.to_glib_none().0,
106 widget.as_ref().to_glib_none().0,
107 );
108 }
109 }
110
111 /// Sets the [`SizeGroupMode`][crate::SizeGroupMode] of the size group.
112 ///
113 /// The mode of the size group determines whether the widgets in the
114 /// size group should all have the same horizontal requisition
115 /// ([`SizeGroupMode::Horizontal`][crate::SizeGroupMode::Horizontal]) all have the same vertical requisition
116 /// ([`SizeGroupMode::Vertical`][crate::SizeGroupMode::Vertical]), or should all have the same requisition
117 /// in both directions ([`SizeGroupMode::Both`][crate::SizeGroupMode::Both]).
118 /// ## `mode`
119 /// the mode to set for the size group.
120 #[doc(alias = "gtk_size_group_set_mode")]
121 #[doc(alias = "mode")]
122 pub fn set_mode(&self, mode: SizeGroupMode) {
123 unsafe {
124 ffi::gtk_size_group_set_mode(self.to_glib_none().0, mode.into_glib());
125 }
126 }
127
128 #[doc(alias = "mode")]
129 pub fn connect_mode_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
130 unsafe extern "C" fn notify_mode_trampoline<F: Fn(&SizeGroup) + 'static>(
131 this: *mut ffi::GtkSizeGroup,
132 _param_spec: glib::ffi::gpointer,
133 f: glib::ffi::gpointer,
134 ) {
135 unsafe {
136 let f: &F = &*(f as *const F);
137 f(&from_glib_borrow(this))
138 }
139 }
140 unsafe {
141 let f: Box_<F> = Box_::new(f);
142 connect_raw(
143 self.as_ptr() as *mut _,
144 c"notify::mode".as_ptr(),
145 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
146 notify_mode_trampoline::<F> as *const (),
147 )),
148 Box_::into_raw(f),
149 )
150 }
151 }
152}