gdk4/auto/
color_state.rs

1// This file was generated by gir (https://github.com/gtk-rs/gir)
2// from gir-files (https://github.com/gtk-rs/gir-files)
3// DO NOT EDIT
4
5use crate::{ffi, CicpParams};
6use glib::translate::*;
7
8glib::wrapper! {
9    /// Provides information to interpret colors and pixels in a variety of ways.
10    ///
11    /// They are also known as
12    /// [*color spaces*](https://en.wikipedia.org/wiki/Color_space).
13    ///
14    /// Crucially, GTK knows how to convert colors from one color
15    /// state to another.
16    ///
17    /// [`ColorState`][crate::ColorState] objects are immutable and therefore threadsafe.
18    #[derive(Debug, PartialOrd, Ord, Hash)]
19    pub struct ColorState(Shared<ffi::GdkColorState>);
20
21    match fn {
22        ref => |ptr| ffi::gdk_color_state_ref(ptr),
23        unref => |ptr| ffi::gdk_color_state_unref(ptr),
24        type_ => || ffi::gdk_color_state_get_type(),
25    }
26}
27
28impl ColorState {
29    /// Create a [`CicpParams`][crate::CicpParams] representing the colorstate.
30    ///
31    /// It is not guaranteed that every [`ColorState`][crate::ColorState] can be
32    /// represented with Cicp parameters. If that is the case,
33    /// this function returns `NULL`.
34    ///
35    /// # Returns
36    ///
37    /// A new [`CicpParams`][crate::CicpParams]
38    #[doc(alias = "gdk_color_state_create_cicp_params")]
39    pub fn create_cicp_params(&self) -> Option<CicpParams> {
40        unsafe {
41            from_glib_full(ffi::gdk_color_state_create_cicp_params(
42                self.to_glib_none().0,
43            ))
44        }
45    }
46
47    #[doc(alias = "gdk_color_state_equal")]
48    fn equal(&self, other: &ColorState) -> bool {
49        unsafe {
50            from_glib(ffi::gdk_color_state_equal(
51                self.to_glib_none().0,
52                other.to_glib_none().0,
53            ))
54        }
55    }
56
57    /// Compares two `GdkColorStates` for equivalence.
58    ///
59    /// Two objects that represent the same color state should be equivalent,
60    /// even though they may not be equal in the sense of `Gdk::ColorState::equal()`.
61    /// ## `other`
62    /// another `GdkColorStatee`
63    ///
64    /// # Returns
65    ///
66    /// [`true`] if the two color states are equivalent
67    #[cfg(feature = "v4_20")]
68    #[cfg_attr(docsrs, doc(cfg(feature = "v4_20")))]
69    #[doc(alias = "gdk_color_state_equivalent")]
70    pub fn equivalent(&self, other: &ColorState) -> bool {
71        unsafe {
72            from_glib(ffi::gdk_color_state_equivalent(
73                self.to_glib_none().0,
74                other.to_glib_none().0,
75            ))
76        }
77    }
78
79    /// Returns the color state object representing the oklab color space.
80    ///
81    /// This is a perceptually uniform color state.
82    ///
83    /// # Returns
84    ///
85    /// the color state object for oklab
86    #[cfg(feature = "v4_18")]
87    #[cfg_attr(docsrs, doc(cfg(feature = "v4_18")))]
88    #[doc(alias = "gdk_color_state_get_oklab")]
89    #[doc(alias = "get_oklab")]
90    pub fn oklab() -> ColorState {
91        assert_initialized_main_thread!();
92        unsafe { from_glib_full(ffi::gdk_color_state_get_oklab()) }
93    }
94
95    /// Returns the color state object representing the oklch color space.
96    ///
97    /// This is the polar variant of oklab, in which the hue is encoded as
98    /// a polar coordinate.
99    ///
100    /// # Returns
101    ///
102    /// the color state object for oklch
103    #[cfg(feature = "v4_18")]
104    #[cfg_attr(docsrs, doc(cfg(feature = "v4_18")))]
105    #[doc(alias = "gdk_color_state_get_oklch")]
106    #[doc(alias = "get_oklch")]
107    pub fn oklch() -> ColorState {
108        assert_initialized_main_thread!();
109        unsafe { from_glib_full(ffi::gdk_color_state_get_oklch()) }
110    }
111
112    /// Returns the color state object representing the linear rec2100 color space.
113    ///
114    /// This color state uses the primaries defined by BT.2020-2 and BT.2100-0 and a linear
115    /// transfer function.
116    ///
117    /// It is equivalent to the [Cicp](class.CicpParams.html) tuple 9/8/0/1.
118    ///
119    /// See e.g. [the CSS HDR Module](https://drafts.csswg.org/css-color-hdr/#valdef-color-rec2100-linear)
120    /// for details about this colorstate.
121    ///
122    /// # Returns
123    ///
124    /// the color state object for linearized rec2100
125    #[doc(alias = "gdk_color_state_get_rec2100_linear")]
126    #[doc(alias = "get_rec2100_linear")]
127    pub fn rec2100_linear() -> ColorState {
128        assert_initialized_main_thread!();
129        unsafe { from_glib_full(ffi::gdk_color_state_get_rec2100_linear()) }
130    }
131
132    /// Returns the color state object representing the rec2100-pq color space.
133    ///
134    /// This color state uses the primaries defined by BT.2020-2 and BT.2100-0 and the transfer
135    /// function defined by SMPTE ST 2084 and BT.2100-2.
136    ///
137    /// It is equivalent to the [Cicp](class.CicpParams.html) tuple 9/16/0/1.
138    ///
139    /// See e.g. [the CSS HDR Module](https://drafts.csswg.org/css-color-hdr/#valdef-color-rec2100-pq)
140    /// for details about this colorstate.
141    ///
142    /// # Returns
143    ///
144    /// the color state object for rec2100-pq
145    #[doc(alias = "gdk_color_state_get_rec2100_pq")]
146    #[doc(alias = "get_rec2100_pq")]
147    pub fn rec2100_pq() -> ColorState {
148        assert_initialized_main_thread!();
149        unsafe { from_glib_full(ffi::gdk_color_state_get_rec2100_pq()) }
150    }
151
152    /// Returns the color state object representing the sRGB color space.
153    ///
154    /// This color state uses the primaries defined by BT.709-6 and the transfer function
155    /// defined by IEC 61966-2-1.
156    ///
157    /// It is equivalent to the [Cicp](class.CicpParams.html) tuple 1/13/0/1.
158    ///
159    /// See e.g. [the CSS Color Module](https://www.w3.org/TR/css-color-4/#predefined-sRGB)
160    /// for details about this colorstate.
161    ///
162    /// # Returns
163    ///
164    /// the color state object for sRGB
165    #[doc(alias = "gdk_color_state_get_srgb")]
166    #[doc(alias = "get_srgb")]
167    pub fn srgb() -> ColorState {
168        assert_initialized_main_thread!();
169        unsafe { from_glib_full(ffi::gdk_color_state_get_srgb()) }
170    }
171
172    /// Returns the color state object representing the linearized sRGB color space.
173    ///
174    /// This color state uses the primaries defined by BT.709-6 and a linear transfer function.
175    ///
176    /// It is equivalent to the [Cicp](class.CicpParams.html) tuple 1/8/0/1.
177    ///
178    /// See e.g. [the CSS Color Module](https://www.w3.org/TR/css-color-4/#predefined-sRGB-linear)
179    /// for details about this colorstate.
180    ///
181    /// # Returns
182    ///
183    /// the color state object for linearized sRGB
184    #[doc(alias = "gdk_color_state_get_srgb_linear")]
185    #[doc(alias = "get_srgb_linear")]
186    pub fn srgb_linear() -> ColorState {
187        assert_initialized_main_thread!();
188        unsafe { from_glib_full(ffi::gdk_color_state_get_srgb_linear()) }
189    }
190}
191
192impl PartialEq for ColorState {
193    #[inline]
194    fn eq(&self, other: &Self) -> bool {
195        self.equal(other)
196    }
197}
198
199impl Eq for ColorState {}