gtk/auto/
stack_switcher.rs1use crate::{Box, Buildable, Container, Orientable, Stack, Widget};
6use glib::{
7 prelude::*,
8 signal::{connect_raw, SignalHandlerId},
9 translate::*,
10};
11use std::{boxed::Box as Box_, fmt, mem::transmute};
12
13glib::wrapper! {
14 #[doc(alias = "GtkStackSwitcher")]
15 pub struct StackSwitcher(Object<ffi::GtkStackSwitcher, ffi::GtkStackSwitcherClass>) @extends Box, Container, Widget, @implements Buildable, Orientable;
16
17 match fn {
18 type_ => || ffi::gtk_stack_switcher_get_type(),
19 }
20}
21
22impl StackSwitcher {
23 pub const NONE: Option<&'static StackSwitcher> = None;
24
25 #[doc(alias = "gtk_stack_switcher_new")]
26 pub fn new() -> StackSwitcher {
27 assert_initialized_main_thread!();
28 unsafe { Widget::from_glib_none(ffi::gtk_stack_switcher_new()).unsafe_cast() }
29 }
30}
31
32impl Default for StackSwitcher {
33 fn default() -> Self {
34 Self::new()
35 }
36}
37
38mod sealed {
39 pub trait Sealed {}
40 impl<T: super::IsA<super::StackSwitcher>> Sealed for T {}
41}
42
43pub trait StackSwitcherExt: IsA<StackSwitcher> + sealed::Sealed + 'static {
44 #[doc(alias = "gtk_stack_switcher_get_stack")]
45 #[doc(alias = "get_stack")]
46 fn stack(&self) -> Option<Stack> {
47 unsafe {
48 from_glib_none(ffi::gtk_stack_switcher_get_stack(
49 self.as_ref().to_glib_none().0,
50 ))
51 }
52 }
53
54 #[doc(alias = "gtk_stack_switcher_set_stack")]
55 fn set_stack(&self, stack: Option<&impl IsA<Stack>>) {
56 unsafe {
57 ffi::gtk_stack_switcher_set_stack(
58 self.as_ref().to_glib_none().0,
59 stack.map(|p| p.as_ref()).to_glib_none().0,
60 );
61 }
62 }
63
64 #[doc(alias = "stack")]
65 fn connect_stack_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
66 unsafe extern "C" fn notify_stack_trampoline<P: IsA<StackSwitcher>, F: Fn(&P) + 'static>(
67 this: *mut ffi::GtkStackSwitcher,
68 _param_spec: glib::ffi::gpointer,
69 f: glib::ffi::gpointer,
70 ) {
71 let f: &F = &*(f as *const F);
72 f(StackSwitcher::from_glib_borrow(this).unsafe_cast_ref())
73 }
74 unsafe {
75 let f: Box_<F> = Box_::new(f);
76 connect_raw(
77 self.as_ptr() as *mut _,
78 b"notify::stack\0".as_ptr() as *const _,
79 Some(transmute::<_, unsafe extern "C" fn()>(
80 notify_stack_trampoline::<Self, F> as *const (),
81 )),
82 Box_::into_raw(f),
83 )
84 }
85 }
86}
87
88impl<O: IsA<StackSwitcher>> StackSwitcherExt for O {}
89
90impl fmt::Display for StackSwitcher {
91 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
92 f.write_str("StackSwitcher")
93 }
94}