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

add Color methods to change one component #227

Merged
merged 1 commit into from
Jan 26, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions src/graphics/color.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,26 @@ impl Color {
Ok(Color::rgba8(r, g, b, a))
}

/// Returns the color with the red component set to the specified value.
pub const fn with_red(self, r: f32) -> Self {
Self { r, ..self }
}

/// Returns the color with the green component set to the specified value.
pub const fn with_green(self, g: f32) -> Self {
Self { g, ..self }
}

/// Returns the color with the blue component set to the specified value.
pub const fn with_blue(self, b: f32) -> Self {
Self { b, ..self }
}

/// Returns the color with the alpha component set to the specified value.
pub const fn with_alpha(self, a: f32) -> Self {
Self { a, ..self }
}

// These constants should remain at the bottom of the impl block to keep
// the docs readable - don't want to have to scroll through a load of colors
// to get to the methods!
Expand Down