Skip to main content

gtk/auto/
stack_switcher.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::{Box, Buildable, Container, Orientable, Stack, Widget, ffi};
6use glib::{
7    prelude::*,
8    signal::{SignalHandlerId, connect_raw},
9    translate::*,
10};
11use std::boxed::Box as Box_;
12
13glib::wrapper! {
14    /// The GtkStackSwitcher widget acts as a controller for a
15    /// [`Stack`][crate::Stack]; it shows a row of buttons to switch between
16    /// the various pages of the associated stack widget.
17    ///
18    /// All the content for the buttons comes from the child properties
19    /// of the [`Stack`][crate::Stack]; the button visibility in a [`StackSwitcher`][crate::StackSwitcher]
20    /// widget is controlled by the visibility of the child in the
21    /// [`Stack`][crate::Stack].
22    ///
23    /// It is possible to associate multiple [`StackSwitcher`][crate::StackSwitcher] widgets
24    /// with the same [`Stack`][crate::Stack] widget.
25    ///
26    /// The GtkStackSwitcher widget was added in 3.10.
27    ///
28    /// # CSS nodes
29    ///
30    /// GtkStackSwitcher has a single CSS node named stackswitcher and
31    /// style class .stack-switcher.
32    ///
33    /// When circumstances require it, GtkStackSwitcher adds the
34    /// .needs-attention style class to the widgets representing the
35    /// stack pages.
36    ///
37    /// ## Properties
38    ///
39    ///
40    /// #### `icon-size`
41    ///  Use the "icon-size" property to change the size of the image displayed
42    /// when a [`StackSwitcher`][crate::StackSwitcher] is displaying icons.
43    ///
44    /// Readable | Writable
45    ///
46    ///
47    /// #### `stack`
48    ///  Readable | Writable | Construct
49    /// <details><summary><h4>Box</h4></summary>
50    ///
51    ///
52    /// #### `baseline-position`
53    ///  Readable | Writable
54    ///
55    ///
56    /// #### `homogeneous`
57    ///  Readable | Writable
58    ///
59    ///
60    /// #### `spacing`
61    ///  Readable | Writable
62    /// </details>
63    /// <details><summary><h4>Container</h4></summary>
64    ///
65    ///
66    /// #### `border-width`
67    ///  Readable | Writable
68    ///
69    ///
70    /// #### `child`
71    ///  Writable
72    ///
73    ///
74    /// #### `resize-mode`
75    ///  Readable | Writable
76    /// </details>
77    /// <details><summary><h4>Widget</h4></summary>
78    ///
79    ///
80    /// #### `app-paintable`
81    ///  Readable | Writable
82    ///
83    ///
84    /// #### `can-default`
85    ///  Readable | Writable
86    ///
87    ///
88    /// #### `can-focus`
89    ///  Readable | Writable
90    ///
91    ///
92    /// #### `composite-child`
93    ///  Readable
94    ///
95    ///
96    /// #### `double-buffered`
97    ///  Whether the widget is double buffered.
98    ///
99    /// Readable | Writable
100    ///
101    ///
102    /// #### `events`
103    ///  Readable | Writable
104    ///
105    ///
106    /// #### `expand`
107    ///  Whether to expand in both directions. Setting this sets both [`hexpand`][struct@crate::Widget#hexpand] and [`vexpand`][struct@crate::Widget#vexpand]
108    ///
109    /// Readable | Writable
110    ///
111    ///
112    /// #### `focus-on-click`
113    ///  Whether the widget should grab focus when it is clicked with the mouse.
114    ///
115    /// This property is only relevant for widgets that can take focus.
116    ///
117    /// Before 3.20, several widgets (GtkButton, GtkFileChooserButton,
118    /// GtkComboBox) implemented this property individually.
119    ///
120    /// Readable | Writable
121    ///
122    ///
123    /// #### `halign`
124    ///  How to distribute horizontal space if widget gets extra space, see [`Align`][crate::Align]
125    ///
126    /// Readable | Writable
127    ///
128    ///
129    /// #### `has-default`
130    ///  Readable | Writable
131    ///
132    ///
133    /// #### `has-focus`
134    ///  Readable | Writable
135    ///
136    ///
137    /// #### `has-tooltip`
138    ///  Enables or disables the emission of [`query-tooltip`][struct@crate::Widget#query-tooltip] on `widget`.
139    /// A value of [`true`] indicates that `widget` can have a tooltip, in this case
140    /// the widget will be queried using [`query-tooltip`][struct@crate::Widget#query-tooltip] to determine
141    /// whether it will provide a tooltip or not.
142    ///
143    /// Note that setting this property to [`true`] for the first time will change
144    /// the event masks of the GdkWindows of this widget to include leave-notify
145    /// and motion-notify events. This cannot and will not be undone when the
146    /// property is set to [`false`] again.
147    ///
148    /// Readable | Writable
149    ///
150    ///
151    /// #### `height-request`
152    ///  Readable | Writable
153    ///
154    ///
155    /// #### `hexpand`
156    ///  Whether to expand horizontally. See [`WidgetExt::set_hexpand()`][crate::prelude::WidgetExt::set_hexpand()].
157    ///
158    /// Readable | Writable
159    ///
160    ///
161    /// #### `hexpand-set`
162    ///  Whether to use the [`hexpand`][struct@crate::Widget#hexpand] property. See [`WidgetExt::is_hexpand_set()`][crate::prelude::WidgetExt::is_hexpand_set()].
163    ///
164    /// Readable | Writable
165    ///
166    ///
167    /// #### `is-focus`
168    ///  Readable | Writable
169    ///
170    ///
171    /// #### `margin`
172    ///  Sets all four sides' margin at once. If read, returns max
173    /// margin on any side.
174    ///
175    /// Readable | Writable
176    ///
177    ///
178    /// #### `margin-bottom`
179    ///  Margin on bottom side of widget.
180    ///
181    /// This property adds margin outside of the widget's normal size
182    /// request, the margin will be added in addition to the size from
183    /// [`WidgetExt::set_size_request()`][crate::prelude::WidgetExt::set_size_request()] for example.
184    ///
185    /// Readable | Writable
186    ///
187    ///
188    /// #### `margin-end`
189    ///  Margin on end of widget, horizontally. This property supports
190    /// left-to-right and right-to-left text directions.
191    ///
192    /// This property adds margin outside of the widget's normal size
193    /// request, the margin will be added in addition to the size from
194    /// [`WidgetExt::set_size_request()`][crate::prelude::WidgetExt::set_size_request()] for example.
195    ///
196    /// Readable | Writable
197    ///
198    ///
199    /// #### `margin-left`
200    ///  Margin on left side of widget.
201    ///
202    /// This property adds margin outside of the widget's normal size
203    /// request, the margin will be added in addition to the size from
204    /// [`WidgetExt::set_size_request()`][crate::prelude::WidgetExt::set_size_request()] for example.
205    ///
206    /// Readable | Writable
207    ///
208    ///
209    /// #### `margin-right`
210    ///  Margin on right side of widget.
211    ///
212    /// This property adds margin outside of the widget's normal size
213    /// request, the margin will be added in addition to the size from
214    /// [`WidgetExt::set_size_request()`][crate::prelude::WidgetExt::set_size_request()] for example.
215    ///
216    /// Readable | Writable
217    ///
218    ///
219    /// #### `margin-start`
220    ///  Margin on start of widget, horizontally. This property supports
221    /// left-to-right and right-to-left text directions.
222    ///
223    /// This property adds margin outside of the widget's normal size
224    /// request, the margin will be added in addition to the size from
225    /// [`WidgetExt::set_size_request()`][crate::prelude::WidgetExt::set_size_request()] for example.
226    ///
227    /// Readable | Writable
228    ///
229    ///
230    /// #### `margin-top`
231    ///  Margin on top side of widget.
232    ///
233    /// This property adds margin outside of the widget's normal size
234    /// request, the margin will be added in addition to the size from
235    /// [`WidgetExt::set_size_request()`][crate::prelude::WidgetExt::set_size_request()] for example.
236    ///
237    /// Readable | Writable
238    ///
239    ///
240    /// #### `name`
241    ///  Readable | Writable
242    ///
243    ///
244    /// #### `no-show-all`
245    ///  Readable | Writable
246    ///
247    ///
248    /// #### `opacity`
249    ///  The requested opacity of the widget. See [`WidgetExt::set_opacity()`][crate::prelude::WidgetExt::set_opacity()] for
250    /// more details about window opacity.
251    ///
252    /// Before 3.8 this was only available in GtkWindow
253    ///
254    /// Readable | Writable
255    ///
256    ///
257    /// #### `parent`
258    ///  Readable | Writable
259    ///
260    ///
261    /// #### `receives-default`
262    ///  Readable | Writable
263    ///
264    ///
265    /// #### `scale-factor`
266    ///  The scale factor of the widget. See [`WidgetExt::scale_factor()`][crate::prelude::WidgetExt::scale_factor()] for
267    /// more details about widget scaling.
268    ///
269    /// Readable
270    ///
271    ///
272    /// #### `sensitive`
273    ///  Readable | Writable
274    ///
275    ///
276    /// #### `style`
277    ///  The style of the widget, which contains information about how it will look (colors, etc).
278    ///
279    /// Readable | Writable
280    ///
281    ///
282    /// #### `tooltip-markup`
283    ///  Sets the text of tooltip to be the given string, which is marked up
284    /// with the [Pango text markup language][PangoMarkupFormat].
285    /// Also see [`Tooltip::set_markup()`][crate::Tooltip::set_markup()].
286    ///
287    /// This is a convenience property which will take care of getting the
288    /// tooltip shown if the given string is not [`None`]: [`has-tooltip`][struct@crate::Widget#has-tooltip]
289    /// will automatically be set to [`true`] and there will be taken care of
290    /// [`query-tooltip`][struct@crate::Widget#query-tooltip] in the default signal handler.
291    ///
292    /// Note that if both [`tooltip-text`][struct@crate::Widget#tooltip-text] and [`tooltip-markup`][struct@crate::Widget#tooltip-markup]
293    /// are set, the last one wins.
294    ///
295    /// Readable | Writable
296    ///
297    ///
298    /// #### `tooltip-text`
299    ///  Sets the text of tooltip to be the given string.
300    ///
301    /// Also see [`Tooltip::set_text()`][crate::Tooltip::set_text()].
302    ///
303    /// This is a convenience property which will take care of getting the
304    /// tooltip shown if the given string is not [`None`]: [`has-tooltip`][struct@crate::Widget#has-tooltip]
305    /// will automatically be set to [`true`] and there will be taken care of
306    /// [`query-tooltip`][struct@crate::Widget#query-tooltip] in the default signal handler.
307    ///
308    /// Note that if both [`tooltip-text`][struct@crate::Widget#tooltip-text] and [`tooltip-markup`][struct@crate::Widget#tooltip-markup]
309    /// are set, the last one wins.
310    ///
311    /// Readable | Writable
312    ///
313    ///
314    /// #### `valign`
315    ///  How to distribute vertical space if widget gets extra space, see [`Align`][crate::Align]
316    ///
317    /// Readable | Writable
318    ///
319    ///
320    /// #### `vexpand`
321    ///  Whether to expand vertically. See [`WidgetExt::set_vexpand()`][crate::prelude::WidgetExt::set_vexpand()].
322    ///
323    /// Readable | Writable
324    ///
325    ///
326    /// #### `vexpand-set`
327    ///  Whether to use the [`vexpand`][struct@crate::Widget#vexpand] property. See [`WidgetExt::is_vexpand_set()`][crate::prelude::WidgetExt::is_vexpand_set()].
328    ///
329    /// Readable | Writable
330    ///
331    ///
332    /// #### `visible`
333    ///  Readable | Writable
334    ///
335    ///
336    /// #### `width-request`
337    ///  Readable | Writable
338    ///
339    ///
340    /// #### `window`
341    ///  The widget's window if it is realized, [`None`] otherwise.
342    ///
343    /// Readable
344    /// </details>
345    /// <details><summary><h4>Orientable</h4></summary>
346    ///
347    ///
348    /// #### `orientation`
349    ///  The orientation of the orientable.
350    ///
351    /// Readable | Writable
352    /// </details>
353    ///
354    /// # Implements
355    ///
356    /// [`StackSwitcherExt`][trait@crate::prelude::StackSwitcherExt], [`BoxExt`][trait@crate::prelude::BoxExt], [`ContainerExt`][trait@crate::prelude::ContainerExt], [`WidgetExt`][trait@crate::prelude::WidgetExt], [`trait@glib::ObjectExt`], [`BuildableExt`][trait@crate::prelude::BuildableExt], [`OrientableExt`][trait@crate::prelude::OrientableExt], [`StackSwitcherExtManual`][trait@crate::prelude::StackSwitcherExtManual], [`ContainerExtManual`][trait@crate::prelude::ContainerExtManual], [`WidgetExtManual`][trait@crate::prelude::WidgetExtManual], [`BuildableExtManual`][trait@crate::prelude::BuildableExtManual]
357    #[doc(alias = "GtkStackSwitcher")]
358    pub struct StackSwitcher(Object<ffi::GtkStackSwitcher, ffi::GtkStackSwitcherClass>) @extends Box, Container, Widget, @implements Buildable, Orientable;
359
360    match fn {
361        type_ => || ffi::gtk_stack_switcher_get_type(),
362    }
363}
364
365impl StackSwitcher {
366    pub const NONE: Option<&'static StackSwitcher> = None;
367
368    /// Create a new [`StackSwitcher`][crate::StackSwitcher].
369    ///
370    /// # Returns
371    ///
372    /// a new [`StackSwitcher`][crate::StackSwitcher].
373    #[doc(alias = "gtk_stack_switcher_new")]
374    pub fn new() -> StackSwitcher {
375        assert_initialized_main_thread!();
376        unsafe { Widget::from_glib_none(ffi::gtk_stack_switcher_new()).unsafe_cast() }
377    }
378}
379
380impl Default for StackSwitcher {
381    fn default() -> Self {
382        Self::new()
383    }
384}
385
386/// Trait containing all [`struct@StackSwitcher`] methods.
387///
388/// # Implementors
389///
390/// [`StackSwitcher`][struct@crate::StackSwitcher]
391pub trait StackSwitcherExt: IsA<StackSwitcher> + 'static {
392    /// Retrieves the stack.
393    /// See [`set_stack()`][Self::set_stack()].
394    ///
395    /// # Returns
396    ///
397    /// the stack, or [`None`] if
398    ///  none has been set explicitly.
399    #[doc(alias = "gtk_stack_switcher_get_stack")]
400    #[doc(alias = "get_stack")]
401    fn stack(&self) -> Option<Stack> {
402        unsafe {
403            from_glib_none(ffi::gtk_stack_switcher_get_stack(
404                self.as_ref().to_glib_none().0,
405            ))
406        }
407    }
408
409    /// Sets the stack to control.
410    /// ## `stack`
411    /// a [`Stack`][crate::Stack]
412    #[doc(alias = "gtk_stack_switcher_set_stack")]
413    #[doc(alias = "stack")]
414    fn set_stack(&self, stack: Option<&impl IsA<Stack>>) {
415        unsafe {
416            ffi::gtk_stack_switcher_set_stack(
417                self.as_ref().to_glib_none().0,
418                stack.map(|p| p.as_ref()).to_glib_none().0,
419            );
420        }
421    }
422
423    #[doc(alias = "stack")]
424    fn connect_stack_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
425        unsafe extern "C" fn notify_stack_trampoline<P: IsA<StackSwitcher>, F: Fn(&P) + 'static>(
426            this: *mut ffi::GtkStackSwitcher,
427            _param_spec: glib::ffi::gpointer,
428            f: glib::ffi::gpointer,
429        ) {
430            unsafe {
431                let f: &F = &*(f as *const F);
432                f(StackSwitcher::from_glib_borrow(this).unsafe_cast_ref())
433            }
434        }
435        unsafe {
436            let f: Box_<F> = Box_::new(f);
437            connect_raw(
438                self.as_ptr() as *mut _,
439                c"notify::stack".as_ptr(),
440                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
441                    notify_stack_trampoline::<Self, F> as *const (),
442                )),
443                Box_::into_raw(f),
444            )
445        }
446    }
447}
448
449impl<O: IsA<StackSwitcher>> StackSwitcherExt for O {}