libadwaita/auto/
toast_overlay.rs1use crate::{ffi, Toast};
7use glib::{
8 prelude::*,
9 signal::{connect_raw, SignalHandlerId},
10 translate::*,
11};
12use std::boxed::Box as Box_;
13
14glib::wrapper! {
15 #[doc(alias = "AdwToastOverlay")]
16 pub struct ToastOverlay(Object<ffi::AdwToastOverlay, ffi::AdwToastOverlayClass>) @extends gtk::Widget, @implements gtk::Accessible, gtk::Buildable, gtk::ConstraintTarget;
17
18 match fn {
19 type_ => || ffi::adw_toast_overlay_get_type(),
20 }
21}
22
23impl ToastOverlay {
24 #[doc(alias = "adw_toast_overlay_new")]
25 pub fn new() -> ToastOverlay {
26 assert_initialized_main_thread!();
27 unsafe { gtk::Widget::from_glib_none(ffi::adw_toast_overlay_new()).unsafe_cast() }
28 }
29
30 #[doc(alias = "adw_toast_overlay_add_toast")]
31 pub fn add_toast(&self, toast: Toast) {
32 unsafe {
33 ffi::adw_toast_overlay_add_toast(self.to_glib_none().0, toast.into_glib_ptr());
34 }
35 }
36
37 #[cfg(feature = "v1_7")]
38 #[cfg_attr(docsrs, doc(cfg(feature = "v1_7")))]
39 #[doc(alias = "adw_toast_overlay_dismiss_all")]
40 pub fn dismiss_all(&self) {
41 unsafe {
42 ffi::adw_toast_overlay_dismiss_all(self.to_glib_none().0);
43 }
44 }
45
46 #[doc(alias = "adw_toast_overlay_get_child")]
47 #[doc(alias = "get_child")]
48 pub fn child(&self) -> Option<gtk::Widget> {
49 unsafe { from_glib_none(ffi::adw_toast_overlay_get_child(self.to_glib_none().0)) }
50 }
51
52 #[doc(alias = "adw_toast_overlay_set_child")]
53 #[doc(alias = "child")]
54 pub fn set_child(&self, child: Option<&impl IsA<gtk::Widget>>) {
55 unsafe {
56 ffi::adw_toast_overlay_set_child(
57 self.to_glib_none().0,
58 child.map(|p| p.as_ref()).to_glib_none().0,
59 );
60 }
61 }
62
63 #[doc(alias = "child")]
64 pub fn connect_child_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
65 unsafe extern "C" fn notify_child_trampoline<F: Fn(&ToastOverlay) + 'static>(
66 this: *mut ffi::AdwToastOverlay,
67 _param_spec: glib::ffi::gpointer,
68 f: glib::ffi::gpointer,
69 ) {
70 let f: &F = &*(f as *const F);
71 f(&from_glib_borrow(this))
72 }
73 unsafe {
74 let f: Box_<F> = Box_::new(f);
75 connect_raw(
76 self.as_ptr() as *mut _,
77 c"notify::child".as_ptr() as *const _,
78 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
79 notify_child_trampoline::<F> as *const (),
80 )),
81 Box_::into_raw(f),
82 )
83 }
84 }
85}
86
87impl Default for ToastOverlay {
88 fn default() -> Self {
89 Self::new()
90 }
91}