Skip to main content

gtk/auto/
size_group.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::{Buildable, SizeGroupMode, Widget, ffi};
6use glib::{
7    prelude::*,
8    signal::{SignalHandlerId, connect_raw},
9    translate::*,
10};
11use std::boxed::Box as Box_;
12
13glib::wrapper! {
14    ///
15    /// ]|
16    ///
17    /// ## Properties
18    ///
19    ///
20    /// #### `ignore-hidden`
21    ///  If [`true`], unmapped widgets are ignored when determining
22    /// the size of the group.
23    ///
24    /// Readable | Writable
25    ///
26    ///
27    /// #### `mode`
28    ///  Readable | Writable
29    ///
30    /// # Implements
31    ///
32    /// [`SizeGroupExt`][trait@crate::prelude::SizeGroupExt], [`trait@glib::ObjectExt`], [`BuildableExt`][trait@crate::prelude::BuildableExt], [`BuildableExtManual`][trait@crate::prelude::BuildableExtManual]
33    #[doc(alias = "GtkSizeGroup")]
34    pub struct SizeGroup(Object<ffi::GtkSizeGroup, ffi::GtkSizeGroupClass>) @implements Buildable;
35
36    match fn {
37        type_ => || ffi::gtk_size_group_get_type(),
38    }
39}
40
41impl SizeGroup {
42    pub const NONE: Option<&'static SizeGroup> = None;
43
44    /// Create a new [`SizeGroup`][crate::SizeGroup].
45    /// ## `mode`
46    /// the mode for the new size group.
47    ///
48    /// # Returns
49    ///
50    /// a newly created [`SizeGroup`][crate::SizeGroup]
51    #[doc(alias = "gtk_size_group_new")]
52    pub fn new(mode: SizeGroupMode) -> SizeGroup {
53        assert_initialized_main_thread!();
54        unsafe { from_glib_full(ffi::gtk_size_group_new(mode.into_glib())) }
55    }
56
57    // rustdoc-stripper-ignore-next
58    /// Creates a new builder-pattern struct instance to construct [`SizeGroup`] objects.
59    ///
60    /// This method returns an instance of [`SizeGroupBuilder`](crate::builders::SizeGroupBuilder) which can be used to create [`SizeGroup`] objects.
61    pub fn builder() -> SizeGroupBuilder {
62        SizeGroupBuilder::new()
63    }
64}
65
66impl Default for SizeGroup {
67    fn default() -> Self {
68        glib::object::Object::new::<Self>()
69    }
70}
71
72// rustdoc-stripper-ignore-next
73/// A [builder-pattern] type to construct [`SizeGroup`] objects.
74///
75/// [builder-pattern]: https://doc.rust-lang.org/1.0.0/style/ownership/builders.html
76#[must_use = "The builder must be built to be used"]
77pub struct SizeGroupBuilder {
78    builder: glib::object::ObjectBuilder<'static, SizeGroup>,
79}
80
81impl SizeGroupBuilder {
82    fn new() -> Self {
83        Self {
84            builder: glib::object::Object::builder(),
85        }
86    }
87
88    pub fn mode(self, mode: SizeGroupMode) -> Self {
89        Self {
90            builder: self.builder.property("mode", mode),
91        }
92    }
93
94    // rustdoc-stripper-ignore-next
95    /// Build the [`SizeGroup`].
96    #[must_use = "Building the object from the builder is usually expensive and is not expected to have side effects"]
97    pub fn build(self) -> SizeGroup {
98        assert_initialized_main_thread!();
99        self.builder.build()
100    }
101}
102
103/// Trait containing all [`struct@SizeGroup`] methods.
104///
105/// # Implementors
106///
107/// [`SizeGroup`][struct@crate::SizeGroup]
108pub trait SizeGroupExt: IsA<SizeGroup> + 'static {
109    /// Adds a widget to a [`SizeGroup`][crate::SizeGroup]. In the future, the requisition
110    /// of the widget will be determined as the maximum of its requisition
111    /// and the requisition of the other widgets in the size group.
112    /// Whether this applies horizontally, vertically, or in both directions
113    /// depends on the mode of the size group. See [`set_mode()`][Self::set_mode()].
114    ///
115    /// When the widget is destroyed or no longer referenced elsewhere, it will
116    /// be removed from the size group.
117    /// ## `widget`
118    /// the [`Widget`][crate::Widget] to add
119    #[doc(alias = "gtk_size_group_add_widget")]
120    fn add_widget(&self, widget: &impl IsA<Widget>) {
121        unsafe {
122            ffi::gtk_size_group_add_widget(
123                self.as_ref().to_glib_none().0,
124                widget.as_ref().to_glib_none().0,
125            );
126        }
127    }
128
129    /// Gets the current mode of the size group. See [`set_mode()`][Self::set_mode()].
130    ///
131    /// # Returns
132    ///
133    /// the current mode of the size group.
134    #[doc(alias = "gtk_size_group_get_mode")]
135    #[doc(alias = "get_mode")]
136    fn mode(&self) -> SizeGroupMode {
137        unsafe { from_glib(ffi::gtk_size_group_get_mode(self.as_ref().to_glib_none().0)) }
138    }
139
140    /// Returns the list of widgets associated with `self`.
141    ///
142    /// # Returns
143    ///
144    /// a `GSList` of
145    ///  widgets. The list is owned by GTK+ and should not be modified.
146    #[doc(alias = "gtk_size_group_get_widgets")]
147    #[doc(alias = "get_widgets")]
148    fn widgets(&self) -> Vec<Widget> {
149        unsafe {
150            FromGlibPtrContainer::from_glib_none(ffi::gtk_size_group_get_widgets(
151                self.as_ref().to_glib_none().0,
152            ))
153        }
154    }
155
156    /// Removes a widget from a [`SizeGroup`][crate::SizeGroup].
157    /// ## `widget`
158    /// the [`Widget`][crate::Widget] to remove
159    #[doc(alias = "gtk_size_group_remove_widget")]
160    fn remove_widget(&self, widget: &impl IsA<Widget>) {
161        unsafe {
162            ffi::gtk_size_group_remove_widget(
163                self.as_ref().to_glib_none().0,
164                widget.as_ref().to_glib_none().0,
165            );
166        }
167    }
168
169    /// Sets the [`SizeGroupMode`][crate::SizeGroupMode] of the size group. The mode of the size
170    /// group determines whether the widgets in the size group should
171    /// all have the same horizontal requisition ([`SizeGroupMode::Horizontal`][crate::SizeGroupMode::Horizontal])
172    /// all have the same vertical requisition ([`SizeGroupMode::Vertical`][crate::SizeGroupMode::Vertical]),
173    /// or should all have the same requisition in both directions
174    /// ([`SizeGroupMode::Both`][crate::SizeGroupMode::Both]).
175    /// ## `mode`
176    /// the mode to set for the size group.
177    #[doc(alias = "gtk_size_group_set_mode")]
178    #[doc(alias = "mode")]
179    fn set_mode(&self, mode: SizeGroupMode) {
180        unsafe {
181            ffi::gtk_size_group_set_mode(self.as_ref().to_glib_none().0, mode.into_glib());
182        }
183    }
184
185    #[doc(alias = "mode")]
186    fn connect_mode_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
187        unsafe extern "C" fn notify_mode_trampoline<P: IsA<SizeGroup>, F: Fn(&P) + 'static>(
188            this: *mut ffi::GtkSizeGroup,
189            _param_spec: glib::ffi::gpointer,
190            f: glib::ffi::gpointer,
191        ) {
192            unsafe {
193                let f: &F = &*(f as *const F);
194                f(SizeGroup::from_glib_borrow(this).unsafe_cast_ref())
195            }
196        }
197        unsafe {
198            let f: Box_<F> = Box_::new(f);
199            connect_raw(
200                self.as_ptr() as *mut _,
201                c"notify::mode".as_ptr(),
202                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
203                    notify_mode_trampoline::<Self, F> as *const (),
204                )),
205                Box_::into_raw(f),
206            )
207        }
208    }
209}
210
211impl<O: IsA<SizeGroup>> SizeGroupExt for O {}