gtk/color_chooser.rs
1// Take a look at the license at the top of the repository in the LICENSE file.
2
3use crate::Orientation;
4use crate::{ColorChooser, ffi};
5use gdk::RGBA;
6use glib::object::IsA;
7use glib::translate::*;
8use libc::c_int;
9
10mod sealed {
11 pub trait Sealed {}
12 impl<T: glib::object::IsA<crate::ColorChooser>> Sealed for T {}
13}
14
15pub trait ColorChooserExtManual: IsA<ColorChooser> + sealed::Sealed + 'static {
16 /// Adds a palette to the color chooser. If `orientation` is horizontal,
17 /// the colors are grouped in rows, with `colors_per_line` colors
18 /// in each row. If `horizontal` is [`false`], the colors are grouped
19 /// in columns instead.
20 ///
21 /// The default color palette of [`ColorChooserWidget`][crate::ColorChooserWidget] has
22 /// 27 colors, organized in columns of 3 colors. The default gray
23 /// palette has 9 grays in a single row.
24 ///
25 /// The layout of the color chooser widget works best when the
26 /// palettes have 9-10 columns.
27 ///
28 /// Calling this function for the first time has the
29 /// side effect of removing the default color and gray palettes
30 /// from the color chooser.
31 ///
32 /// If `colors` is [`None`], removes all previously added palettes.
33 /// ## `orientation`
34 /// [`Orientation::Horizontal`][crate::Orientation::Horizontal] if the palette should
35 /// be displayed in rows, [`Orientation::Vertical`][crate::Orientation::Vertical] for columns
36 /// ## `colors_per_line`
37 /// the number of colors to show in each row/column
38 /// ## `colors`
39 /// the colors of the palette, or [`None`]
40 #[doc(alias = "gtk_color_chooser_add_palette")]
41 fn add_palette(&self, orientation: Orientation, colors_per_line: i32, colors: &[RGBA]) {
42 unsafe {
43 ffi::gtk_color_chooser_add_palette(
44 self.as_ref().to_glib_none().0,
45 orientation.into_glib(),
46 colors_per_line,
47 colors.len() as c_int,
48 colors.as_ptr() as *mut gdk::ffi::GdkRGBA,
49 )
50 }
51 }
52}
53
54impl<O: IsA<ColorChooser>> ColorChooserExtManual for O {}