gtk/auto/color_chooser.rs
1// This file was generated by gir (https://github.com/gtk-rs/gir)
2// from gir-files (https://github.com/gtk-rs/gir-files)
3// DO NOT EDIT
4
5use crate::ffi;
6use glib::{
7 object::ObjectType as _,
8 prelude::*,
9 signal::{SignalHandlerId, connect_raw},
10 translate::*,
11};
12use std::boxed::Box as Box_;
13
14glib::wrapper! {
15 /// [`ColorChooser`][crate::ColorChooser] is an interface that is implemented by widgets
16 /// for choosing colors. Depending on the situation, colors may be
17 /// allowed to have alpha (translucency).
18 ///
19 /// In GTK+, the main widgets that implement this interface are
20 /// [`ColorChooserWidget`][crate::ColorChooserWidget], [`ColorChooserDialog`][crate::ColorChooserDialog] and [`ColorButton`][crate::ColorButton].
21 ///
22 /// ## Properties
23 ///
24 ///
25 /// #### `rgba`
26 /// The ::rgba property contains the currently selected color,
27 /// as a [`gdk::RGBA`][crate::gdk::RGBA] struct. The property can be set to change
28 /// the current selection programmatically.
29 ///
30 /// Readable | Writable
31 ///
32 ///
33 /// #### `use-alpha`
34 /// When ::use-alpha is [`true`], colors may have alpha (translucency)
35 /// information. When it is [`false`], the [`gdk::RGBA`][crate::gdk::RGBA] struct obtained
36 /// via the [`rgba`][struct@crate::ColorChooser#rgba] property will be forced to have
37 /// alpha == 1.
38 ///
39 /// Implementations are expected to show alpha by rendering the color
40 /// over a non-uniform background (like a checkerboard pattern).
41 ///
42 /// Readable | Writable
43 ///
44 /// ## Signals
45 ///
46 ///
47 /// #### `color-activated`
48 /// Emitted when a color is activated from the color chooser.
49 /// This usually happens when the user clicks a color swatch,
50 /// or a color is selected and the user presses one of the keys
51 /// Space, Shift+Space, Return or Enter.
52 ///
53 ///
54 ///
55 /// # Implements
56 ///
57 /// [`ColorChooserExt`][trait@crate::prelude::ColorChooserExt], [`ColorChooserExtManual`][trait@crate::prelude::ColorChooserExtManual]
58 #[doc(alias = "GtkColorChooser")]
59 pub struct ColorChooser(Interface<ffi::GtkColorChooser, ffi::GtkColorChooserInterface>);
60
61 match fn {
62 type_ => || ffi::gtk_color_chooser_get_type(),
63 }
64}
65
66impl ColorChooser {
67 pub const NONE: Option<&'static ColorChooser> = None;
68}
69
70/// Trait containing all [`struct@ColorChooser`] methods.
71///
72/// # Implementors
73///
74/// [`ColorButton`][struct@crate::ColorButton], [`ColorChooserDialog`][struct@crate::ColorChooserDialog], [`ColorChooserWidget`][struct@crate::ColorChooserWidget], [`ColorChooser`][struct@crate::ColorChooser]
75pub trait ColorChooserExt: IsA<ColorChooser> + 'static {
76 /// Gets the currently-selected color.
77 ///
78 /// # Returns
79 ///
80 ///
81 /// ## `color`
82 /// a [`gdk::RGBA`][crate::gdk::RGBA] to fill in with the current color
83 #[doc(alias = "gtk_color_chooser_get_rgba")]
84 #[doc(alias = "get_rgba")]
85 fn rgba(&self) -> gdk::RGBA {
86 unsafe {
87 let mut color = gdk::RGBA::uninitialized();
88 ffi::gtk_color_chooser_get_rgba(
89 self.as_ref().to_glib_none().0,
90 color.to_glib_none_mut().0,
91 );
92 color
93 }
94 }
95
96 /// Returns whether the color chooser shows the alpha channel.
97 ///
98 /// # Returns
99 ///
100 /// [`true`] if the color chooser uses the alpha channel,
101 /// [`false`] if not
102 #[doc(alias = "gtk_color_chooser_get_use_alpha")]
103 #[doc(alias = "get_use_alpha")]
104 #[doc(alias = "use-alpha")]
105 fn uses_alpha(&self) -> bool {
106 unsafe {
107 from_glib(ffi::gtk_color_chooser_get_use_alpha(
108 self.as_ref().to_glib_none().0,
109 ))
110 }
111 }
112
113 /// Sets the color.
114 /// ## `color`
115 /// the new color
116 #[doc(alias = "gtk_color_chooser_set_rgba")]
117 #[doc(alias = "rgba")]
118 fn set_rgba(&self, color: &gdk::RGBA) {
119 unsafe {
120 ffi::gtk_color_chooser_set_rgba(self.as_ref().to_glib_none().0, color.to_glib_none().0);
121 }
122 }
123
124 /// Sets whether or not the color chooser should use the alpha channel.
125 /// ## `use_alpha`
126 /// [`true`] if color chooser should use alpha channel, [`false`] if not
127 #[doc(alias = "gtk_color_chooser_set_use_alpha")]
128 #[doc(alias = "use-alpha")]
129 fn set_use_alpha(&self, use_alpha: bool) {
130 unsafe {
131 ffi::gtk_color_chooser_set_use_alpha(
132 self.as_ref().to_glib_none().0,
133 use_alpha.into_glib(),
134 );
135 }
136 }
137
138 /// Emitted when a color is activated from the color chooser.
139 /// This usually happens when the user clicks a color swatch,
140 /// or a color is selected and the user presses one of the keys
141 /// Space, Shift+Space, Return or Enter.
142 /// ## `color`
143 /// the color
144 #[doc(alias = "color-activated")]
145 fn connect_color_activated<F: Fn(&Self, &gdk::RGBA) + 'static>(&self, f: F) -> SignalHandlerId {
146 unsafe extern "C" fn color_activated_trampoline<
147 P: IsA<ColorChooser>,
148 F: Fn(&P, &gdk::RGBA) + 'static,
149 >(
150 this: *mut ffi::GtkColorChooser,
151 color: *mut gdk::ffi::GdkRGBA,
152 f: glib::ffi::gpointer,
153 ) {
154 unsafe {
155 let f: &F = &*(f as *const F);
156 f(
157 ColorChooser::from_glib_borrow(this).unsafe_cast_ref(),
158 &from_glib_borrow(color),
159 )
160 }
161 }
162 unsafe {
163 let f: Box_<F> = Box_::new(f);
164 connect_raw(
165 self.as_ptr() as *mut _,
166 c"color-activated".as_ptr(),
167 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
168 color_activated_trampoline::<Self, F> as *const (),
169 )),
170 Box_::into_raw(f),
171 )
172 }
173 }
174
175 #[doc(alias = "rgba")]
176 fn connect_rgba_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
177 unsafe extern "C" fn notify_rgba_trampoline<P: IsA<ColorChooser>, F: Fn(&P) + 'static>(
178 this: *mut ffi::GtkColorChooser,
179 _param_spec: glib::ffi::gpointer,
180 f: glib::ffi::gpointer,
181 ) {
182 unsafe {
183 let f: &F = &*(f as *const F);
184 f(ColorChooser::from_glib_borrow(this).unsafe_cast_ref())
185 }
186 }
187 unsafe {
188 let f: Box_<F> = Box_::new(f);
189 connect_raw(
190 self.as_ptr() as *mut _,
191 c"notify::rgba".as_ptr(),
192 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
193 notify_rgba_trampoline::<Self, F> as *const (),
194 )),
195 Box_::into_raw(f),
196 )
197 }
198 }
199
200 #[doc(alias = "use-alpha")]
201 fn connect_use_alpha_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
202 unsafe extern "C" fn notify_use_alpha_trampoline<
203 P: IsA<ColorChooser>,
204 F: Fn(&P) + 'static,
205 >(
206 this: *mut ffi::GtkColorChooser,
207 _param_spec: glib::ffi::gpointer,
208 f: glib::ffi::gpointer,
209 ) {
210 unsafe {
211 let f: &F = &*(f as *const F);
212 f(ColorChooser::from_glib_borrow(this).unsafe_cast_ref())
213 }
214 }
215 unsafe {
216 let f: Box_<F> = Box_::new(f);
217 connect_raw(
218 self.as_ptr() as *mut _,
219 c"notify::use-alpha".as_ptr(),
220 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
221 notify_use_alpha_trampoline::<Self, F> as *const (),
222 )),
223 Box_::into_raw(f),
224 )
225 }
226 }
227}
228
229impl<O: IsA<ColorChooser>> ColorChooserExt for O {}