1use 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 = "AdwToggle")]
16 pub struct Toggle(Object<ffi::AdwToggle, ffi::AdwToggleClass>);
17
18 match fn {
19 type_ => || ffi::adw_toggle_get_type(),
20 }
21}
22
23impl Toggle {
24 #[doc(alias = "adw_toggle_new")]
25 pub fn new() -> Toggle {
26 assert_initialized_main_thread!();
27 unsafe { from_glib_full(ffi::adw_toggle_new()) }
28 }
29
30 pub fn builder() -> ToggleBuilder {
35 ToggleBuilder::new()
36 }
37
38 #[doc(alias = "adw_toggle_get_child")]
39 #[doc(alias = "get_child")]
40 pub fn child(&self) -> Option<gtk::Widget> {
41 unsafe { from_glib_none(ffi::adw_toggle_get_child(self.to_glib_none().0)) }
42 }
43
44 #[doc(alias = "adw_toggle_get_enabled")]
45 #[doc(alias = "get_enabled")]
46 #[doc(alias = "enabled")]
47 pub fn is_enabled(&self) -> bool {
48 unsafe { from_glib(ffi::adw_toggle_get_enabled(self.to_glib_none().0)) }
49 }
50
51 #[doc(alias = "adw_toggle_get_icon_name")]
52 #[doc(alias = "get_icon_name")]
53 #[doc(alias = "icon-name")]
54 pub fn icon_name(&self) -> Option<glib::GString> {
55 unsafe { from_glib_none(ffi::adw_toggle_get_icon_name(self.to_glib_none().0)) }
56 }
57
58 #[doc(alias = "adw_toggle_get_index")]
59 #[doc(alias = "get_index")]
60 pub fn index(&self) -> u32 {
61 unsafe { ffi::adw_toggle_get_index(self.to_glib_none().0) }
62 }
63
64 #[doc(alias = "adw_toggle_get_label")]
65 #[doc(alias = "get_label")]
66 pub fn label(&self) -> Option<glib::GString> {
67 unsafe { from_glib_none(ffi::adw_toggle_get_label(self.to_glib_none().0)) }
68 }
69
70 #[doc(alias = "adw_toggle_get_name")]
71 #[doc(alias = "get_name")]
72 pub fn name(&self) -> glib::GString {
73 unsafe { from_glib_none(ffi::adw_toggle_get_name(self.to_glib_none().0)) }
74 }
75
76 #[doc(alias = "adw_toggle_get_tooltip")]
77 #[doc(alias = "get_tooltip")]
78 pub fn tooltip(&self) -> glib::GString {
79 unsafe { from_glib_none(ffi::adw_toggle_get_tooltip(self.to_glib_none().0)) }
80 }
81
82 #[doc(alias = "adw_toggle_get_use_underline")]
83 #[doc(alias = "get_use_underline")]
84 #[doc(alias = "use-underline")]
85 pub fn uses_underline(&self) -> bool {
86 unsafe { from_glib(ffi::adw_toggle_get_use_underline(self.to_glib_none().0)) }
87 }
88
89 #[doc(alias = "adw_toggle_set_child")]
90 #[doc(alias = "child")]
91 pub fn set_child(&self, child: Option<&impl IsA<gtk::Widget>>) {
92 unsafe {
93 ffi::adw_toggle_set_child(
94 self.to_glib_none().0,
95 child.map(|p| p.as_ref()).to_glib_none().0,
96 );
97 }
98 }
99
100 #[doc(alias = "adw_toggle_set_enabled")]
101 #[doc(alias = "enabled")]
102 pub fn set_enabled(&self, enabled: bool) {
103 unsafe {
104 ffi::adw_toggle_set_enabled(self.to_glib_none().0, enabled.into_glib());
105 }
106 }
107
108 #[doc(alias = "adw_toggle_set_icon_name")]
109 #[doc(alias = "icon-name")]
110 pub fn set_icon_name(&self, icon_name: Option<&str>) {
111 unsafe {
112 ffi::adw_toggle_set_icon_name(self.to_glib_none().0, icon_name.to_glib_none().0);
113 }
114 }
115
116 #[doc(alias = "adw_toggle_set_label")]
117 #[doc(alias = "label")]
118 pub fn set_label(&self, label: Option<&str>) {
119 unsafe {
120 ffi::adw_toggle_set_label(self.to_glib_none().0, label.to_glib_none().0);
121 }
122 }
123
124 #[doc(alias = "adw_toggle_set_name")]
125 #[doc(alias = "name")]
126 pub fn set_name(&self, name: Option<&str>) {
127 unsafe {
128 ffi::adw_toggle_set_name(self.to_glib_none().0, name.to_glib_none().0);
129 }
130 }
131
132 #[doc(alias = "adw_toggle_set_tooltip")]
133 #[doc(alias = "tooltip")]
134 pub fn set_tooltip(&self, tooltip: &str) {
135 unsafe {
136 ffi::adw_toggle_set_tooltip(self.to_glib_none().0, tooltip.to_glib_none().0);
137 }
138 }
139
140 #[doc(alias = "adw_toggle_set_use_underline")]
141 #[doc(alias = "use-underline")]
142 pub fn set_use_underline(&self, use_underline: bool) {
143 unsafe {
144 ffi::adw_toggle_set_use_underline(self.to_glib_none().0, use_underline.into_glib());
145 }
146 }
147
148 #[cfg(feature = "v1_7")]
149 #[cfg_attr(docsrs, doc(cfg(feature = "v1_7")))]
150 #[doc(alias = "child")]
151 pub fn connect_child_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
152 unsafe extern "C" fn notify_child_trampoline<F: Fn(&Toggle) + 'static>(
153 this: *mut ffi::AdwToggle,
154 _param_spec: glib::ffi::gpointer,
155 f: glib::ffi::gpointer,
156 ) {
157 let f: &F = &*(f as *const F);
158 f(&from_glib_borrow(this))
159 }
160 unsafe {
161 let f: Box_<F> = Box_::new(f);
162 connect_raw(
163 self.as_ptr() as *mut _,
164 c"notify::child".as_ptr() as *const _,
165 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
166 notify_child_trampoline::<F> as *const (),
167 )),
168 Box_::into_raw(f),
169 )
170 }
171 }
172
173 #[cfg(feature = "v1_7")]
174 #[cfg_attr(docsrs, doc(cfg(feature = "v1_7")))]
175 #[doc(alias = "enabled")]
176 pub fn connect_enabled_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
177 unsafe extern "C" fn notify_enabled_trampoline<F: Fn(&Toggle) + 'static>(
178 this: *mut ffi::AdwToggle,
179 _param_spec: glib::ffi::gpointer,
180 f: glib::ffi::gpointer,
181 ) {
182 let f: &F = &*(f as *const F);
183 f(&from_glib_borrow(this))
184 }
185 unsafe {
186 let f: Box_<F> = Box_::new(f);
187 connect_raw(
188 self.as_ptr() as *mut _,
189 c"notify::enabled".as_ptr() as *const _,
190 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
191 notify_enabled_trampoline::<F> as *const (),
192 )),
193 Box_::into_raw(f),
194 )
195 }
196 }
197
198 #[cfg(feature = "v1_7")]
199 #[cfg_attr(docsrs, doc(cfg(feature = "v1_7")))]
200 #[doc(alias = "icon-name")]
201 pub fn connect_icon_name_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
202 unsafe extern "C" fn notify_icon_name_trampoline<F: Fn(&Toggle) + 'static>(
203 this: *mut ffi::AdwToggle,
204 _param_spec: glib::ffi::gpointer,
205 f: glib::ffi::gpointer,
206 ) {
207 let f: &F = &*(f as *const F);
208 f(&from_glib_borrow(this))
209 }
210 unsafe {
211 let f: Box_<F> = Box_::new(f);
212 connect_raw(
213 self.as_ptr() as *mut _,
214 c"notify::icon-name".as_ptr() as *const _,
215 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
216 notify_icon_name_trampoline::<F> as *const (),
217 )),
218 Box_::into_raw(f),
219 )
220 }
221 }
222
223 #[cfg(feature = "v1_7")]
224 #[cfg_attr(docsrs, doc(cfg(feature = "v1_7")))]
225 #[doc(alias = "label")]
226 pub fn connect_label_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
227 unsafe extern "C" fn notify_label_trampoline<F: Fn(&Toggle) + 'static>(
228 this: *mut ffi::AdwToggle,
229 _param_spec: glib::ffi::gpointer,
230 f: glib::ffi::gpointer,
231 ) {
232 let f: &F = &*(f as *const F);
233 f(&from_glib_borrow(this))
234 }
235 unsafe {
236 let f: Box_<F> = Box_::new(f);
237 connect_raw(
238 self.as_ptr() as *mut _,
239 c"notify::label".as_ptr() as *const _,
240 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
241 notify_label_trampoline::<F> as *const (),
242 )),
243 Box_::into_raw(f),
244 )
245 }
246 }
247
248 #[cfg(feature = "v1_7")]
249 #[cfg_attr(docsrs, doc(cfg(feature = "v1_7")))]
250 #[doc(alias = "name")]
251 pub fn connect_name_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
252 unsafe extern "C" fn notify_name_trampoline<F: Fn(&Toggle) + 'static>(
253 this: *mut ffi::AdwToggle,
254 _param_spec: glib::ffi::gpointer,
255 f: glib::ffi::gpointer,
256 ) {
257 let f: &F = &*(f as *const F);
258 f(&from_glib_borrow(this))
259 }
260 unsafe {
261 let f: Box_<F> = Box_::new(f);
262 connect_raw(
263 self.as_ptr() as *mut _,
264 c"notify::name".as_ptr() as *const _,
265 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
266 notify_name_trampoline::<F> as *const (),
267 )),
268 Box_::into_raw(f),
269 )
270 }
271 }
272
273 #[cfg(feature = "v1_7")]
274 #[cfg_attr(docsrs, doc(cfg(feature = "v1_7")))]
275 #[doc(alias = "tooltip")]
276 pub fn connect_tooltip_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
277 unsafe extern "C" fn notify_tooltip_trampoline<F: Fn(&Toggle) + 'static>(
278 this: *mut ffi::AdwToggle,
279 _param_spec: glib::ffi::gpointer,
280 f: glib::ffi::gpointer,
281 ) {
282 let f: &F = &*(f as *const F);
283 f(&from_glib_borrow(this))
284 }
285 unsafe {
286 let f: Box_<F> = Box_::new(f);
287 connect_raw(
288 self.as_ptr() as *mut _,
289 c"notify::tooltip".as_ptr() as *const _,
290 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
291 notify_tooltip_trampoline::<F> as *const (),
292 )),
293 Box_::into_raw(f),
294 )
295 }
296 }
297
298 #[cfg(feature = "v1_7")]
299 #[cfg_attr(docsrs, doc(cfg(feature = "v1_7")))]
300 #[doc(alias = "use-underline")]
301 pub fn connect_use_underline_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
302 unsafe extern "C" fn notify_use_underline_trampoline<F: Fn(&Toggle) + 'static>(
303 this: *mut ffi::AdwToggle,
304 _param_spec: glib::ffi::gpointer,
305 f: glib::ffi::gpointer,
306 ) {
307 let f: &F = &*(f as *const F);
308 f(&from_glib_borrow(this))
309 }
310 unsafe {
311 let f: Box_<F> = Box_::new(f);
312 connect_raw(
313 self.as_ptr() as *mut _,
314 c"notify::use-underline".as_ptr() as *const _,
315 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
316 notify_use_underline_trampoline::<F> as *const (),
317 )),
318 Box_::into_raw(f),
319 )
320 }
321 }
322}
323
324#[cfg(feature = "v1_7")]
325#[cfg_attr(docsrs, doc(cfg(feature = "v1_7")))]
326impl Default for Toggle {
327 fn default() -> Self {
328 Self::new()
329 }
330}
331
332impl std::fmt::Display for Toggle {
333 #[inline]
334 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
335 f.write_str(&self.name())
336 }
337}
338
339#[must_use = "The builder must be built to be used"]
344pub struct ToggleBuilder {
345 builder: glib::object::ObjectBuilder<'static, Toggle>,
346}
347
348impl ToggleBuilder {
349 fn new() -> Self {
350 Self {
351 builder: glib::object::Object::builder(),
352 }
353 }
354
355 #[cfg(feature = "v1_7")]
356 #[cfg_attr(docsrs, doc(cfg(feature = "v1_7")))]
357 pub fn child(self, child: &impl IsA<gtk::Widget>) -> Self {
358 Self {
359 builder: self.builder.property("child", child.clone().upcast()),
360 }
361 }
362
363 #[cfg(feature = "v1_7")]
364 #[cfg_attr(docsrs, doc(cfg(feature = "v1_7")))]
365 pub fn enabled(self, enabled: bool) -> Self {
366 Self {
367 builder: self.builder.property("enabled", enabled),
368 }
369 }
370
371 #[cfg(feature = "v1_7")]
372 #[cfg_attr(docsrs, doc(cfg(feature = "v1_7")))]
373 pub fn icon_name(self, icon_name: impl Into<glib::GString>) -> Self {
374 Self {
375 builder: self.builder.property("icon-name", icon_name.into()),
376 }
377 }
378
379 #[cfg(feature = "v1_7")]
380 #[cfg_attr(docsrs, doc(cfg(feature = "v1_7")))]
381 pub fn label(self, label: impl Into<glib::GString>) -> Self {
382 Self {
383 builder: self.builder.property("label", label.into()),
384 }
385 }
386
387 #[cfg(feature = "v1_7")]
388 #[cfg_attr(docsrs, doc(cfg(feature = "v1_7")))]
389 pub fn name(self, name: impl Into<glib::GString>) -> Self {
390 Self {
391 builder: self.builder.property("name", name.into()),
392 }
393 }
394
395 #[cfg(feature = "v1_7")]
396 #[cfg_attr(docsrs, doc(cfg(feature = "v1_7")))]
397 pub fn tooltip(self, tooltip: impl Into<glib::GString>) -> Self {
398 Self {
399 builder: self.builder.property("tooltip", tooltip.into()),
400 }
401 }
402
403 #[cfg(feature = "v1_7")]
404 #[cfg_attr(docsrs, doc(cfg(feature = "v1_7")))]
405 pub fn use_underline(self, use_underline: bool) -> Self {
406 Self {
407 builder: self.builder.property("use-underline", use_underline),
408 }
409 }
410
411 #[must_use = "Building the object from the builder is usually expensive and is not expected to have side effects"]
414 pub fn build(self) -> Toggle {
415 assert_initialized_main_thread!();
416 self.builder.build()
417 }
418}