gtk4/
color_chooser.rs

1// Take a look at the license at the top of the repository in the LICENSE file.
2
3use gdk::RGBA;
4use glib::translate::*;
5use libc::c_int;
6
7use crate::{ffi, prelude::*, ColorChooser, Orientation};
8
9// rustdoc-stripper-ignore-next
10/// Trait containing manually implemented methods of
11/// [`ColorChooser`](crate::ColorChooser).
12#[cfg_attr(feature = "v4_10", deprecated = "Since 4.10")]
13#[allow(deprecated)]
14pub trait ColorChooserExtManual: IsA<ColorChooser> + 'static {
15    /// Adds a palette to the color chooser.
16    ///
17    /// If @orientation is horizontal, the colors are grouped in rows,
18    /// with @colors_per_line colors in each row. If @horizontal is [`false`],
19    /// the colors are grouped in columns instead.
20    ///
21    /// The default color palette of [`ColorChooserWidget`][crate::ColorChooserWidget] has
22    /// 45 colors, organized in columns of 5 colors (this includes some
23    /// grays).
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 side effect
29    /// of removing the default color palette from the color chooser.
30    ///
31    /// If @colors is [`None`], removes all previously added palettes.
32    ///
33    /// # Deprecated since 4.10
34    ///
35    /// Use [`ColorDialog`][crate::ColorDialog] instead
36    /// ## `orientation`
37    /// [`Orientation::Horizontal`][crate::Orientation::Horizontal] if the palette should
38    ///   be displayed in rows, [`Orientation::Vertical`][crate::Orientation::Vertical] for columns
39    /// ## `colors_per_line`
40    /// the number of colors to show in each row/column
41    /// ## `colors`
42    /// the colors of the palette
43    #[doc(alias = "gtk_color_chooser_add_palette")]
44    fn add_palette(&self, orientation: Orientation, colors_per_line: i32, colors: &[RGBA]) {
45        unsafe {
46            ffi::gtk_color_chooser_add_palette(
47                self.as_ref().to_glib_none().0,
48                orientation.into_glib(),
49                colors_per_line,
50                colors.len() as c_int,
51                if colors.is_empty() {
52                    std::ptr::null_mut()
53                } else {
54                    colors.as_ptr() as *mut gdk::ffi::GdkRGBA
55                },
56            )
57        }
58    }
59}
60
61impl<O: IsA<ColorChooser>> ColorChooserExtManual for O {}