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