use gtk4 as gtk; use gtk::{*, prelude::*}; use glib::{ signal::{connect_raw, SignalHandlerId}, translate::*, }; use std::boxed::Box as Box_; mod sealed { pub trait Sealed {} impl> Sealed for T {} } pub trait SwitchExt: IsA + sealed::Sealed + 'static { #[doc(alias = "gtk_switch_get_active")] #[doc(alias = "get_active")] fn is_active(&self) -> bool { unsafe { from_glib(ffi::gtk_switch_get_active(self.as_ref().to_glib_none().0)) } } #[doc(alias = "gtk_switch_get_state")] #[doc(alias = "get_state")] fn state(&self) -> bool { unsafe { from_glib(ffi::gtk_switch_get_state(self.as_ref().to_glib_none().0)) } } #[doc(alias = "gtk_switch_set_active")] fn set_active(&self, is_active: bool) { unsafe { ffi::gtk_switch_set_active(self.as_ref().to_glib_none().0, is_active.into_glib()); } } #[doc(alias = "gtk_switch_set_state")] fn set_state(&self, state: bool) { unsafe { ffi::gtk_switch_set_state(self.as_ref().to_glib_none().0, state.into_glib()); } } #[doc(alias = "activate")] fn connect_activate(&self, f: F) -> SignalHandlerId { unsafe extern "C" fn activate_trampoline, F: Fn(&P) + 'static>( this: *mut ffi::GtkSwitch, f: glib::ffi::gpointer, ) { let f: &F = &*(f as *const F); f(Switch::from_glib_borrow(this).unsafe_cast_ref()) } unsafe { let f: Box_ = Box_::new(f); connect_raw( self.as_ptr() as *mut _, b"activate\0".as_ptr() as *const _, Some(std::mem::transmute::<_, unsafe extern "C" fn()>( activate_trampoline:: as *const (), )), Box_::into_raw(f), ) } } fn emit_activate(&self) { self.emit_by_name::<()>("activate", &[]); } #[doc(alias = "state-set")] fn connect_state_set glib::Propagation + 'static>( &self, f: F, ) -> SignalHandlerId { unsafe extern "C" fn state_set_trampoline< P: IsA, F: Fn(&P, bool) -> glib::Propagation + 'static, >( this: *mut ffi::GtkSwitch, state: glib::ffi::gboolean, f: glib::ffi::gpointer, ) -> glib::ffi::gboolean { let f: &F = &*(f as *const F); f( Switch::from_glib_borrow(this).unsafe_cast_ref(), from_glib(state), ) .into_glib() } unsafe { let f: Box_ = Box_::new(f); connect_raw( self.as_ptr() as *mut _, b"state-set\0".as_ptr() as *const _, Some(std::mem::transmute::<_, unsafe extern "C" fn()>( state_set_trampoline:: as *const (), )), Box_::into_raw(f), ) } } #[doc(alias = "active")] fn connect_active_notify(&self, f: F) -> SignalHandlerId { unsafe extern "C" fn notify_active_trampoline, F: Fn(&P) + 'static>( this: *mut ffi::GtkSwitch, _param_spec: glib::ffi::gpointer, f: glib::ffi::gpointer, ) { let f: &F = &*(f as *const F); f(Switch::from_glib_borrow(this).unsafe_cast_ref()) } unsafe { let f: Box_ = Box_::new(f); connect_raw( self.as_ptr() as *mut _, b"notify::active\0".as_ptr() as *const _, Some(std::mem::transmute::<_, unsafe extern "C" fn()>( notify_active_trampoline:: as *const (), )), Box_::into_raw(f), ) } } #[doc(alias = "state")] fn connect_state_notify(&self, f: F) -> SignalHandlerId { unsafe extern "C" fn notify_state_trampoline, F: Fn(&P) + 'static>( this: *mut ffi::GtkSwitch, _param_spec: glib::ffi::gpointer, f: glib::ffi::gpointer, ) { let f: &F = &*(f as *const F); f(Switch::from_glib_borrow(this).unsafe_cast_ref()) } unsafe { let f: Box_ = Box_::new(f); connect_raw( self.as_ptr() as *mut _, b"notify::state\0".as_ptr() as *const _, Some(std::mem::transmute::<_, unsafe extern "C" fn()>( notify_state_trampoline:: as *const (), )), Box_::into_raw(f), ) } } } impl> SwitchExt for O {}