Skip to main content

gdk/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 glib::translate::*;
6use std::{fmt, hash};
7
8glib::wrapper! {
9    /// A [`RGBA`][crate::RGBA] is used to represent a (possibly translucent)
10    /// color, in a way that is compatible with cairo’s notion of color.
11    pub struct RGBA(BoxedInline<ffi::GdkRGBA>);
12
13    match fn {
14        copy => |ptr| ffi::gdk_rgba_copy(ptr),
15        free => |ptr| ffi::gdk_rgba_free(ptr),
16        type_ => || ffi::gdk_rgba_get_type(),
17    }
18}
19
20impl RGBA {
21    #[doc(alias = "gdk_rgba_equal")]
22    fn equal(&self, p2: &RGBA) -> bool {
23        unsafe {
24            from_glib(ffi::gdk_rgba_equal(
25                ToGlibPtr::<*const ffi::GdkRGBA>::to_glib_none(self).0 as glib::ffi::gconstpointer,
26                ToGlibPtr::<*const ffi::GdkRGBA>::to_glib_none(p2).0 as glib::ffi::gconstpointer,
27            ))
28        }
29    }
30
31    #[doc(alias = "gdk_rgba_hash")]
32    fn hash(&self) -> u32 {
33        unsafe {
34            ffi::gdk_rgba_hash(
35                ToGlibPtr::<*const ffi::GdkRGBA>::to_glib_none(self).0 as glib::ffi::gconstpointer,
36            )
37        }
38    }
39
40    /// Returns a textual specification of `self` in the form
41    /// `rgb(r,g,b)` or
42    /// `rgba(r g,b,a)`,
43    /// where “r”, “g”, “b” and “a” represent the red, green,
44    /// blue and alpha values respectively. “r”, “g”, and “b” are
45    /// represented as integers in the range 0 to 255, and “a”
46    /// is represented as a floating point value in the range 0 to 1.
47    ///
48    /// These string forms are string forms that are supported by
49    /// the CSS3 colors module, and can be parsed by [`parse()`][Self::parse()].
50    ///
51    /// Note that this string representation may lose some
52    /// precision, since “r”, “g” and “b” are represented as 8-bit
53    /// integers. If this is a concern, you should use a
54    /// different representation.
55    ///
56    /// # Returns
57    ///
58    /// A newly allocated text string
59    #[doc(alias = "gdk_rgba_to_string")]
60    #[doc(alias = "to_string")]
61    pub fn to_str(&self) -> glib::GString {
62        unsafe { from_glib_full(ffi::gdk_rgba_to_string(self.to_glib_none().0)) }
63    }
64}
65
66impl PartialEq for RGBA {
67    #[inline]
68    fn eq(&self, other: &Self) -> bool {
69        self.equal(other)
70    }
71}
72
73impl Eq for RGBA {}
74
75impl fmt::Display for RGBA {
76    #[inline]
77    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
78        f.write_str(&self.to_str())
79    }
80}
81
82impl hash::Hash for RGBA {
83    #[inline]
84    fn hash<H>(&self, state: &mut H)
85    where
86        H: hash::Hasher,
87    {
88        hash::Hash::hash(&self.hash(), state)
89    }
90}