Skip to main content

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