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