1use crate::{ffi, BaselinePosition, LayoutManager};
6use glib::{
7 prelude::*,
8 signal::{connect_raw, SignalHandlerId},
9 translate::*,
10};
11use std::boxed::Box as Box_;
12
13glib::wrapper! {
14 #[doc(alias = "GtkGridLayout")]
15 pub struct GridLayout(Object<ffi::GtkGridLayout, ffi::GtkGridLayoutClass>) @extends LayoutManager;
16
17 match fn {
18 type_ => || ffi::gtk_grid_layout_get_type(),
19 }
20}
21
22impl GridLayout {
23 #[doc(alias = "gtk_grid_layout_new")]
24 pub fn new() -> GridLayout {
25 assert_initialized_main_thread!();
26 unsafe { LayoutManager::from_glib_full(ffi::gtk_grid_layout_new()).unsafe_cast() }
27 }
28
29 pub fn builder() -> GridLayoutBuilder {
34 GridLayoutBuilder::new()
35 }
36
37 #[doc(alias = "gtk_grid_layout_get_baseline_row")]
38 #[doc(alias = "get_baseline_row")]
39 #[doc(alias = "baseline-row")]
40 pub fn baseline_row(&self) -> i32 {
41 unsafe { ffi::gtk_grid_layout_get_baseline_row(self.to_glib_none().0) }
42 }
43
44 #[doc(alias = "gtk_grid_layout_get_column_homogeneous")]
45 #[doc(alias = "get_column_homogeneous")]
46 #[doc(alias = "column-homogeneous")]
47 pub fn is_column_homogeneous(&self) -> bool {
48 unsafe {
49 from_glib(ffi::gtk_grid_layout_get_column_homogeneous(
50 self.to_glib_none().0,
51 ))
52 }
53 }
54
55 #[doc(alias = "gtk_grid_layout_get_column_spacing")]
56 #[doc(alias = "get_column_spacing")]
57 #[doc(alias = "column-spacing")]
58 pub fn column_spacing(&self) -> u32 {
59 unsafe { ffi::gtk_grid_layout_get_column_spacing(self.to_glib_none().0) }
60 }
61
62 #[doc(alias = "gtk_grid_layout_get_row_baseline_position")]
63 #[doc(alias = "get_row_baseline_position")]
64 pub fn row_baseline_position(&self, row: i32) -> BaselinePosition {
65 unsafe {
66 from_glib(ffi::gtk_grid_layout_get_row_baseline_position(
67 self.to_glib_none().0,
68 row,
69 ))
70 }
71 }
72
73 #[doc(alias = "gtk_grid_layout_get_row_homogeneous")]
74 #[doc(alias = "get_row_homogeneous")]
75 #[doc(alias = "row-homogeneous")]
76 pub fn is_row_homogeneous(&self) -> bool {
77 unsafe {
78 from_glib(ffi::gtk_grid_layout_get_row_homogeneous(
79 self.to_glib_none().0,
80 ))
81 }
82 }
83
84 #[doc(alias = "gtk_grid_layout_get_row_spacing")]
85 #[doc(alias = "get_row_spacing")]
86 #[doc(alias = "row-spacing")]
87 pub fn row_spacing(&self) -> u32 {
88 unsafe { ffi::gtk_grid_layout_get_row_spacing(self.to_glib_none().0) }
89 }
90
91 #[doc(alias = "gtk_grid_layout_set_baseline_row")]
92 #[doc(alias = "baseline-row")]
93 pub fn set_baseline_row(&self, row: i32) {
94 unsafe {
95 ffi::gtk_grid_layout_set_baseline_row(self.to_glib_none().0, row);
96 }
97 }
98
99 #[doc(alias = "gtk_grid_layout_set_column_homogeneous")]
100 #[doc(alias = "column-homogeneous")]
101 pub fn set_column_homogeneous(&self, homogeneous: bool) {
102 unsafe {
103 ffi::gtk_grid_layout_set_column_homogeneous(
104 self.to_glib_none().0,
105 homogeneous.into_glib(),
106 );
107 }
108 }
109
110 #[doc(alias = "gtk_grid_layout_set_column_spacing")]
111 #[doc(alias = "column-spacing")]
112 pub fn set_column_spacing(&self, spacing: u32) {
113 unsafe {
114 ffi::gtk_grid_layout_set_column_spacing(self.to_glib_none().0, spacing);
115 }
116 }
117
118 #[doc(alias = "gtk_grid_layout_set_row_baseline_position")]
119 pub fn set_row_baseline_position(&self, row: i32, pos: BaselinePosition) {
120 unsafe {
121 ffi::gtk_grid_layout_set_row_baseline_position(
122 self.to_glib_none().0,
123 row,
124 pos.into_glib(),
125 );
126 }
127 }
128
129 #[doc(alias = "gtk_grid_layout_set_row_homogeneous")]
130 #[doc(alias = "row-homogeneous")]
131 pub fn set_row_homogeneous(&self, homogeneous: bool) {
132 unsafe {
133 ffi::gtk_grid_layout_set_row_homogeneous(
134 self.to_glib_none().0,
135 homogeneous.into_glib(),
136 );
137 }
138 }
139
140 #[doc(alias = "gtk_grid_layout_set_row_spacing")]
141 #[doc(alias = "row-spacing")]
142 pub fn set_row_spacing(&self, spacing: u32) {
143 unsafe {
144 ffi::gtk_grid_layout_set_row_spacing(self.to_glib_none().0, spacing);
145 }
146 }
147
148 #[doc(alias = "baseline-row")]
149 pub fn connect_baseline_row_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
150 unsafe extern "C" fn notify_baseline_row_trampoline<F: Fn(&GridLayout) + 'static>(
151 this: *mut ffi::GtkGridLayout,
152 _param_spec: glib::ffi::gpointer,
153 f: glib::ffi::gpointer,
154 ) {
155 let f: &F = &*(f as *const F);
156 f(&from_glib_borrow(this))
157 }
158 unsafe {
159 let f: Box_<F> = Box_::new(f);
160 connect_raw(
161 self.as_ptr() as *mut _,
162 c"notify::baseline-row".as_ptr() as *const _,
163 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
164 notify_baseline_row_trampoline::<F> as *const (),
165 )),
166 Box_::into_raw(f),
167 )
168 }
169 }
170
171 #[doc(alias = "column-homogeneous")]
172 pub fn connect_column_homogeneous_notify<F: Fn(&Self) + 'static>(
173 &self,
174 f: F,
175 ) -> SignalHandlerId {
176 unsafe extern "C" fn notify_column_homogeneous_trampoline<F: Fn(&GridLayout) + 'static>(
177 this: *mut ffi::GtkGridLayout,
178 _param_spec: glib::ffi::gpointer,
179 f: glib::ffi::gpointer,
180 ) {
181 let f: &F = &*(f as *const F);
182 f(&from_glib_borrow(this))
183 }
184 unsafe {
185 let f: Box_<F> = Box_::new(f);
186 connect_raw(
187 self.as_ptr() as *mut _,
188 c"notify::column-homogeneous".as_ptr() as *const _,
189 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
190 notify_column_homogeneous_trampoline::<F> as *const (),
191 )),
192 Box_::into_raw(f),
193 )
194 }
195 }
196
197 #[doc(alias = "column-spacing")]
198 pub fn connect_column_spacing_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
199 unsafe extern "C" fn notify_column_spacing_trampoline<F: Fn(&GridLayout) + 'static>(
200 this: *mut ffi::GtkGridLayout,
201 _param_spec: glib::ffi::gpointer,
202 f: glib::ffi::gpointer,
203 ) {
204 let f: &F = &*(f as *const F);
205 f(&from_glib_borrow(this))
206 }
207 unsafe {
208 let f: Box_<F> = Box_::new(f);
209 connect_raw(
210 self.as_ptr() as *mut _,
211 c"notify::column-spacing".as_ptr() as *const _,
212 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
213 notify_column_spacing_trampoline::<F> as *const (),
214 )),
215 Box_::into_raw(f),
216 )
217 }
218 }
219
220 #[doc(alias = "row-homogeneous")]
221 pub fn connect_row_homogeneous_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
222 unsafe extern "C" fn notify_row_homogeneous_trampoline<F: Fn(&GridLayout) + 'static>(
223 this: *mut ffi::GtkGridLayout,
224 _param_spec: glib::ffi::gpointer,
225 f: glib::ffi::gpointer,
226 ) {
227 let f: &F = &*(f as *const F);
228 f(&from_glib_borrow(this))
229 }
230 unsafe {
231 let f: Box_<F> = Box_::new(f);
232 connect_raw(
233 self.as_ptr() as *mut _,
234 c"notify::row-homogeneous".as_ptr() as *const _,
235 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
236 notify_row_homogeneous_trampoline::<F> as *const (),
237 )),
238 Box_::into_raw(f),
239 )
240 }
241 }
242
243 #[doc(alias = "row-spacing")]
244 pub fn connect_row_spacing_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
245 unsafe extern "C" fn notify_row_spacing_trampoline<F: Fn(&GridLayout) + 'static>(
246 this: *mut ffi::GtkGridLayout,
247 _param_spec: glib::ffi::gpointer,
248 f: glib::ffi::gpointer,
249 ) {
250 let f: &F = &*(f as *const F);
251 f(&from_glib_borrow(this))
252 }
253 unsafe {
254 let f: Box_<F> = Box_::new(f);
255 connect_raw(
256 self.as_ptr() as *mut _,
257 c"notify::row-spacing".as_ptr() as *const _,
258 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
259 notify_row_spacing_trampoline::<F> as *const (),
260 )),
261 Box_::into_raw(f),
262 )
263 }
264 }
265}
266
267impl Default for GridLayout {
268 fn default() -> Self {
269 Self::new()
270 }
271}
272
273#[must_use = "The builder must be built to be used"]
278pub struct GridLayoutBuilder {
279 builder: glib::object::ObjectBuilder<'static, GridLayout>,
280}
281
282impl GridLayoutBuilder {
283 fn new() -> Self {
284 Self {
285 builder: glib::object::Object::builder(),
286 }
287 }
288
289 pub fn baseline_row(self, baseline_row: i32) -> Self {
290 Self {
291 builder: self.builder.property("baseline-row", baseline_row),
292 }
293 }
294
295 pub fn column_homogeneous(self, column_homogeneous: bool) -> Self {
296 Self {
297 builder: self
298 .builder
299 .property("column-homogeneous", column_homogeneous),
300 }
301 }
302
303 pub fn column_spacing(self, column_spacing: i32) -> Self {
304 Self {
305 builder: self.builder.property("column-spacing", column_spacing),
306 }
307 }
308
309 pub fn row_homogeneous(self, row_homogeneous: bool) -> Self {
310 Self {
311 builder: self.builder.property("row-homogeneous", row_homogeneous),
312 }
313 }
314
315 pub fn row_spacing(self, row_spacing: i32) -> Self {
316 Self {
317 builder: self.builder.property("row-spacing", row_spacing),
318 }
319 }
320
321 #[must_use = "Building the object from the builder is usually expensive and is not expected to have side effects"]
324 pub fn build(self) -> GridLayout {
325 assert_initialized_main_thread!();
326 self.builder.build()
327 }
328}