libadwaita/auto/
shortcut_label.rs1use crate::ffi;
7use glib::{
8 prelude::*,
9 signal::{connect_raw, SignalHandlerId},
10 translate::*,
11};
12use std::boxed::Box as Box_;
13
14glib::wrapper! {
15 #[doc(alias = "AdwShortcutLabel")]
16 pub struct ShortcutLabel(Object<ffi::AdwShortcutLabel, ffi::AdwShortcutLabelClass>) @extends gtk::Widget, @implements gtk::Accessible, gtk::Buildable, gtk::ConstraintTarget;
17
18 match fn {
19 type_ => || ffi::adw_shortcut_label_get_type(),
20 }
21}
22
23impl ShortcutLabel {
24 #[doc(alias = "adw_shortcut_label_new")]
25 pub fn new(accelerator: &str) -> ShortcutLabel {
26 assert_initialized_main_thread!();
27 unsafe {
28 gtk::Widget::from_glib_none(ffi::adw_shortcut_label_new(accelerator.to_glib_none().0))
29 .unsafe_cast()
30 }
31 }
32
33 #[doc(alias = "adw_shortcut_label_get_accelerator")]
34 #[doc(alias = "get_accelerator")]
35 pub fn accelerator(&self) -> glib::GString {
36 unsafe {
37 from_glib_none(ffi::adw_shortcut_label_get_accelerator(
38 self.to_glib_none().0,
39 ))
40 }
41 }
42
43 #[doc(alias = "adw_shortcut_label_get_disabled_text")]
44 #[doc(alias = "get_disabled_text")]
45 #[doc(alias = "disabled-text")]
46 pub fn disabled_text(&self) -> glib::GString {
47 unsafe {
48 from_glib_none(ffi::adw_shortcut_label_get_disabled_text(
49 self.to_glib_none().0,
50 ))
51 }
52 }
53
54 #[doc(alias = "adw_shortcut_label_set_accelerator")]
55 #[doc(alias = "accelerator")]
56 pub fn set_accelerator(&self, accelerator: &str) {
57 unsafe {
58 ffi::adw_shortcut_label_set_accelerator(
59 self.to_glib_none().0,
60 accelerator.to_glib_none().0,
61 );
62 }
63 }
64
65 #[doc(alias = "adw_shortcut_label_set_disabled_text")]
66 #[doc(alias = "disabled-text")]
67 pub fn set_disabled_text(&self, disabled_text: &str) {
68 unsafe {
69 ffi::adw_shortcut_label_set_disabled_text(
70 self.to_glib_none().0,
71 disabled_text.to_glib_none().0,
72 );
73 }
74 }
75
76 #[cfg(feature = "v1_8")]
77 #[cfg_attr(docsrs, doc(cfg(feature = "v1_8")))]
78 #[doc(alias = "accelerator")]
79 pub fn connect_accelerator_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
80 unsafe extern "C" fn notify_accelerator_trampoline<F: Fn(&ShortcutLabel) + 'static>(
81 this: *mut ffi::AdwShortcutLabel,
82 _param_spec: glib::ffi::gpointer,
83 f: glib::ffi::gpointer,
84 ) {
85 let f: &F = &*(f as *const F);
86 f(&from_glib_borrow(this))
87 }
88 unsafe {
89 let f: Box_<F> = Box_::new(f);
90 connect_raw(
91 self.as_ptr() as *mut _,
92 c"notify::accelerator".as_ptr() as *const _,
93 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
94 notify_accelerator_trampoline::<F> as *const (),
95 )),
96 Box_::into_raw(f),
97 )
98 }
99 }
100
101 #[cfg(feature = "v1_8")]
102 #[cfg_attr(docsrs, doc(cfg(feature = "v1_8")))]
103 #[doc(alias = "disabled-text")]
104 pub fn connect_disabled_text_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
105 unsafe extern "C" fn notify_disabled_text_trampoline<F: Fn(&ShortcutLabel) + 'static>(
106 this: *mut ffi::AdwShortcutLabel,
107 _param_spec: glib::ffi::gpointer,
108 f: glib::ffi::gpointer,
109 ) {
110 let f: &F = &*(f as *const F);
111 f(&from_glib_borrow(this))
112 }
113 unsafe {
114 let f: Box_<F> = Box_::new(f);
115 connect_raw(
116 self.as_ptr() as *mut _,
117 c"notify::disabled-text".as_ptr() as *const _,
118 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
119 notify_disabled_text_trampoline::<F> as *const (),
120 )),
121 Box_::into_raw(f),
122 )
123 }
124 }
125}