gtk/auto/
color_chooser.rs1use glib::{
6 prelude::*,
7 signal::{connect_raw, SignalHandlerId},
8 translate::*,
9};
10use std::{boxed::Box as Box_, fmt, mem::transmute};
11
12glib::wrapper! {
13 #[doc(alias = "GtkColorChooser")]
14 pub struct ColorChooser(Interface<ffi::GtkColorChooser, ffi::GtkColorChooserInterface>);
15
16 match fn {
17 type_ => || ffi::gtk_color_chooser_get_type(),
18 }
19}
20
21impl ColorChooser {
22 pub const NONE: Option<&'static ColorChooser> = None;
23}
24
25mod sealed {
26 pub trait Sealed {}
27 impl<T: super::IsA<super::ColorChooser>> Sealed for T {}
28}
29
30pub trait ColorChooserExt: IsA<ColorChooser> + sealed::Sealed + 'static {
31 #[doc(alias = "gtk_color_chooser_get_rgba")]
32 #[doc(alias = "get_rgba")]
33 fn rgba(&self) -> gdk::RGBA {
34 unsafe {
35 let mut color = gdk::RGBA::uninitialized();
36 ffi::gtk_color_chooser_get_rgba(
37 self.as_ref().to_glib_none().0,
38 color.to_glib_none_mut().0,
39 );
40 color
41 }
42 }
43
44 #[doc(alias = "gtk_color_chooser_get_use_alpha")]
45 #[doc(alias = "get_use_alpha")]
46 fn uses_alpha(&self) -> bool {
47 unsafe {
48 from_glib(ffi::gtk_color_chooser_get_use_alpha(
49 self.as_ref().to_glib_none().0,
50 ))
51 }
52 }
53
54 #[doc(alias = "gtk_color_chooser_set_rgba")]
55 fn set_rgba(&self, color: &gdk::RGBA) {
56 unsafe {
57 ffi::gtk_color_chooser_set_rgba(self.as_ref().to_glib_none().0, color.to_glib_none().0);
58 }
59 }
60
61 #[doc(alias = "gtk_color_chooser_set_use_alpha")]
62 fn set_use_alpha(&self, use_alpha: bool) {
63 unsafe {
64 ffi::gtk_color_chooser_set_use_alpha(
65 self.as_ref().to_glib_none().0,
66 use_alpha.into_glib(),
67 );
68 }
69 }
70
71 #[doc(alias = "color-activated")]
72 fn connect_color_activated<F: Fn(&Self, &gdk::RGBA) + 'static>(&self, f: F) -> SignalHandlerId {
73 unsafe extern "C" fn color_activated_trampoline<
74 P: IsA<ColorChooser>,
75 F: Fn(&P, &gdk::RGBA) + 'static,
76 >(
77 this: *mut ffi::GtkColorChooser,
78 color: *mut gdk::ffi::GdkRGBA,
79 f: glib::ffi::gpointer,
80 ) {
81 let f: &F = &*(f as *const F);
82 f(
83 ColorChooser::from_glib_borrow(this).unsafe_cast_ref(),
84 &from_glib_borrow(color),
85 )
86 }
87 unsafe {
88 let f: Box_<F> = Box_::new(f);
89 connect_raw(
90 self.as_ptr() as *mut _,
91 b"color-activated\0".as_ptr() as *const _,
92 Some(transmute::<_, unsafe extern "C" fn()>(
93 color_activated_trampoline::<Self, F> as *const (),
94 )),
95 Box_::into_raw(f),
96 )
97 }
98 }
99
100 #[doc(alias = "rgba")]
101 fn connect_rgba_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
102 unsafe extern "C" fn notify_rgba_trampoline<P: IsA<ColorChooser>, F: Fn(&P) + 'static>(
103 this: *mut ffi::GtkColorChooser,
104 _param_spec: glib::ffi::gpointer,
105 f: glib::ffi::gpointer,
106 ) {
107 let f: &F = &*(f as *const F);
108 f(ColorChooser::from_glib_borrow(this).unsafe_cast_ref())
109 }
110 unsafe {
111 let f: Box_<F> = Box_::new(f);
112 connect_raw(
113 self.as_ptr() as *mut _,
114 b"notify::rgba\0".as_ptr() as *const _,
115 Some(transmute::<_, unsafe extern "C" fn()>(
116 notify_rgba_trampoline::<Self, F> as *const (),
117 )),
118 Box_::into_raw(f),
119 )
120 }
121 }
122
123 #[doc(alias = "use-alpha")]
124 fn connect_use_alpha_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
125 unsafe extern "C" fn notify_use_alpha_trampoline<
126 P: IsA<ColorChooser>,
127 F: Fn(&P) + 'static,
128 >(
129 this: *mut ffi::GtkColorChooser,
130 _param_spec: glib::ffi::gpointer,
131 f: glib::ffi::gpointer,
132 ) {
133 let f: &F = &*(f as *const F);
134 f(ColorChooser::from_glib_borrow(this).unsafe_cast_ref())
135 }
136 unsafe {
137 let f: Box_<F> = Box_::new(f);
138 connect_raw(
139 self.as_ptr() as *mut _,
140 b"notify::use-alpha\0".as_ptr() as *const _,
141 Some(transmute::<_, unsafe extern "C" fn()>(
142 notify_use_alpha_trampoline::<Self, F> as *const (),
143 )),
144 Box_::into_raw(f),
145 )
146 }
147 }
148}
149
150impl<O: IsA<ColorChooser>> ColorChooserExt for O {}
151
152impl fmt::Display for ColorChooser {
153 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
154 f.write_str("ColorChooser")
155 }
156}