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