[go: up one dir, main page]

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