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    /// Returns the color state object representing the oklab color space.
58    ///
59    /// This is a perceptually uniform color state.
60    ///
61    /// # Returns
62    ///
63    /// the color state object for oklab
64    #[cfg(feature = "v4_18")]
65    #[cfg_attr(docsrs, doc(cfg(feature = "v4_18")))]
66    #[doc(alias = "gdk_color_state_get_oklab")]
67    #[doc(alias = "get_oklab")]
68    pub fn oklab() -> ColorState {
69        assert_initialized_main_thread!();
70        unsafe { from_glib_full(ffi::gdk_color_state_get_oklab()) }
71    }
72
73    /// Returns the color state object representing the oklch color space.
74    ///
75    /// This is the polar variant of oklab, in which the hue is encoded as
76    /// a polar coordinate.
77    ///
78    /// # Returns
79    ///
80    /// the color state object for oklch
81    #[cfg(feature = "v4_18")]
82    #[cfg_attr(docsrs, doc(cfg(feature = "v4_18")))]
83    #[doc(alias = "gdk_color_state_get_oklch")]
84    #[doc(alias = "get_oklch")]
85    pub fn oklch() -> ColorState {
86        assert_initialized_main_thread!();
87        unsafe { from_glib_full(ffi::gdk_color_state_get_oklch()) }
88    }
89
90    /// Returns the color state object representing the linear rec2100 color space.
91    ///
92    /// This color state uses the primaries defined by BT.2020-2 and BT.2100-0 and a linear
93    /// transfer function.
94    ///
95    /// It is equivalent to the [Cicp](class.CicpParams.html) tuple 9/8/0/1.
96    ///
97    /// See e.g. [the CSS HDR Module](https://drafts.csswg.org/css-color-hdr/#valdef-color-rec2100-linear)
98    /// for details about this colorstate.
99    ///
100    /// # Returns
101    ///
102    /// the color state object for linearized rec2100
103    #[doc(alias = "gdk_color_state_get_rec2100_linear")]
104    #[doc(alias = "get_rec2100_linear")]
105    pub fn rec2100_linear() -> ColorState {
106        assert_initialized_main_thread!();
107        unsafe { from_glib_full(ffi::gdk_color_state_get_rec2100_linear()) }
108    }
109
110    /// Returns the color state object representing the rec2100-pq color space.
111    ///
112    /// This color state uses the primaries defined by BT.2020-2 and BT.2100-0 and the transfer
113    /// function defined by SMPTE ST 2084 and BT.2100-2.
114    ///
115    /// It is equivalent to the [Cicp](class.CicpParams.html) tuple 9/16/0/1.
116    ///
117    /// See e.g. [the CSS HDR Module](https://drafts.csswg.org/css-color-hdr/#valdef-color-rec2100-pq)
118    /// for details about this colorstate.
119    ///
120    /// # Returns
121    ///
122    /// the color state object for rec2100-pq
123    #[doc(alias = "gdk_color_state_get_rec2100_pq")]
124    #[doc(alias = "get_rec2100_pq")]
125    pub fn rec2100_pq() -> ColorState {
126        assert_initialized_main_thread!();
127        unsafe { from_glib_full(ffi::gdk_color_state_get_rec2100_pq()) }
128    }
129
130    /// Returns the color state object representing the sRGB color space.
131    ///
132    /// This color state uses the primaries defined by BT.709-6 and the transfer function
133    /// defined by IEC 61966-2-1.
134    ///
135    /// It is equivalent to the [Cicp](class.CicpParams.html) tuple 1/13/0/1.
136    ///
137    /// See e.g. [the CSS Color Module](https://www.w3.org/TR/css-color-4/#predefined-sRGB)
138    /// for details about this colorstate.
139    ///
140    /// # Returns
141    ///
142    /// the color state object for sRGB
143    #[doc(alias = "gdk_color_state_get_srgb")]
144    #[doc(alias = "get_srgb")]
145    pub fn srgb() -> ColorState {
146        assert_initialized_main_thread!();
147        unsafe { from_glib_full(ffi::gdk_color_state_get_srgb()) }
148    }
149
150    /// Returns the color state object representing the linearized sRGB color space.
151    ///
152    /// This color state uses the primaries defined by BT.709-6 and a linear transfer function.
153    ///
154    /// It is equivalent to the [Cicp](class.CicpParams.html) tuple 1/8/0/1.
155    ///
156    /// See e.g. [the CSS Color Module](https://www.w3.org/TR/css-color-4/#predefined-sRGB-linear)
157    /// for details about this colorstate.
158    ///
159    /// # Returns
160    ///
161    /// the color state object for linearized sRGB
162    #[doc(alias = "gdk_color_state_get_srgb_linear")]
163    #[doc(alias = "get_srgb_linear")]
164    pub fn srgb_linear() -> ColorState {
165        assert_initialized_main_thread!();
166        unsafe { from_glib_full(ffi::gdk_color_state_get_srgb_linear()) }
167    }
168}
169
170impl PartialEq for ColorState {
171    #[inline]
172    fn eq(&self, other: &Self) -> bool {
173        self.equal(other)
174    }
175}
176
177impl Eq for ColorState {}