Skip to content

Commit 2f38d3a

Browse files
SeaDvebilelmoussaoui
authored andcommitted
gdk: Add with_* constructors for RGBA
1 parent cf661f5 commit 2f38d3a

File tree

1 file changed

+78
-0
lines changed

1 file changed

+78
-0
lines changed

gdk4/src/rgba.rs

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,84 @@ impl RGBA {
7979
}
8080
}
8181

82+
// rustdoc-stripper-ignore-next
83+
/// Creates an owned [`RGBA`] like `self` but with the given red value.
84+
///
85+
/// # Example
86+
///
87+
/// ```
88+
/// # use gdk4::RGBA;
89+
///
90+
/// let rgba = RGBA::new(1.0, 1.0, 1.0, 1.0);
91+
/// assert_eq!(rgba.with_red(0.5), RGBA::new(0.5, 1.0, 1.0, 1.0));
92+
/// ```
93+
#[inline]
94+
pub const fn with_red(self, red: f32) -> Self {
95+
Self {
96+
inner: ffi::GdkRGBA { red, ..self.inner },
97+
}
98+
}
99+
100+
// rustdoc-stripper-ignore-next
101+
/// Creates an owned [`RGBA`] like `self` but with the given green value.
102+
///
103+
/// # Example
104+
///
105+
/// ```
106+
/// # use gdk4::RGBA;
107+
///
108+
/// let rgba = RGBA::new(1.0, 1.0, 1.0, 1.0);
109+
/// assert_eq!(rgba.with_green(0.5), RGBA::new(1.0, 0.5, 1.0, 1.0));
110+
/// ```
111+
#[inline]
112+
pub const fn with_green(self, green: f32) -> Self {
113+
Self {
114+
inner: ffi::GdkRGBA {
115+
green,
116+
..self.inner
117+
},
118+
}
119+
}
120+
121+
// rustdoc-stripper-ignore-next
122+
/// Creates an owned [`RGBA`] like `self` but with the given blue value.
123+
///
124+
/// # Example
125+
///
126+
/// ```
127+
/// # use gdk4::RGBA;
128+
///
129+
/// let rgba = RGBA::new(1.0, 1.0, 1.0, 1.0);
130+
/// assert_eq!(rgba.with_blue(0.5), RGBA::new(1.0, 1.0, 0.5, 1.0));
131+
/// ```
132+
#[inline]
133+
pub const fn with_blue(self, blue: f32) -> Self {
134+
Self {
135+
inner: ffi::GdkRGBA { blue, ..self.inner },
136+
}
137+
}
138+
139+
// rustdoc-stripper-ignore-next
140+
/// Creates an owned [`RGBA`] like `self` but with the given alpha value.
141+
///
142+
/// # Example
143+
///
144+
/// ```
145+
/// # use gdk4::RGBA;
146+
///
147+
/// let rgba = RGBA::new(1.0, 1.0, 1.0, 1.0);
148+
/// assert_eq!(rgba.with_alpha(0.5), RGBA::new(1.0, 1.0, 1.0, 0.5));
149+
/// ```
150+
#[inline]
151+
pub const fn with_alpha(self, alpha: f32) -> Self {
152+
Self {
153+
inner: ffi::GdkRGBA {
154+
alpha,
155+
..self.inner
156+
},
157+
}
158+
}
159+
82160
// rustdoc-stripper-ignore-next
83161
/// Creates a new builder-pattern struct instance to construct [`RGBA`] objects.
84162
///

0 commit comments

Comments
 (0)