1use crate::{BaselinePosition, LayoutManager, ffi};
6use glib::{
7 prelude::*,
8 signal::{SignalHandlerId, connect_raw},
9 translate::*,
10};
11use std::boxed::Box as Box_;
12
13glib::wrapper! {
14 #[doc(alias = "GtkGridLayout")]
65 pub struct GridLayout(Object<ffi::GtkGridLayout, ffi::GtkGridLayoutClass>) @extends LayoutManager;
66
67 match fn {
68 type_ => || ffi::gtk_grid_layout_get_type(),
69 }
70}
71
72impl GridLayout {
73 #[doc(alias = "gtk_grid_layout_new")]
79 pub fn new() -> GridLayout {
80 assert_initialized_main_thread!();
81 unsafe { LayoutManager::from_glib_full(ffi::gtk_grid_layout_new()).unsafe_cast() }
82 }
83
84 pub fn builder() -> GridLayoutBuilder {
89 GridLayoutBuilder::new()
90 }
91
92 #[doc(alias = "gtk_grid_layout_get_baseline_row")]
98 #[doc(alias = "get_baseline_row")]
99 #[doc(alias = "baseline-row")]
100 pub fn baseline_row(&self) -> i32 {
101 unsafe { ffi::gtk_grid_layout_get_baseline_row(self.to_glib_none().0) }
102 }
103
104 #[doc(alias = "gtk_grid_layout_get_column_homogeneous")]
110 #[doc(alias = "get_column_homogeneous")]
111 #[doc(alias = "column-homogeneous")]
112 pub fn is_column_homogeneous(&self) -> bool {
113 unsafe {
114 from_glib(ffi::gtk_grid_layout_get_column_homogeneous(
115 self.to_glib_none().0,
116 ))
117 }
118 }
119
120 #[doc(alias = "gtk_grid_layout_get_column_spacing")]
126 #[doc(alias = "get_column_spacing")]
127 #[doc(alias = "column-spacing")]
128 pub fn column_spacing(&self) -> u32 {
129 unsafe { ffi::gtk_grid_layout_get_column_spacing(self.to_glib_none().0) }
130 }
131
132 #[doc(alias = "gtk_grid_layout_get_row_baseline_position")]
145 #[doc(alias = "get_row_baseline_position")]
146 pub fn row_baseline_position(&self, row: i32) -> BaselinePosition {
147 unsafe {
148 from_glib(ffi::gtk_grid_layout_get_row_baseline_position(
149 self.to_glib_none().0,
150 row,
151 ))
152 }
153 }
154
155 #[doc(alias = "gtk_grid_layout_get_row_homogeneous")]
161 #[doc(alias = "get_row_homogeneous")]
162 #[doc(alias = "row-homogeneous")]
163 pub fn is_row_homogeneous(&self) -> bool {
164 unsafe {
165 from_glib(ffi::gtk_grid_layout_get_row_homogeneous(
166 self.to_glib_none().0,
167 ))
168 }
169 }
170
171 #[doc(alias = "gtk_grid_layout_get_row_spacing")]
177 #[doc(alias = "get_row_spacing")]
178 #[doc(alias = "row-spacing")]
179 pub fn row_spacing(&self) -> u32 {
180 unsafe { ffi::gtk_grid_layout_get_row_spacing(self.to_glib_none().0) }
181 }
182
183 #[doc(alias = "gtk_grid_layout_set_baseline_row")]
191 #[doc(alias = "baseline-row")]
192 pub fn set_baseline_row(&self, row: i32) {
193 unsafe {
194 ffi::gtk_grid_layout_set_baseline_row(self.to_glib_none().0, row);
195 }
196 }
197
198 #[doc(alias = "gtk_grid_layout_set_column_homogeneous")]
202 #[doc(alias = "column-homogeneous")]
203 pub fn set_column_homogeneous(&self, homogeneous: bool) {
204 unsafe {
205 ffi::gtk_grid_layout_set_column_homogeneous(
206 self.to_glib_none().0,
207 homogeneous.into_glib(),
208 );
209 }
210 }
211
212 #[doc(alias = "gtk_grid_layout_set_column_spacing")]
216 #[doc(alias = "column-spacing")]
217 pub fn set_column_spacing(&self, spacing: u32) {
218 unsafe {
219 ffi::gtk_grid_layout_set_column_spacing(self.to_glib_none().0, spacing);
220 }
221 }
222
223 #[doc(alias = "gtk_grid_layout_set_row_baseline_position")]
230 pub fn set_row_baseline_position(&self, row: i32, pos: BaselinePosition) {
231 unsafe {
232 ffi::gtk_grid_layout_set_row_baseline_position(
233 self.to_glib_none().0,
234 row,
235 pos.into_glib(),
236 );
237 }
238 }
239
240 #[doc(alias = "gtk_grid_layout_set_row_homogeneous")]
244 #[doc(alias = "row-homogeneous")]
245 pub fn set_row_homogeneous(&self, homogeneous: bool) {
246 unsafe {
247 ffi::gtk_grid_layout_set_row_homogeneous(
248 self.to_glib_none().0,
249 homogeneous.into_glib(),
250 );
251 }
252 }
253
254 #[doc(alias = "gtk_grid_layout_set_row_spacing")]
258 #[doc(alias = "row-spacing")]
259 pub fn set_row_spacing(&self, spacing: u32) {
260 unsafe {
261 ffi::gtk_grid_layout_set_row_spacing(self.to_glib_none().0, spacing);
262 }
263 }
264
265 #[doc(alias = "baseline-row")]
266 pub fn connect_baseline_row_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
267 unsafe extern "C" fn notify_baseline_row_trampoline<F: Fn(&GridLayout) + 'static>(
268 this: *mut ffi::GtkGridLayout,
269 _param_spec: glib::ffi::gpointer,
270 f: glib::ffi::gpointer,
271 ) {
272 unsafe {
273 let f: &F = &*(f as *const F);
274 f(&from_glib_borrow(this))
275 }
276 }
277 unsafe {
278 let f: Box_<F> = Box_::new(f);
279 connect_raw(
280 self.as_ptr() as *mut _,
281 c"notify::baseline-row".as_ptr() as *const _,
282 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
283 notify_baseline_row_trampoline::<F> as *const (),
284 )),
285 Box_::into_raw(f),
286 )
287 }
288 }
289
290 #[doc(alias = "column-homogeneous")]
291 pub fn connect_column_homogeneous_notify<F: Fn(&Self) + 'static>(
292 &self,
293 f: F,
294 ) -> SignalHandlerId {
295 unsafe extern "C" fn notify_column_homogeneous_trampoline<F: Fn(&GridLayout) + 'static>(
296 this: *mut ffi::GtkGridLayout,
297 _param_spec: glib::ffi::gpointer,
298 f: glib::ffi::gpointer,
299 ) {
300 unsafe {
301 let f: &F = &*(f as *const F);
302 f(&from_glib_borrow(this))
303 }
304 }
305 unsafe {
306 let f: Box_<F> = Box_::new(f);
307 connect_raw(
308 self.as_ptr() as *mut _,
309 c"notify::column-homogeneous".as_ptr() as *const _,
310 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
311 notify_column_homogeneous_trampoline::<F> as *const (),
312 )),
313 Box_::into_raw(f),
314 )
315 }
316 }
317
318 #[doc(alias = "column-spacing")]
319 pub fn connect_column_spacing_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
320 unsafe extern "C" fn notify_column_spacing_trampoline<F: Fn(&GridLayout) + 'static>(
321 this: *mut ffi::GtkGridLayout,
322 _param_spec: glib::ffi::gpointer,
323 f: glib::ffi::gpointer,
324 ) {
325 unsafe {
326 let f: &F = &*(f as *const F);
327 f(&from_glib_borrow(this))
328 }
329 }
330 unsafe {
331 let f: Box_<F> = Box_::new(f);
332 connect_raw(
333 self.as_ptr() as *mut _,
334 c"notify::column-spacing".as_ptr() as *const _,
335 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
336 notify_column_spacing_trampoline::<F> as *const (),
337 )),
338 Box_::into_raw(f),
339 )
340 }
341 }
342
343 #[doc(alias = "row-homogeneous")]
344 pub fn connect_row_homogeneous_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
345 unsafe extern "C" fn notify_row_homogeneous_trampoline<F: Fn(&GridLayout) + 'static>(
346 this: *mut ffi::GtkGridLayout,
347 _param_spec: glib::ffi::gpointer,
348 f: glib::ffi::gpointer,
349 ) {
350 unsafe {
351 let f: &F = &*(f as *const F);
352 f(&from_glib_borrow(this))
353 }
354 }
355 unsafe {
356 let f: Box_<F> = Box_::new(f);
357 connect_raw(
358 self.as_ptr() as *mut _,
359 c"notify::row-homogeneous".as_ptr() as *const _,
360 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
361 notify_row_homogeneous_trampoline::<F> as *const (),
362 )),
363 Box_::into_raw(f),
364 )
365 }
366 }
367
368 #[doc(alias = "row-spacing")]
369 pub fn connect_row_spacing_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
370 unsafe extern "C" fn notify_row_spacing_trampoline<F: Fn(&GridLayout) + 'static>(
371 this: *mut ffi::GtkGridLayout,
372 _param_spec: glib::ffi::gpointer,
373 f: glib::ffi::gpointer,
374 ) {
375 unsafe {
376 let f: &F = &*(f as *const F);
377 f(&from_glib_borrow(this))
378 }
379 }
380 unsafe {
381 let f: Box_<F> = Box_::new(f);
382 connect_raw(
383 self.as_ptr() as *mut _,
384 c"notify::row-spacing".as_ptr() as *const _,
385 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
386 notify_row_spacing_trampoline::<F> as *const (),
387 )),
388 Box_::into_raw(f),
389 )
390 }
391 }
392}
393
394impl Default for GridLayout {
395 fn default() -> Self {
396 Self::new()
397 }
398}
399
400#[must_use = "The builder must be built to be used"]
405pub struct GridLayoutBuilder {
406 builder: glib::object::ObjectBuilder<'static, GridLayout>,
407}
408
409impl GridLayoutBuilder {
410 fn new() -> Self {
411 Self {
412 builder: glib::object::Object::builder(),
413 }
414 }
415
416 pub fn baseline_row(self, baseline_row: i32) -> Self {
419 Self {
420 builder: self.builder.property("baseline-row", baseline_row),
421 }
422 }
423
424 pub fn column_homogeneous(self, column_homogeneous: bool) -> Self {
426 Self {
427 builder: self
428 .builder
429 .property("column-homogeneous", column_homogeneous),
430 }
431 }
432
433 pub fn column_spacing(self, column_spacing: i32) -> Self {
435 Self {
436 builder: self.builder.property("column-spacing", column_spacing),
437 }
438 }
439
440 pub fn row_homogeneous(self, row_homogeneous: bool) -> Self {
442 Self {
443 builder: self.builder.property("row-homogeneous", row_homogeneous),
444 }
445 }
446
447 pub fn row_spacing(self, row_spacing: i32) -> Self {
449 Self {
450 builder: self.builder.property("row-spacing", row_spacing),
451 }
452 }
453
454 #[must_use = "Building the object from the builder is usually expensive and is not expected to have side effects"]
457 pub fn build(self) -> GridLayout {
458 assert_initialized_main_thread!();
459 self.builder.build()
460 }
461}