[go: up one dir, main page]

gtk4/auto/
grid.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::{
6    ffi, Accessible, AccessibleRole, Align, BaselinePosition, Buildable, ConstraintTarget,
7    LayoutManager, Orientable, Orientation, Overflow, PositionType, Widget,
8};
9use glib::{
10    prelude::*,
11    signal::{connect_raw, SignalHandlerId},
12    translate::*,
13};
14use std::boxed::Box as Box_;
15
16glib::wrapper! {
17    #[doc(alias = "GtkGrid")]
18    pub struct Grid(Object<ffi::GtkGrid, ffi::GtkGridClass>) @extends Widget, @implements Accessible, Buildable, ConstraintTarget, Orientable;
19
20    match fn {
21        type_ => || ffi::gtk_grid_get_type(),
22    }
23}
24
25impl Grid {
26    pub const NONE: Option<&'static Grid> = None;
27
28    #[doc(alias = "gtk_grid_new")]
29    pub fn new() -> Grid {
30        assert_initialized_main_thread!();
31        unsafe { Widget::from_glib_none(ffi::gtk_grid_new()).unsafe_cast() }
32    }
33
34    // rustdoc-stripper-ignore-next
35    /// Creates a new builder-pattern struct instance to construct [`Grid`] objects.
36    ///
37    /// This method returns an instance of [`GridBuilder`](crate::builders::GridBuilder) which can be used to create [`Grid`] objects.
38    pub fn builder() -> GridBuilder {
39        GridBuilder::new()
40    }
41}
42
43impl Default for Grid {
44    fn default() -> Self {
45        Self::new()
46    }
47}
48
49// rustdoc-stripper-ignore-next
50/// A [builder-pattern] type to construct [`Grid`] objects.
51///
52/// [builder-pattern]: https://doc.rust-lang.org/1.0.0/style/ownership/builders.html
53#[must_use = "The builder must be built to be used"]
54pub struct GridBuilder {
55    builder: glib::object::ObjectBuilder<'static, Grid>,
56}
57
58impl GridBuilder {
59    fn new() -> Self {
60        Self {
61            builder: glib::object::Object::builder(),
62        }
63    }
64
65    pub fn baseline_row(self, baseline_row: i32) -> Self {
66        Self {
67            builder: self.builder.property("baseline-row", baseline_row),
68        }
69    }
70
71    pub fn column_homogeneous(self, column_homogeneous: bool) -> Self {
72        Self {
73            builder: self
74                .builder
75                .property("column-homogeneous", column_homogeneous),
76        }
77    }
78
79    pub fn column_spacing(self, column_spacing: i32) -> Self {
80        Self {
81            builder: self.builder.property("column-spacing", column_spacing),
82        }
83    }
84
85    pub fn row_homogeneous(self, row_homogeneous: bool) -> Self {
86        Self {
87            builder: self.builder.property("row-homogeneous", row_homogeneous),
88        }
89    }
90
91    pub fn row_spacing(self, row_spacing: i32) -> Self {
92        Self {
93            builder: self.builder.property("row-spacing", row_spacing),
94        }
95    }
96
97    pub fn can_focus(self, can_focus: bool) -> Self {
98        Self {
99            builder: self.builder.property("can-focus", can_focus),
100        }
101    }
102
103    pub fn can_target(self, can_target: bool) -> Self {
104        Self {
105            builder: self.builder.property("can-target", can_target),
106        }
107    }
108
109    pub fn css_classes(self, css_classes: impl Into<glib::StrV>) -> Self {
110        Self {
111            builder: self.builder.property("css-classes", css_classes.into()),
112        }
113    }
114
115    pub fn css_name(self, css_name: impl Into<glib::GString>) -> Self {
116        Self {
117            builder: self.builder.property("css-name", css_name.into()),
118        }
119    }
120
121    pub fn cursor(self, cursor: &gdk::Cursor) -> Self {
122        Self {
123            builder: self.builder.property("cursor", cursor.clone()),
124        }
125    }
126
127    pub fn focus_on_click(self, focus_on_click: bool) -> Self {
128        Self {
129            builder: self.builder.property("focus-on-click", focus_on_click),
130        }
131    }
132
133    pub fn focusable(self, focusable: bool) -> Self {
134        Self {
135            builder: self.builder.property("focusable", focusable),
136        }
137    }
138
139    pub fn halign(self, halign: Align) -> Self {
140        Self {
141            builder: self.builder.property("halign", halign),
142        }
143    }
144
145    pub fn has_tooltip(self, has_tooltip: bool) -> Self {
146        Self {
147            builder: self.builder.property("has-tooltip", has_tooltip),
148        }
149    }
150
151    pub fn height_request(self, height_request: i32) -> Self {
152        Self {
153            builder: self.builder.property("height-request", height_request),
154        }
155    }
156
157    pub fn hexpand(self, hexpand: bool) -> Self {
158        Self {
159            builder: self.builder.property("hexpand", hexpand),
160        }
161    }
162
163    pub fn hexpand_set(self, hexpand_set: bool) -> Self {
164        Self {
165            builder: self.builder.property("hexpand-set", hexpand_set),
166        }
167    }
168
169    pub fn layout_manager(self, layout_manager: &impl IsA<LayoutManager>) -> Self {
170        Self {
171            builder: self
172                .builder
173                .property("layout-manager", layout_manager.clone().upcast()),
174        }
175    }
176
177    #[cfg(feature = "v4_18")]
178    #[cfg_attr(docsrs, doc(cfg(feature = "v4_18")))]
179    pub fn limit_events(self, limit_events: bool) -> Self {
180        Self {
181            builder: self.builder.property("limit-events", limit_events),
182        }
183    }
184
185    pub fn margin_bottom(self, margin_bottom: i32) -> Self {
186        Self {
187            builder: self.builder.property("margin-bottom", margin_bottom),
188        }
189    }
190
191    pub fn margin_end(self, margin_end: i32) -> Self {
192        Self {
193            builder: self.builder.property("margin-end", margin_end),
194        }
195    }
196
197    pub fn margin_start(self, margin_start: i32) -> Self {
198        Self {
199            builder: self.builder.property("margin-start", margin_start),
200        }
201    }
202
203    pub fn margin_top(self, margin_top: i32) -> Self {
204        Self {
205            builder: self.builder.property("margin-top", margin_top),
206        }
207    }
208
209    pub fn name(self, name: impl Into<glib::GString>) -> Self {
210        Self {
211            builder: self.builder.property("name", name.into()),
212        }
213    }
214
215    pub fn opacity(self, opacity: f64) -> Self {
216        Self {
217            builder: self.builder.property("opacity", opacity),
218        }
219    }
220
221    pub fn overflow(self, overflow: Overflow) -> Self {
222        Self {
223            builder: self.builder.property("overflow", overflow),
224        }
225    }
226
227    pub fn receives_default(self, receives_default: bool) -> Self {
228        Self {
229            builder: self.builder.property("receives-default", receives_default),
230        }
231    }
232
233    pub fn sensitive(self, sensitive: bool) -> Self {
234        Self {
235            builder: self.builder.property("sensitive", sensitive),
236        }
237    }
238
239    pub fn tooltip_markup(self, tooltip_markup: impl Into<glib::GString>) -> Self {
240        Self {
241            builder: self
242                .builder
243                .property("tooltip-markup", tooltip_markup.into()),
244        }
245    }
246
247    pub fn tooltip_text(self, tooltip_text: impl Into<glib::GString>) -> Self {
248        Self {
249            builder: self.builder.property("tooltip-text", tooltip_text.into()),
250        }
251    }
252
253    pub fn valign(self, valign: Align) -> Self {
254        Self {
255            builder: self.builder.property("valign", valign),
256        }
257    }
258
259    pub fn vexpand(self, vexpand: bool) -> Self {
260        Self {
261            builder: self.builder.property("vexpand", vexpand),
262        }
263    }
264
265    pub fn vexpand_set(self, vexpand_set: bool) -> Self {
266        Self {
267            builder: self.builder.property("vexpand-set", vexpand_set),
268        }
269    }
270
271    pub fn visible(self, visible: bool) -> Self {
272        Self {
273            builder: self.builder.property("visible", visible),
274        }
275    }
276
277    pub fn width_request(self, width_request: i32) -> Self {
278        Self {
279            builder: self.builder.property("width-request", width_request),
280        }
281    }
282
283    pub fn accessible_role(self, accessible_role: AccessibleRole) -> Self {
284        Self {
285            builder: self.builder.property("accessible-role", accessible_role),
286        }
287    }
288
289    pub fn orientation(self, orientation: Orientation) -> Self {
290        Self {
291            builder: self.builder.property("orientation", orientation),
292        }
293    }
294
295    // rustdoc-stripper-ignore-next
296    /// Build the [`Grid`].
297    #[must_use = "Building the object from the builder is usually expensive and is not expected to have side effects"]
298    pub fn build(self) -> Grid {
299        assert_initialized_main_thread!();
300        self.builder.build()
301    }
302}
303
304pub trait GridExt: IsA<Grid> + 'static {
305    #[doc(alias = "gtk_grid_attach")]
306    fn attach(&self, child: &impl IsA<Widget>, column: i32, row: i32, width: i32, height: i32) {
307        unsafe {
308            ffi::gtk_grid_attach(
309                self.as_ref().to_glib_none().0,
310                child.as_ref().to_glib_none().0,
311                column,
312                row,
313                width,
314                height,
315            );
316        }
317    }
318
319    #[doc(alias = "gtk_grid_attach_next_to")]
320    fn attach_next_to(
321        &self,
322        child: &impl IsA<Widget>,
323        sibling: Option<&impl IsA<Widget>>,
324        side: PositionType,
325        width: i32,
326        height: i32,
327    ) {
328        unsafe {
329            ffi::gtk_grid_attach_next_to(
330                self.as_ref().to_glib_none().0,
331                child.as_ref().to_glib_none().0,
332                sibling.map(|p| p.as_ref()).to_glib_none().0,
333                side.into_glib(),
334                width,
335                height,
336            );
337        }
338    }
339
340    #[doc(alias = "gtk_grid_get_baseline_row")]
341    #[doc(alias = "get_baseline_row")]
342    #[doc(alias = "baseline-row")]
343    fn baseline_row(&self) -> i32 {
344        unsafe { ffi::gtk_grid_get_baseline_row(self.as_ref().to_glib_none().0) }
345    }
346
347    #[doc(alias = "gtk_grid_get_child_at")]
348    #[doc(alias = "get_child_at")]
349    fn child_at(&self, column: i32, row: i32) -> Option<Widget> {
350        unsafe {
351            from_glib_none(ffi::gtk_grid_get_child_at(
352                self.as_ref().to_glib_none().0,
353                column,
354                row,
355            ))
356        }
357    }
358
359    #[doc(alias = "gtk_grid_get_column_homogeneous")]
360    #[doc(alias = "get_column_homogeneous")]
361    #[doc(alias = "column-homogeneous")]
362    fn is_column_homogeneous(&self) -> bool {
363        unsafe {
364            from_glib(ffi::gtk_grid_get_column_homogeneous(
365                self.as_ref().to_glib_none().0,
366            ))
367        }
368    }
369
370    #[doc(alias = "gtk_grid_get_column_spacing")]
371    #[doc(alias = "get_column_spacing")]
372    #[doc(alias = "column-spacing")]
373    fn column_spacing(&self) -> u32 {
374        unsafe { ffi::gtk_grid_get_column_spacing(self.as_ref().to_glib_none().0) }
375    }
376
377    #[doc(alias = "gtk_grid_get_row_baseline_position")]
378    #[doc(alias = "get_row_baseline_position")]
379    fn row_baseline_position(&self, row: i32) -> BaselinePosition {
380        unsafe {
381            from_glib(ffi::gtk_grid_get_row_baseline_position(
382                self.as_ref().to_glib_none().0,
383                row,
384            ))
385        }
386    }
387
388    #[doc(alias = "gtk_grid_get_row_homogeneous")]
389    #[doc(alias = "get_row_homogeneous")]
390    #[doc(alias = "row-homogeneous")]
391    fn is_row_homogeneous(&self) -> bool {
392        unsafe {
393            from_glib(ffi::gtk_grid_get_row_homogeneous(
394                self.as_ref().to_glib_none().0,
395            ))
396        }
397    }
398
399    #[doc(alias = "gtk_grid_get_row_spacing")]
400    #[doc(alias = "get_row_spacing")]
401    #[doc(alias = "row-spacing")]
402    fn row_spacing(&self) -> u32 {
403        unsafe { ffi::gtk_grid_get_row_spacing(self.as_ref().to_glib_none().0) }
404    }
405
406    #[doc(alias = "gtk_grid_insert_column")]
407    fn insert_column(&self, position: i32) {
408        unsafe {
409            ffi::gtk_grid_insert_column(self.as_ref().to_glib_none().0, position);
410        }
411    }
412
413    #[doc(alias = "gtk_grid_insert_next_to")]
414    fn insert_next_to(&self, sibling: &impl IsA<Widget>, side: PositionType) {
415        unsafe {
416            ffi::gtk_grid_insert_next_to(
417                self.as_ref().to_glib_none().0,
418                sibling.as_ref().to_glib_none().0,
419                side.into_glib(),
420            );
421        }
422    }
423
424    #[doc(alias = "gtk_grid_insert_row")]
425    fn insert_row(&self, position: i32) {
426        unsafe {
427            ffi::gtk_grid_insert_row(self.as_ref().to_glib_none().0, position);
428        }
429    }
430
431    #[doc(alias = "gtk_grid_query_child")]
432    fn query_child(&self, child: &impl IsA<Widget>) -> (i32, i32, i32, i32) {
433        unsafe {
434            let mut column = std::mem::MaybeUninit::uninit();
435            let mut row = std::mem::MaybeUninit::uninit();
436            let mut width = std::mem::MaybeUninit::uninit();
437            let mut height = std::mem::MaybeUninit::uninit();
438            ffi::gtk_grid_query_child(
439                self.as_ref().to_glib_none().0,
440                child.as_ref().to_glib_none().0,
441                column.as_mut_ptr(),
442                row.as_mut_ptr(),
443                width.as_mut_ptr(),
444                height.as_mut_ptr(),
445            );
446            (
447                column.assume_init(),
448                row.assume_init(),
449                width.assume_init(),
450                height.assume_init(),
451            )
452        }
453    }
454
455    #[doc(alias = "gtk_grid_remove")]
456    fn remove(&self, child: &impl IsA<Widget>) {
457        unsafe {
458            ffi::gtk_grid_remove(
459                self.as_ref().to_glib_none().0,
460                child.as_ref().to_glib_none().0,
461            );
462        }
463    }
464
465    #[doc(alias = "gtk_grid_remove_column")]
466    fn remove_column(&self, position: i32) {
467        unsafe {
468            ffi::gtk_grid_remove_column(self.as_ref().to_glib_none().0, position);
469        }
470    }
471
472    #[doc(alias = "gtk_grid_remove_row")]
473    fn remove_row(&self, position: i32) {
474        unsafe {
475            ffi::gtk_grid_remove_row(self.as_ref().to_glib_none().0, position);
476        }
477    }
478
479    #[doc(alias = "gtk_grid_set_baseline_row")]
480    #[doc(alias = "baseline-row")]
481    fn set_baseline_row(&self, row: i32) {
482        unsafe {
483            ffi::gtk_grid_set_baseline_row(self.as_ref().to_glib_none().0, row);
484        }
485    }
486
487    #[doc(alias = "gtk_grid_set_column_homogeneous")]
488    #[doc(alias = "column-homogeneous")]
489    fn set_column_homogeneous(&self, homogeneous: bool) {
490        unsafe {
491            ffi::gtk_grid_set_column_homogeneous(
492                self.as_ref().to_glib_none().0,
493                homogeneous.into_glib(),
494            );
495        }
496    }
497
498    #[doc(alias = "gtk_grid_set_column_spacing")]
499    #[doc(alias = "column-spacing")]
500    fn set_column_spacing(&self, spacing: u32) {
501        unsafe {
502            ffi::gtk_grid_set_column_spacing(self.as_ref().to_glib_none().0, spacing);
503        }
504    }
505
506    #[doc(alias = "gtk_grid_set_row_baseline_position")]
507    fn set_row_baseline_position(&self, row: i32, pos: BaselinePosition) {
508        unsafe {
509            ffi::gtk_grid_set_row_baseline_position(
510                self.as_ref().to_glib_none().0,
511                row,
512                pos.into_glib(),
513            );
514        }
515    }
516
517    #[doc(alias = "gtk_grid_set_row_homogeneous")]
518    #[doc(alias = "row-homogeneous")]
519    fn set_row_homogeneous(&self, homogeneous: bool) {
520        unsafe {
521            ffi::gtk_grid_set_row_homogeneous(
522                self.as_ref().to_glib_none().0,
523                homogeneous.into_glib(),
524            );
525        }
526    }
527
528    #[doc(alias = "gtk_grid_set_row_spacing")]
529    #[doc(alias = "row-spacing")]
530    fn set_row_spacing(&self, spacing: u32) {
531        unsafe {
532            ffi::gtk_grid_set_row_spacing(self.as_ref().to_glib_none().0, spacing);
533        }
534    }
535
536    #[doc(alias = "baseline-row")]
537    fn connect_baseline_row_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
538        unsafe extern "C" fn notify_baseline_row_trampoline<P: IsA<Grid>, F: Fn(&P) + 'static>(
539            this: *mut ffi::GtkGrid,
540            _param_spec: glib::ffi::gpointer,
541            f: glib::ffi::gpointer,
542        ) {
543            let f: &F = &*(f as *const F);
544            f(Grid::from_glib_borrow(this).unsafe_cast_ref())
545        }
546        unsafe {
547            let f: Box_<F> = Box_::new(f);
548            connect_raw(
549                self.as_ptr() as *mut _,
550                c"notify::baseline-row".as_ptr() as *const _,
551                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
552                    notify_baseline_row_trampoline::<Self, F> as *const (),
553                )),
554                Box_::into_raw(f),
555            )
556        }
557    }
558
559    #[doc(alias = "column-homogeneous")]
560    fn connect_column_homogeneous_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
561        unsafe extern "C" fn notify_column_homogeneous_trampoline<
562            P: IsA<Grid>,
563            F: Fn(&P) + 'static,
564        >(
565            this: *mut ffi::GtkGrid,
566            _param_spec: glib::ffi::gpointer,
567            f: glib::ffi::gpointer,
568        ) {
569            let f: &F = &*(f as *const F);
570            f(Grid::from_glib_borrow(this).unsafe_cast_ref())
571        }
572        unsafe {
573            let f: Box_<F> = Box_::new(f);
574            connect_raw(
575                self.as_ptr() as *mut _,
576                c"notify::column-homogeneous".as_ptr() as *const _,
577                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
578                    notify_column_homogeneous_trampoline::<Self, F> as *const (),
579                )),
580                Box_::into_raw(f),
581            )
582        }
583    }
584
585    #[doc(alias = "column-spacing")]
586    fn connect_column_spacing_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
587        unsafe extern "C" fn notify_column_spacing_trampoline<P: IsA<Grid>, F: Fn(&P) + 'static>(
588            this: *mut ffi::GtkGrid,
589            _param_spec: glib::ffi::gpointer,
590            f: glib::ffi::gpointer,
591        ) {
592            let f: &F = &*(f as *const F);
593            f(Grid::from_glib_borrow(this).unsafe_cast_ref())
594        }
595        unsafe {
596            let f: Box_<F> = Box_::new(f);
597            connect_raw(
598                self.as_ptr() as *mut _,
599                c"notify::column-spacing".as_ptr() as *const _,
600                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
601                    notify_column_spacing_trampoline::<Self, F> as *const (),
602                )),
603                Box_::into_raw(f),
604            )
605        }
606    }
607
608    #[doc(alias = "row-homogeneous")]
609    fn connect_row_homogeneous_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
610        unsafe extern "C" fn notify_row_homogeneous_trampoline<
611            P: IsA<Grid>,
612            F: Fn(&P) + 'static,
613        >(
614            this: *mut ffi::GtkGrid,
615            _param_spec: glib::ffi::gpointer,
616            f: glib::ffi::gpointer,
617        ) {
618            let f: &F = &*(f as *const F);
619            f(Grid::from_glib_borrow(this).unsafe_cast_ref())
620        }
621        unsafe {
622            let f: Box_<F> = Box_::new(f);
623            connect_raw(
624                self.as_ptr() as *mut _,
625                c"notify::row-homogeneous".as_ptr() as *const _,
626                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
627                    notify_row_homogeneous_trampoline::<Self, F> as *const (),
628                )),
629                Box_::into_raw(f),
630            )
631        }
632    }
633
634    #[doc(alias = "row-spacing")]
635    fn connect_row_spacing_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
636        unsafe extern "C" fn notify_row_spacing_trampoline<P: IsA<Grid>, F: Fn(&P) + 'static>(
637            this: *mut ffi::GtkGrid,
638            _param_spec: glib::ffi::gpointer,
639            f: glib::ffi::gpointer,
640        ) {
641            let f: &F = &*(f as *const F);
642            f(Grid::from_glib_borrow(this).unsafe_cast_ref())
643        }
644        unsafe {
645            let f: Box_<F> = Box_::new(f);
646            connect_raw(
647                self.as_ptr() as *mut _,
648                c"notify::row-spacing".as_ptr() as *const _,
649                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
650                    notify_row_spacing_trampoline::<Self, F> as *const (),
651                )),
652                Box_::into_raw(f),
653            )
654        }
655    }
656}
657
658impl<O: IsA<Grid>> GridExt for O {}