Skip to content

Commit

Permalink
gdk: Add with_* constructors for RGBA
Browse files Browse the repository at this point in the history
  • Loading branch information
SeaDve committed Aug 16, 2023
1 parent f27af90 commit 6046ab1
Showing 1 changed file with 74 additions and 0 deletions.
74 changes: 74 additions & 0 deletions gdk4/src/rgba.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,80 @@ impl RGBA {
}
}

/// Creates an owned [`RGBA`] like `self` but with the given red value.
///
/// # Example
///
/// ```
/// # use gdk4::RGBA;
///
/// let rgba = RGBA::new(1.0, 1.0, 1.0, 1.0);
/// assert_eq!(rgba.with_red(0.0), RGBA::new(0.0, 1.0, 1.0, 1.0));
/// ```
#[inline]
pub const fn with_red(self, red: f32) -> Self {
Self {
inner: ffi::GdkRGBA { red, ..self.inner },
}
}

/// Creates an owned [`RGBA`] like `self` but with the given green value.
///
/// # Example
///
/// ```
/// # use gdk4::RGBA;
///
/// let rgba = RGBA::new(1.0, 1.0, 1.0, 1.0);
/// assert_eq!(rgba.with_green(0.0), RGBA::new(1.0, 0.0, 1.0, 1.0));
/// ```
#[inline]
pub const fn with_green(self, green: f32) -> Self {
Self {
inner: ffi::GdkRGBA {
green,
..self.inner
},
}
}

/// Creates an owned [`RGBA`] like `self` but with the given blue value.
///
/// # Example
///
/// ```
/// # use gdk4::RGBA;
///
/// let rgba = RGBA::new(1.0, 1.0, 1.0, 1.0);
/// assert_eq!(rgba.with_blue(0.0), RGBA::new(1.0, 1.0, 0.0, 1.0));
/// ```
#[inline]
pub const fn with_blue(self, blue: f32) -> Self {
Self {
inner: ffi::GdkRGBA { blue, ..self.inner },
}
}

/// Creates an owned [`RGBA`] like `self` but with the given alpha value.
///
/// # Example
///
/// ```
/// # use gdk4::RGBA;
///
/// let rgba = RGBA::new(1.0, 1.0, 1.0, 1.0);
/// assert_eq!(rgba.with_alpha(0.0), RGBA::new(1.0, 1.0, 1.0, 0.0));
/// ```
#[inline]
pub const fn with_alpha(self, alpha: f32) -> Self {
Self {
inner: ffi::GdkRGBA {
alpha,
..self.inner
},
}
}

// rustdoc-stripper-ignore-next
/// Creates a new builder-pattern struct instance to construct [`RGBA`] objects.
///
Expand Down

0 comments on commit 6046ab1

Please sign in to comment.