1use crate::ffi;
7use glib::{
8 prelude::*,
9 signal::{SignalHandlerId, connect_raw},
10 translate::*,
11};
12use std::boxed::Box as Box_;
13
14glib::wrapper! {
15 #[doc(alias = "AdwToggle")]
103 pub struct Toggle(Object<ffi::AdwToggle, ffi::AdwToggleClass>);
104
105 match fn {
106 type_ => || ffi::adw_toggle_get_type(),
107 }
108}
109
110impl Toggle {
111 #[doc(alias = "adw_toggle_new")]
117 pub fn new() -> Toggle {
118 assert_initialized_main_thread!();
119 unsafe { from_glib_full(ffi::adw_toggle_new()) }
120 }
121
122 pub fn builder() -> ToggleBuilder {
127 ToggleBuilder::new()
128 }
129
130 #[doc(alias = "adw_toggle_get_child")]
136 #[doc(alias = "get_child")]
137 pub fn child(&self) -> Option<gtk::Widget> {
138 unsafe { from_glib_none(ffi::adw_toggle_get_child(self.to_glib_none().0)) }
139 }
140
141 #[cfg(feature = "v1_9")]
147 #[cfg_attr(docsrs, doc(cfg(feature = "v1_9")))]
148 #[doc(alias = "adw_toggle_get_description")]
149 #[doc(alias = "get_description")]
150 pub fn description(&self) -> glib::GString {
151 unsafe { from_glib_none(ffi::adw_toggle_get_description(self.to_glib_none().0)) }
152 }
153
154 #[doc(alias = "adw_toggle_get_enabled")]
160 #[doc(alias = "get_enabled")]
161 #[doc(alias = "enabled")]
162 pub fn is_enabled(&self) -> bool {
163 unsafe { from_glib(ffi::adw_toggle_get_enabled(self.to_glib_none().0)) }
164 }
165
166 #[doc(alias = "adw_toggle_get_icon_name")]
172 #[doc(alias = "get_icon_name")]
173 #[doc(alias = "icon-name")]
174 pub fn icon_name(&self) -> Option<glib::GString> {
175 unsafe { from_glib_none(ffi::adw_toggle_get_icon_name(self.to_glib_none().0)) }
176 }
177
178 #[doc(alias = "adw_toggle_get_index")]
184 #[doc(alias = "get_index")]
185 pub fn index(&self) -> u32 {
186 unsafe { ffi::adw_toggle_get_index(self.to_glib_none().0) }
187 }
188
189 #[doc(alias = "adw_toggle_get_label")]
195 #[doc(alias = "get_label")]
196 pub fn label(&self) -> Option<glib::GString> {
197 unsafe { from_glib_none(ffi::adw_toggle_get_label(self.to_glib_none().0)) }
198 }
199
200 #[doc(alias = "adw_toggle_get_name")]
206 #[doc(alias = "get_name")]
207 pub fn name(&self) -> glib::GString {
208 unsafe { from_glib_none(ffi::adw_toggle_get_name(self.to_glib_none().0)) }
209 }
210
211 #[doc(alias = "adw_toggle_get_tooltip")]
217 #[doc(alias = "get_tooltip")]
218 pub fn tooltip(&self) -> glib::GString {
219 unsafe { from_glib_none(ffi::adw_toggle_get_tooltip(self.to_glib_none().0)) }
220 }
221
222 #[doc(alias = "adw_toggle_get_use_underline")]
228 #[doc(alias = "get_use_underline")]
229 #[doc(alias = "use-underline")]
230 pub fn uses_underline(&self) -> bool {
231 unsafe { from_glib(ffi::adw_toggle_get_use_underline(self.to_glib_none().0)) }
232 }
233
234 #[doc(alias = "adw_toggle_set_child")]
243 #[doc(alias = "child")]
244 pub fn set_child(&self, child: Option<&impl IsA<gtk::Widget>>) {
245 unsafe {
246 ffi::adw_toggle_set_child(
247 self.to_glib_none().0,
248 child.map(|p| p.as_ref()).to_glib_none().0,
249 );
250 }
251 }
252
253 #[cfg(feature = "v1_9")]
262 #[cfg_attr(docsrs, doc(cfg(feature = "v1_9")))]
263 #[doc(alias = "adw_toggle_set_description")]
264 #[doc(alias = "description")]
265 pub fn set_description(&self, description: &str) {
266 unsafe {
267 ffi::adw_toggle_set_description(self.to_glib_none().0, description.to_glib_none().0);
268 }
269 }
270
271 #[doc(alias = "adw_toggle_set_enabled")]
275 #[doc(alias = "enabled")]
276 pub fn set_enabled(&self, enabled: bool) {
277 unsafe {
278 ffi::adw_toggle_set_enabled(self.to_glib_none().0, enabled.into_glib());
279 }
280 }
281
282 #[doc(alias = "adw_toggle_set_icon_name")]
289 #[doc(alias = "icon-name")]
290 pub fn set_icon_name(&self, icon_name: Option<&str>) {
291 unsafe {
292 ffi::adw_toggle_set_icon_name(self.to_glib_none().0, icon_name.to_glib_none().0);
293 }
294 }
295
296 #[doc(alias = "adw_toggle_set_label")]
304 #[doc(alias = "label")]
305 pub fn set_label(&self, label: Option<&str>) {
306 unsafe {
307 ffi::adw_toggle_set_label(self.to_glib_none().0, label.to_glib_none().0);
308 }
309 }
310
311 #[doc(alias = "adw_toggle_set_name")]
319 #[doc(alias = "name")]
320 pub fn set_name(&self, name: Option<&str>) {
321 unsafe {
322 ffi::adw_toggle_set_name(self.to_glib_none().0, name.to_glib_none().0);
323 }
324 }
325
326 #[doc(alias = "adw_toggle_set_tooltip")]
335 #[doc(alias = "tooltip")]
336 pub fn set_tooltip(&self, tooltip: &str) {
337 unsafe {
338 ffi::adw_toggle_set_tooltip(self.to_glib_none().0, tooltip.to_glib_none().0);
339 }
340 }
341
342 #[doc(alias = "adw_toggle_set_use_underline")]
348 #[doc(alias = "use-underline")]
349 pub fn set_use_underline(&self, use_underline: bool) {
350 unsafe {
351 ffi::adw_toggle_set_use_underline(self.to_glib_none().0, use_underline.into_glib());
352 }
353 }
354
355 #[cfg(feature = "v1_7")]
356 #[cfg_attr(docsrs, doc(cfg(feature = "v1_7")))]
357 #[doc(alias = "child")]
358 pub fn connect_child_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
359 unsafe extern "C" fn notify_child_trampoline<F: Fn(&Toggle) + 'static>(
360 this: *mut ffi::AdwToggle,
361 _param_spec: glib::ffi::gpointer,
362 f: glib::ffi::gpointer,
363 ) {
364 unsafe {
365 let f: &F = &*(f as *const F);
366 f(&from_glib_borrow(this))
367 }
368 }
369 unsafe {
370 let f: Box_<F> = Box_::new(f);
371 connect_raw(
372 self.as_ptr() as *mut _,
373 c"notify::child".as_ptr(),
374 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
375 notify_child_trampoline::<F> as *const (),
376 )),
377 Box_::into_raw(f),
378 )
379 }
380 }
381
382 #[cfg(feature = "v1_9")]
383 #[cfg_attr(docsrs, doc(cfg(feature = "v1_9")))]
384 #[doc(alias = "description")]
385 pub fn connect_description_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
386 unsafe extern "C" fn notify_description_trampoline<F: Fn(&Toggle) + 'static>(
387 this: *mut ffi::AdwToggle,
388 _param_spec: glib::ffi::gpointer,
389 f: glib::ffi::gpointer,
390 ) {
391 unsafe {
392 let f: &F = &*(f as *const F);
393 f(&from_glib_borrow(this))
394 }
395 }
396 unsafe {
397 let f: Box_<F> = Box_::new(f);
398 connect_raw(
399 self.as_ptr() as *mut _,
400 c"notify::description".as_ptr(),
401 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
402 notify_description_trampoline::<F> as *const (),
403 )),
404 Box_::into_raw(f),
405 )
406 }
407 }
408
409 #[cfg(feature = "v1_7")]
410 #[cfg_attr(docsrs, doc(cfg(feature = "v1_7")))]
411 #[doc(alias = "enabled")]
412 pub fn connect_enabled_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
413 unsafe extern "C" fn notify_enabled_trampoline<F: Fn(&Toggle) + 'static>(
414 this: *mut ffi::AdwToggle,
415 _param_spec: glib::ffi::gpointer,
416 f: glib::ffi::gpointer,
417 ) {
418 unsafe {
419 let f: &F = &*(f as *const F);
420 f(&from_glib_borrow(this))
421 }
422 }
423 unsafe {
424 let f: Box_<F> = Box_::new(f);
425 connect_raw(
426 self.as_ptr() as *mut _,
427 c"notify::enabled".as_ptr(),
428 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
429 notify_enabled_trampoline::<F> as *const (),
430 )),
431 Box_::into_raw(f),
432 )
433 }
434 }
435
436 #[cfg(feature = "v1_7")]
437 #[cfg_attr(docsrs, doc(cfg(feature = "v1_7")))]
438 #[doc(alias = "icon-name")]
439 pub fn connect_icon_name_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
440 unsafe extern "C" fn notify_icon_name_trampoline<F: Fn(&Toggle) + 'static>(
441 this: *mut ffi::AdwToggle,
442 _param_spec: glib::ffi::gpointer,
443 f: glib::ffi::gpointer,
444 ) {
445 unsafe {
446 let f: &F = &*(f as *const F);
447 f(&from_glib_borrow(this))
448 }
449 }
450 unsafe {
451 let f: Box_<F> = Box_::new(f);
452 connect_raw(
453 self.as_ptr() as *mut _,
454 c"notify::icon-name".as_ptr(),
455 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
456 notify_icon_name_trampoline::<F> as *const (),
457 )),
458 Box_::into_raw(f),
459 )
460 }
461 }
462
463 #[cfg(feature = "v1_7")]
464 #[cfg_attr(docsrs, doc(cfg(feature = "v1_7")))]
465 #[doc(alias = "label")]
466 pub fn connect_label_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
467 unsafe extern "C" fn notify_label_trampoline<F: Fn(&Toggle) + 'static>(
468 this: *mut ffi::AdwToggle,
469 _param_spec: glib::ffi::gpointer,
470 f: glib::ffi::gpointer,
471 ) {
472 unsafe {
473 let f: &F = &*(f as *const F);
474 f(&from_glib_borrow(this))
475 }
476 }
477 unsafe {
478 let f: Box_<F> = Box_::new(f);
479 connect_raw(
480 self.as_ptr() as *mut _,
481 c"notify::label".as_ptr(),
482 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
483 notify_label_trampoline::<F> as *const (),
484 )),
485 Box_::into_raw(f),
486 )
487 }
488 }
489
490 #[cfg(feature = "v1_7")]
491 #[cfg_attr(docsrs, doc(cfg(feature = "v1_7")))]
492 #[doc(alias = "name")]
493 pub fn connect_name_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
494 unsafe extern "C" fn notify_name_trampoline<F: Fn(&Toggle) + 'static>(
495 this: *mut ffi::AdwToggle,
496 _param_spec: glib::ffi::gpointer,
497 f: glib::ffi::gpointer,
498 ) {
499 unsafe {
500 let f: &F = &*(f as *const F);
501 f(&from_glib_borrow(this))
502 }
503 }
504 unsafe {
505 let f: Box_<F> = Box_::new(f);
506 connect_raw(
507 self.as_ptr() as *mut _,
508 c"notify::name".as_ptr(),
509 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
510 notify_name_trampoline::<F> as *const (),
511 )),
512 Box_::into_raw(f),
513 )
514 }
515 }
516
517 #[cfg(feature = "v1_7")]
518 #[cfg_attr(docsrs, doc(cfg(feature = "v1_7")))]
519 #[doc(alias = "tooltip")]
520 pub fn connect_tooltip_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
521 unsafe extern "C" fn notify_tooltip_trampoline<F: Fn(&Toggle) + 'static>(
522 this: *mut ffi::AdwToggle,
523 _param_spec: glib::ffi::gpointer,
524 f: glib::ffi::gpointer,
525 ) {
526 unsafe {
527 let f: &F = &*(f as *const F);
528 f(&from_glib_borrow(this))
529 }
530 }
531 unsafe {
532 let f: Box_<F> = Box_::new(f);
533 connect_raw(
534 self.as_ptr() as *mut _,
535 c"notify::tooltip".as_ptr(),
536 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
537 notify_tooltip_trampoline::<F> as *const (),
538 )),
539 Box_::into_raw(f),
540 )
541 }
542 }
543
544 #[cfg(feature = "v1_7")]
545 #[cfg_attr(docsrs, doc(cfg(feature = "v1_7")))]
546 #[doc(alias = "use-underline")]
547 pub fn connect_use_underline_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
548 unsafe extern "C" fn notify_use_underline_trampoline<F: Fn(&Toggle) + 'static>(
549 this: *mut ffi::AdwToggle,
550 _param_spec: glib::ffi::gpointer,
551 f: glib::ffi::gpointer,
552 ) {
553 unsafe {
554 let f: &F = &*(f as *const F);
555 f(&from_glib_borrow(this))
556 }
557 }
558 unsafe {
559 let f: Box_<F> = Box_::new(f);
560 connect_raw(
561 self.as_ptr() as *mut _,
562 c"notify::use-underline".as_ptr(),
563 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
564 notify_use_underline_trampoline::<F> as *const (),
565 )),
566 Box_::into_raw(f),
567 )
568 }
569 }
570}
571
572#[cfg(feature = "v1_7")]
573#[cfg_attr(docsrs, doc(cfg(feature = "v1_7")))]
574impl Default for Toggle {
575 fn default() -> Self {
576 Self::new()
577 }
578}
579
580impl std::fmt::Display for Toggle {
581 #[inline]
582 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
583 f.write_str(&self.name())
584 }
585}
586
587#[must_use = "The builder must be built to be used"]
592pub struct ToggleBuilder {
593 builder: glib::object::ObjectBuilder<'static, Toggle>,
594}
595
596impl ToggleBuilder {
597 fn new() -> Self {
598 Self {
599 builder: glib::object::Object::builder(),
600 }
601 }
602
603 #[cfg(feature = "v1_7")]
610 #[cfg_attr(docsrs, doc(cfg(feature = "v1_7")))]
611 pub fn child(self, child: &impl IsA<gtk::Widget>) -> Self {
612 Self {
613 builder: self.builder.property("child", child.clone().upcast()),
614 }
615 }
616
617 #[cfg(feature = "v1_9")]
624 #[cfg_attr(docsrs, doc(cfg(feature = "v1_9")))]
625 pub fn description(self, description: impl Into<glib::GString>) -> Self {
626 Self {
627 builder: self.builder.property("description", description.into()),
628 }
629 }
630
631 #[cfg(feature = "v1_7")]
633 #[cfg_attr(docsrs, doc(cfg(feature = "v1_7")))]
634 pub fn enabled(self, enabled: bool) -> Self {
635 Self {
636 builder: self.builder.property("enabled", enabled),
637 }
638 }
639
640 #[cfg(feature = "v1_7")]
645 #[cfg_attr(docsrs, doc(cfg(feature = "v1_7")))]
646 pub fn icon_name(self, icon_name: impl Into<glib::GString>) -> Self {
647 Self {
648 builder: self.builder.property("icon-name", icon_name.into()),
649 }
650 }
651
652 #[cfg(feature = "v1_7")]
658 #[cfg_attr(docsrs, doc(cfg(feature = "v1_7")))]
659 pub fn label(self, label: impl Into<glib::GString>) -> Self {
660 Self {
661 builder: self.builder.property("label", label.into()),
662 }
663 }
664
665 #[cfg(feature = "v1_7")]
671 #[cfg_attr(docsrs, doc(cfg(feature = "v1_7")))]
672 pub fn name(self, name: impl Into<glib::GString>) -> Self {
673 Self {
674 builder: self.builder.property("name", name.into()),
675 }
676 }
677
678 #[cfg(feature = "v1_7")]
685 #[cfg_attr(docsrs, doc(cfg(feature = "v1_7")))]
686 pub fn tooltip(self, tooltip: impl Into<glib::GString>) -> Self {
687 Self {
688 builder: self.builder.property("tooltip", tooltip.into()),
689 }
690 }
691
692 #[cfg(feature = "v1_7")]
696 #[cfg_attr(docsrs, doc(cfg(feature = "v1_7")))]
697 pub fn use_underline(self, use_underline: bool) -> Self {
698 Self {
699 builder: self.builder.property("use-underline", use_underline),
700 }
701 }
702
703 #[must_use = "Building the object from the builder is usually expensive and is not expected to have side effects"]
706 pub fn build(self) -> Toggle {
707 assert_initialized_main_thread!();
708 self.builder.build()
709 }
710}