gdk4/auto/
rgba.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;
6use glib::translate::*;
7
8glib::wrapper! {
9    /// Represents a color, in a way that is compatible with cairo’s notion of color.
10    ///
11    /// [`RGBA`][crate::RGBA] is a convenient way to pass colors around. It’s based on
12    /// cairo’s way to deal with colors and mirrors its behavior. All values
13    /// are in the range from 0.0 to 1.0 inclusive. So the color
14    /// (0.0, 0.0, 0.0, 0.0) represents transparent black and
15    /// (1.0, 1.0, 1.0, 1.0) is opaque white. Other values will
16    /// be clamped to this range when drawing.
17    pub struct RGBA(BoxedInline<ffi::GdkRGBA>);
18
19    match fn {
20        copy => |ptr| ffi::gdk_rgba_copy(ptr),
21        free => |ptr| ffi::gdk_rgba_free(ptr),
22        type_ => || ffi::gdk_rgba_get_type(),
23    }
24}
25
26impl RGBA {
27    #[doc(alias = "gdk_rgba_equal")]
28    fn equal(&self, p2: &RGBA) -> bool {
29        unsafe {
30            from_glib(ffi::gdk_rgba_equal(
31                ToGlibPtr::<*const ffi::GdkRGBA>::to_glib_none(self).0 as glib::ffi::gconstpointer,
32                ToGlibPtr::<*const ffi::GdkRGBA>::to_glib_none(p2).0 as glib::ffi::gconstpointer,
33            ))
34        }
35    }
36
37    #[doc(alias = "gdk_rgba_hash")]
38    fn hash(&self) -> u32 {
39        unsafe {
40            ffi::gdk_rgba_hash(
41                ToGlibPtr::<*const ffi::GdkRGBA>::to_glib_none(self).0 as glib::ffi::gconstpointer,
42            )
43        }
44    }
45
46    /// Checks if an @self value is transparent.
47    ///
48    /// That is, drawing with the value would not produce any change.
49    ///
50    /// # Returns
51    ///
52    /// [`true`] if the @self is clear
53    #[doc(alias = "gdk_rgba_is_clear")]
54    pub fn is_clear(&self) -> bool {
55        unsafe { from_glib(ffi::gdk_rgba_is_clear(self.to_glib_none().0)) }
56    }
57
58    /// Checks if an @self value is opaque.
59    ///
60    /// That is, drawing with the value will not retain any results
61    /// from previous contents.
62    ///
63    /// # Returns
64    ///
65    /// [`true`] if the @self is opaque
66    #[doc(alias = "gdk_rgba_is_opaque")]
67    pub fn is_opaque(&self) -> bool {
68        unsafe { from_glib(ffi::gdk_rgba_is_opaque(self.to_glib_none().0)) }
69    }
70
71    /// Returns a textual specification of @self in the form
72    /// `rgb(r,g,b)` or `rgba(r,g,b,a)`, where “r”, “g”, “b” and
73    /// “a” represent the red, green, blue and alpha values
74    /// respectively. “r”, “g”, and “b” are represented as integers
75    /// in the range 0 to 255, and “a” is represented as a floating
76    /// point value in the range 0 to 1.
77    ///
78    /// These string forms are string forms that are supported by
79    /// the CSS3 colors module, and can be parsed by [`parse()`][Self::parse()].
80    ///
81    /// Note that this string representation may lose some precision,
82    /// since “r”, “g” and “b” are represented as 8-bit integers. If
83    /// this is a concern, you should use a different representation.
84    ///
85    /// # Returns
86    ///
87    /// A newly allocated text string
88    #[doc(alias = "gdk_rgba_to_string")]
89    #[doc(alias = "to_string")]
90    pub fn to_str(&self) -> glib::GString {
91        unsafe { from_glib_full(ffi::gdk_rgba_to_string(self.to_glib_none().0)) }
92    }
93}
94
95impl PartialEq for RGBA {
96    #[inline]
97    fn eq(&self, other: &Self) -> bool {
98        self.equal(other)
99    }
100}
101
102impl Eq for RGBA {}
103
104impl std::fmt::Display for RGBA {
105    #[inline]
106    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
107        f.write_str(&self.to_str())
108    }
109}
110
111impl std::hash::Hash for RGBA {
112    #[inline]
113    fn hash<H>(&self, state: &mut H)
114    where
115        H: std::hash::Hasher,
116    {
117        std::hash::Hash::hash(&self.hash(), state)
118    }
119}