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")]
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 let f: &F = &*(f as *const F);
273 f(&from_glib_borrow(this))
274 }
275 unsafe {
276 let f: Box_<F> = Box_::new(f);
277 connect_raw(
278 self.as_ptr() as *mut _,
279 c"notify::baseline-row".as_ptr() as *const _,
280 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
281 notify_baseline_row_trampoline::<F> as *const (),
282 )),
283 Box_::into_raw(f),
284 )
285 }
286 }
287
288 #[doc(alias = "column-homogeneous")]
289 pub fn connect_column_homogeneous_notify<F: Fn(&Self) + 'static>(
290 &self,
291 f: F,
292 ) -> SignalHandlerId {
293 unsafe extern "C" fn notify_column_homogeneous_trampoline<F: Fn(&GridLayout) + 'static>(
294 this: *mut ffi::GtkGridLayout,
295 _param_spec: glib::ffi::gpointer,
296 f: glib::ffi::gpointer,
297 ) {
298 let f: &F = &*(f as *const F);
299 f(&from_glib_borrow(this))
300 }
301 unsafe {
302 let f: Box_<F> = Box_::new(f);
303 connect_raw(
304 self.as_ptr() as *mut _,
305 c"notify::column-homogeneous".as_ptr() as *const _,
306 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
307 notify_column_homogeneous_trampoline::<F> as *const (),
308 )),
309 Box_::into_raw(f),
310 )
311 }
312 }
313
314 #[doc(alias = "column-spacing")]
315 pub fn connect_column_spacing_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
316 unsafe extern "C" fn notify_column_spacing_trampoline<F: Fn(&GridLayout) + 'static>(
317 this: *mut ffi::GtkGridLayout,
318 _param_spec: glib::ffi::gpointer,
319 f: glib::ffi::gpointer,
320 ) {
321 let f: &F = &*(f as *const F);
322 f(&from_glib_borrow(this))
323 }
324 unsafe {
325 let f: Box_<F> = Box_::new(f);
326 connect_raw(
327 self.as_ptr() as *mut _,
328 c"notify::column-spacing".as_ptr() as *const _,
329 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
330 notify_column_spacing_trampoline::<F> as *const (),
331 )),
332 Box_::into_raw(f),
333 )
334 }
335 }
336
337 #[doc(alias = "row-homogeneous")]
338 pub fn connect_row_homogeneous_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
339 unsafe extern "C" fn notify_row_homogeneous_trampoline<F: Fn(&GridLayout) + 'static>(
340 this: *mut ffi::GtkGridLayout,
341 _param_spec: glib::ffi::gpointer,
342 f: glib::ffi::gpointer,
343 ) {
344 let f: &F = &*(f as *const F);
345 f(&from_glib_borrow(this))
346 }
347 unsafe {
348 let f: Box_<F> = Box_::new(f);
349 connect_raw(
350 self.as_ptr() as *mut _,
351 c"notify::row-homogeneous".as_ptr() as *const _,
352 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
353 notify_row_homogeneous_trampoline::<F> as *const (),
354 )),
355 Box_::into_raw(f),
356 )
357 }
358 }
359
360 #[doc(alias = "row-spacing")]
361 pub fn connect_row_spacing_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
362 unsafe extern "C" fn notify_row_spacing_trampoline<F: Fn(&GridLayout) + 'static>(
363 this: *mut ffi::GtkGridLayout,
364 _param_spec: glib::ffi::gpointer,
365 f: glib::ffi::gpointer,
366 ) {
367 let f: &F = &*(f as *const F);
368 f(&from_glib_borrow(this))
369 }
370 unsafe {
371 let f: Box_<F> = Box_::new(f);
372 connect_raw(
373 self.as_ptr() as *mut _,
374 c"notify::row-spacing".as_ptr() as *const _,
375 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
376 notify_row_spacing_trampoline::<F> as *const (),
377 )),
378 Box_::into_raw(f),
379 )
380 }
381 }
382}
383
384impl Default for GridLayout {
385 fn default() -> Self {
386 Self::new()
387 }
388}
389
390#[must_use = "The builder must be built to be used"]
395pub struct GridLayoutBuilder {
396 builder: glib::object::ObjectBuilder<'static, GridLayout>,
397}
398
399impl GridLayoutBuilder {
400 fn new() -> Self {
401 Self {
402 builder: glib::object::Object::builder(),
403 }
404 }
405
406 pub fn baseline_row(self, baseline_row: i32) -> Self {
409 Self {
410 builder: self.builder.property("baseline-row", baseline_row),
411 }
412 }
413
414 pub fn column_homogeneous(self, column_homogeneous: bool) -> Self {
416 Self {
417 builder: self
418 .builder
419 .property("column-homogeneous", column_homogeneous),
420 }
421 }
422
423 pub fn column_spacing(self, column_spacing: i32) -> Self {
425 Self {
426 builder: self.builder.property("column-spacing", column_spacing),
427 }
428 }
429
430 pub fn row_homogeneous(self, row_homogeneous: bool) -> Self {
432 Self {
433 builder: self.builder.property("row-homogeneous", row_homogeneous),
434 }
435 }
436
437 pub fn row_spacing(self, row_spacing: i32) -> Self {
439 Self {
440 builder: self.builder.property("row-spacing", row_spacing),
441 }
442 }
443
444 #[must_use = "Building the object from the builder is usually expensive and is not expected to have side effects"]
447 pub fn build(self) -> GridLayout {
448 assert_initialized_main_thread!();
449 self.builder.build()
450 }
451}