Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New release! #1494

Merged
merged 15 commits into from
Sep 23, 2023
Prev Previous commit
Next Next commit
gdk: Add with_* constructors for RGBA
  • Loading branch information
SeaDve authored and bilelmoussaoui committed Sep 23, 2023
commit d1101b3934fe025e5b1df217abd95451f1f28330
78 changes: 78 additions & 0 deletions gdk4/src/rgba.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,84 @@ impl RGBA {
}
}

// rustdoc-stripper-ignore-next
/// 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.5), RGBA::new(0.5, 1.0, 1.0, 1.0));
/// ```
#[inline]
pub const fn with_red(self, red: f32) -> Self {
Self {
inner: ffi::GdkRGBA { red, ..self.inner },
}
}

// rustdoc-stripper-ignore-next
/// 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.5), RGBA::new(1.0, 0.5, 1.0, 1.0));
/// ```
#[inline]
pub const fn with_green(self, green: f32) -> Self {
Self {
inner: ffi::GdkRGBA {
green,
..self.inner
},
}
}

// rustdoc-stripper-ignore-next
/// 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.5), RGBA::new(1.0, 1.0, 0.5, 1.0));
/// ```
#[inline]
pub const fn with_blue(self, blue: f32) -> Self {
Self {
inner: ffi::GdkRGBA { blue, ..self.inner },
}
}

// rustdoc-stripper-ignore-next
/// 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.5), RGBA::new(1.0, 1.0, 1.0, 0.5));
/// ```
#[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