Skip to content

Commit

Permalink
Add from_color to StandardMaterial and ColorMaterial (#13791)
Browse files Browse the repository at this point in the history
# Objective

Closes #13738

## Solution

Added `from_color` to materials that would support it. Didn't add
`from_color` to `WireframeMaterial` as it doesn't seem we expect users
to be constructing them themselves.

## Testing

None

---

## Changelog

### Added

- `from_color` to `StandardMaterial` so you can construct this material
from any color type.
- `from_color` to `ColorMaterial` so you can construct this material
from any color type.
  • Loading branch information
Brezak authored and mockersf committed Jun 11, 2024
1 parent 9a82ecf commit e14f3ba
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
5 changes: 5 additions & 0 deletions crates/bevy_pbr/src/pbr_material.rs
Original file line number Diff line number Diff line change
Expand Up @@ -747,6 +747,11 @@ impl StandardMaterial {
self.flip(horizontal, vertical);
self
}

/// Creates a new material from a given color
pub fn from_color(color: impl Into<Color>) -> Self {
Self::from(color.into())
}
}

impl Default for StandardMaterial {
Expand Down
7 changes: 7 additions & 0 deletions crates/bevy_sprite/src/mesh2d/color_material.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,13 @@ pub struct ColorMaterial {
pub texture: Option<Handle<Image>>,
}

impl ColorMaterial {
/// Creates a new material from a given color
pub fn from_color(color: impl Into<Color>) -> Self {
Self::from(color.into())
}
}

impl Default for ColorMaterial {
fn default() -> Self {
ColorMaterial {
Expand Down

0 comments on commit e14f3ba

Please sign in to comment.