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