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
78mod sealed {
79 pub trait Sealed {}
80 impl<T: super::IsA<super::ColorChooser>> Sealed for T {}
81}
82
83/// Trait containing all [`struct@ColorChooser`] methods.
84///
85/// # Implementors
86///
87/// [`ColorButton`][struct@crate::ColorButton], [`ColorChooserDialog`][struct@crate::ColorChooserDialog], [`ColorChooserWidget`][struct@crate::ColorChooserWidget], [`ColorChooser`][struct@crate::ColorChooser]
88pub trait ColorChooserExt: IsA<ColorChooser> + sealed::Sealed + 'static {
89 /// Gets the currently-selected color.
90 ///
91 /// # Deprecated since 4.10
92 ///
93 /// Use [`ColorDialog`][crate::ColorDialog] instead
94 ///
95 /// # Returns
96 ///
97 ///
98 /// ## `color`
99 /// a [`gdk::RGBA`][crate::gdk::RGBA] to fill in with the current color
100 #[cfg_attr(feature = "v4_10", deprecated = "Since 4.10")]
101 #[allow(deprecated)]
102 #[doc(alias = "gtk_color_chooser_get_rgba")]
103 #[doc(alias = "get_rgba")]
104 fn rgba(&self) -> gdk::RGBA {
105 unsafe {
106 let mut color = gdk::RGBA::uninitialized();
107 ffi::gtk_color_chooser_get_rgba(
108 self.as_ref().to_glib_none().0,
109 color.to_glib_none_mut().0,
110 );
111 color
112 }
113 }
114
115 /// Returns whether the color chooser shows the alpha channel.
116 ///
117 /// # Deprecated since 4.10
118 ///
119 /// Use [`ColorDialog`][crate::ColorDialog] instead
120 ///
121 /// # Returns
122 ///
123 /// [`true`] if the color chooser uses the alpha channel,
124 /// [`false`] if not
125 #[cfg_attr(feature = "v4_10", deprecated = "Since 4.10")]
126 #[allow(deprecated)]
127 #[doc(alias = "gtk_color_chooser_get_use_alpha")]
128 #[doc(alias = "get_use_alpha")]
129 #[doc(alias = "use-alpha")]
130 fn uses_alpha(&self) -> bool {
131 unsafe {
132 from_glib(ffi::gtk_color_chooser_get_use_alpha(
133 self.as_ref().to_glib_none().0,
134 ))
135 }
136 }
137
138 /// Sets the color.
139 ///
140 /// # Deprecated since 4.10
141 ///
142 /// Use [`ColorDialog`][crate::ColorDialog] instead
143 /// ## `color`
144 /// the new color
145 #[cfg_attr(feature = "v4_10", deprecated = "Since 4.10")]
146 #[allow(deprecated)]
147 #[doc(alias = "gtk_color_chooser_set_rgba")]
148 #[doc(alias = "rgba")]
149 fn set_rgba(&self, color: &gdk::RGBA) {
150 unsafe {
151 ffi::gtk_color_chooser_set_rgba(self.as_ref().to_glib_none().0, color.to_glib_none().0);
152 }
153 }
154
155 /// Sets whether or not the color chooser should use the alpha channel.
156 ///
157 /// # Deprecated since 4.10
158 ///
159 /// Use [`ColorDialog`][crate::ColorDialog] instead
160 /// ## `use_alpha`
161 /// [`true`] if color chooser should use alpha channel, [`false`] if not
162 #[cfg_attr(feature = "v4_10", deprecated = "Since 4.10")]
163 #[allow(deprecated)]
164 #[doc(alias = "gtk_color_chooser_set_use_alpha")]
165 #[doc(alias = "use-alpha")]
166 fn set_use_alpha(&self, use_alpha: bool) {
167 unsafe {
168 ffi::gtk_color_chooser_set_use_alpha(
169 self.as_ref().to_glib_none().0,
170 use_alpha.into_glib(),
171 );
172 }
173 }
174
175 /// Emitted when a color is activated from the color chooser.
176 ///
177 /// This usually happens when the user clicks a color swatch,
178 /// or a color is selected and the user presses one of the keys
179 /// Space, Shift+Space, Return or Enter.
180 ///
181 /// # Deprecated since 4.10
182 ///
183 /// Use [`ColorDialog`][crate::ColorDialog] and [`ColorDialogButton`][crate::ColorDialogButton]
184 /// instead of widgets implementing [`ColorChooser`][crate::ColorChooser]
185 /// ## `color`
186 /// the color
187 #[cfg_attr(feature = "v4_10", deprecated = "Since 4.10")]
188 #[doc(alias = "color-activated")]
189 fn connect_color_activated<F: Fn(&Self, &gdk::RGBA) + 'static>(&self, f: F) -> SignalHandlerId {
190 unsafe extern "C" fn color_activated_trampoline<
191 P: IsA<ColorChooser>,
192 F: Fn(&P, &gdk::RGBA) + 'static,
193 >(
194 this: *mut ffi::GtkColorChooser,
195 color: *mut gdk::ffi::GdkRGBA,
196 f: glib::ffi::gpointer,
197 ) {
198 let f: &F = &*(f as *const F);
199 f(
200 ColorChooser::from_glib_borrow(this).unsafe_cast_ref(),
201 &from_glib_borrow(color),
202 )
203 }
204 unsafe {
205 let f: Box_<F> = Box_::new(f);
206 connect_raw(
207 self.as_ptr() as *mut _,
208 b"color-activated\0".as_ptr() as *const _,
209 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
210 color_activated_trampoline::<Self, F> as *const (),
211 )),
212 Box_::into_raw(f),
213 )
214 }
215 }
216
217 #[cfg_attr(feature = "v4_10", deprecated = "Since 4.10")]
218 #[doc(alias = "rgba")]
219 fn connect_rgba_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
220 unsafe extern "C" fn notify_rgba_trampoline<P: IsA<ColorChooser>, F: Fn(&P) + 'static>(
221 this: *mut ffi::GtkColorChooser,
222 _param_spec: glib::ffi::gpointer,
223 f: glib::ffi::gpointer,
224 ) {
225 let f: &F = &*(f as *const F);
226 f(ColorChooser::from_glib_borrow(this).unsafe_cast_ref())
227 }
228 unsafe {
229 let f: Box_<F> = Box_::new(f);
230 connect_raw(
231 self.as_ptr() as *mut _,
232 b"notify::rgba\0".as_ptr() as *const _,
233 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
234 notify_rgba_trampoline::<Self, F> as *const (),
235 )),
236 Box_::into_raw(f),
237 )
238 }
239 }
240
241 #[cfg_attr(feature = "v4_10", deprecated = "Since 4.10")]
242 #[doc(alias = "use-alpha")]
243 fn connect_use_alpha_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
244 unsafe extern "C" fn notify_use_alpha_trampoline<
245 P: IsA<ColorChooser>,
246 F: Fn(&P) + 'static,
247 >(
248 this: *mut ffi::GtkColorChooser,
249 _param_spec: glib::ffi::gpointer,
250 f: glib::ffi::gpointer,
251 ) {
252 let f: &F = &*(f as *const F);
253 f(ColorChooser::from_glib_borrow(this).unsafe_cast_ref())
254 }
255 unsafe {
256 let f: Box_<F> = Box_::new(f);
257 connect_raw(
258 self.as_ptr() as *mut _,
259 b"notify::use-alpha\0".as_ptr() as *const _,
260 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
261 notify_use_alpha_trampoline::<Self, F> as *const (),
262 )),
263 Box_::into_raw(f),
264 )
265 }
266 }
267}
268
269impl<O: IsA<ColorChooser>> ColorChooserExt for O {}