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::{connect_raw, SignalHandlerId},
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 let f: &F = &*(f as *const F);
194 f(
195 ColorChooser::from_glib_borrow(this).unsafe_cast_ref(),
196 &from_glib_borrow(color),
197 )
198 }
199 unsafe {
200 let f: Box_<F> = Box_::new(f);
201 connect_raw(
202 self.as_ptr() as *mut _,
203 c"color-activated".as_ptr() as *const _,
204 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
205 color_activated_trampoline::<Self, F> as *const (),
206 )),
207 Box_::into_raw(f),
208 )
209 }
210 }
211
212 #[cfg_attr(feature = "v4_10", deprecated = "Since 4.10")]
213 #[doc(alias = "rgba")]
214 fn connect_rgba_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
215 unsafe extern "C" fn notify_rgba_trampoline<P: IsA<ColorChooser>, F: Fn(&P) + 'static>(
216 this: *mut ffi::GtkColorChooser,
217 _param_spec: glib::ffi::gpointer,
218 f: glib::ffi::gpointer,
219 ) {
220 let f: &F = &*(f as *const F);
221 f(ColorChooser::from_glib_borrow(this).unsafe_cast_ref())
222 }
223 unsafe {
224 let f: Box_<F> = Box_::new(f);
225 connect_raw(
226 self.as_ptr() as *mut _,
227 c"notify::rgba".as_ptr() as *const _,
228 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
229 notify_rgba_trampoline::<Self, F> as *const (),
230 )),
231 Box_::into_raw(f),
232 )
233 }
234 }
235
236 #[cfg_attr(feature = "v4_10", deprecated = "Since 4.10")]
237 #[doc(alias = "use-alpha")]
238 fn connect_use_alpha_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
239 unsafe extern "C" fn notify_use_alpha_trampoline<
240 P: IsA<ColorChooser>,
241 F: Fn(&P) + 'static,
242 >(
243 this: *mut ffi::GtkColorChooser,
244 _param_spec: glib::ffi::gpointer,
245 f: glib::ffi::gpointer,
246 ) {
247 let f: &F = &*(f as *const F);
248 f(ColorChooser::from_glib_borrow(this).unsafe_cast_ref())
249 }
250 unsafe {
251 let f: Box_<F> = Box_::new(f);
252 connect_raw(
253 self.as_ptr() as *mut _,
254 c"notify::use-alpha".as_ptr() as *const _,
255 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
256 notify_use_alpha_trampoline::<Self, F> as *const (),
257 )),
258 Box_::into_raw(f),
259 )
260 }
261 }
262}
263
264impl<O: IsA<ColorChooser>> ColorChooserExt for O {}