Add from_color to StandardMaterial and ColorMaterial (#13791)

# 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.
This commit is contained in:
Brezak 2024-06-10 23:25:31 +02:00 committed by François
parent 9a82ecfcba
commit e14f3ba1aa
No known key found for this signature in database
2 changed files with 12 additions and 0 deletions

View File

@ -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 {

View File

@ -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 {