1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
// Take a look at the license at the top of the repository in the LICENSE file.

use crate::{ColorChooser, Orientation};
use gdk::RGBA;
use glib::object::IsA;
use glib::translate::*;
use libc::c_int;

// rustdoc-stripper-ignore-next
/// Trait containing manually implemented methods of [`ColorChooser`](crate::ColorChooser).
#[cfg_attr(feature = "v4_10", deprecated = "Since 4.10")]
pub trait ColorChooserExtManual: 'static {
    /// Adds a palette to the color chooser.
    ///
    /// If @orientation is horizontal, the colors are grouped in rows,
    /// with @colors_per_line colors in each row. If @horizontal is [`false`],
    /// the colors are grouped in columns instead.
    ///
    /// The default color palette of [`ColorChooserWidget`][crate::ColorChooserWidget] has
    /// 45 colors, organized in columns of 5 colors (this includes some
    /// grays).
    ///
    /// The layout of the color chooser widget works best when the
    /// palettes have 9-10 columns.
    ///
    /// Calling this function for the first time has the side effect
    /// of removing the default color palette from the color chooser.
    ///
    /// If @colors is [`None`], removes all previously added palettes.
    ///
    /// # Deprecated since 4.10
    ///
    /// Use [`ColorDialog`][crate::ColorDialog] instead
    /// ## `orientation`
    /// [`Orientation::Horizontal`][crate::Orientation::Horizontal] if the palette should
    ///   be displayed in rows, [`Orientation::Vertical`][crate::Orientation::Vertical] for columns
    /// ## `colors_per_line`
    /// the number of colors to show in each row/column
    /// ## `colors`
    /// the colors of the palette
    #[doc(alias = "gtk_color_chooser_add_palette")]
    fn add_palette(&self, orientation: Orientation, colors_per_line: i32, colors: &[RGBA]);
}

impl<O: IsA<ColorChooser>> ColorChooserExtManual for O {
    fn add_palette(&self, orientation: Orientation, colors_per_line: i32, colors: &[RGBA]) {
        unsafe {
            ffi::gtk_color_chooser_add_palette(
                self.as_ref().to_glib_none().0,
                orientation.into_glib(),
                colors_per_line,
                colors.len() as c_int,
                if colors.is_empty() {
                    std::ptr::null_mut()
                } else {
                    colors.as_ptr() as *mut gdk::ffi::GdkRGBA
                },
            )
        }
    }
}