diff --git a/gdk4/src/rgba.rs b/gdk4/src/rgba.rs index 57d0c1b6d4e2..533f1e39c507 100644 --- a/gdk4/src/rgba.rs +++ b/gdk4/src/rgba.rs @@ -4,17 +4,18 @@ use crate::RGBA; use glib::{translate::*, IntoGStr}; use std::{fmt, str::FromStr}; -#[derive(Debug, Default)] +#[derive(Debug)] // rustdoc-stripper-ignore-next /// A [builder-pattern] type to construct [`RGBA`] objects. /// /// [builder-pattern]: https://doc.rust-lang.org/1.0.0/style/ownership/builders.html #[must_use = "The builder must be built to be used"] -pub struct RGBABuilder { - red: Option, - green: Option, - blue: Option, - alpha: Option, +pub struct RGBABuilder(RGBA); + +impl Default for RGBABuilder { + fn default() -> Self { + Self(RGBA::WHITE) + } } impl RGBABuilder { @@ -25,22 +26,22 @@ impl RGBABuilder { } pub fn blue(mut self, blue: f32) -> Self { - self.blue = Some(blue); + self.0.set_blue(blue); self } pub fn green(mut self, green: f32) -> Self { - self.green = Some(green); + self.0.set_green(green); self } pub fn red(mut self, red: f32) -> Self { - self.red = Some(red); + self.0.set_red(red); self } pub fn alpha(mut self, alpha: f32) -> Self { - self.alpha = Some(alpha); + self.0.set_alpha(alpha); self } @@ -48,20 +49,7 @@ impl RGBABuilder { /// Build the [`RGBA`]. #[must_use = "The RGBA returned by this builder should probably be used"] pub fn build(self) -> RGBA { - let mut rgba = RGBA::WHITE; - if let Some(blue) = self.blue { - rgba.set_blue(blue); - } - if let Some(red) = self.red { - rgba.set_red(red); - } - if let Some(green) = self.green { - rgba.set_green(green); - } - if let Some(alpha) = self.alpha { - rgba.set_alpha(alpha); - } - rgba + self.0 } } @@ -220,59 +208,17 @@ impl RGBA { } } - pub const BLACK: RGBA = Self { - inner: ffi::GdkRGBA { - red: 0f32, - green: 0f32, - blue: 0f32, - alpha: 1f32, - }, - }; - - pub const BLUE: RGBA = Self { - inner: ffi::GdkRGBA { - red: 0f32, - green: 0f32, - blue: 1f32, - alpha: 1f32, - }, - }; - - pub const GREEN: RGBA = Self { - inner: ffi::GdkRGBA { - red: 0f32, - green: 1f32, - blue: 0f32, - alpha: 1f32, - }, - }; - - pub const RED: RGBA = Self { - inner: ffi::GdkRGBA { - red: 1f32, - green: 0f32, - blue: 0f32, - alpha: 1f32, - }, - }; - - pub const WHITE: RGBA = Self { - inner: ffi::GdkRGBA { - red: 1f32, - green: 1f32, - blue: 1f32, - alpha: 1f32, - }, - }; - - pub const TRANSPARENT: RGBA = Self { - inner: ffi::GdkRGBA { - red: 0f32, - green: 0f32, - blue: 0f32, - alpha: 0f32, - }, - }; + pub const BLACK: RGBA = Self::new(0f32, 0f32, 0f32, 1f32); + + pub const BLUE: RGBA = Self::new(0f32, 0f32, 1f32, 1f32); + + pub const GREEN: RGBA = Self::new(0f32, 1f32, 0f32, 1f32); + + pub const RED: RGBA = Self::new(1f32, 0f32, 0f32, 1f32); + + pub const WHITE: RGBA = Self::new(1f32, 1f32, 1f32, 1f32); + + pub const TRANSPARENT: RGBA = Self::new(0f32, 0f32, 0f32, 0f32); } impl fmt::Debug for RGBA {