Skip to main content

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