Skip to content

Commit

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

# Objective

Closes bevyengine#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 Jun 10, 2024
1 parent c172c3c commit d803adf
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 d803adf

Please sign in to comment.