From e14f3ba1aa4ba3f38520cf51c9dd6c848fea61b4 Mon Sep 17 00:00:00 2001 From: Brezak Date: Mon, 10 Jun 2024 23:25:31 +0200 Subject: [PATCH] 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. --- crates/bevy_pbr/src/pbr_material.rs | 5 +++++ crates/bevy_sprite/src/mesh2d/color_material.rs | 7 +++++++ 2 files changed, 12 insertions(+) diff --git a/crates/bevy_pbr/src/pbr_material.rs b/crates/bevy_pbr/src/pbr_material.rs index 1d21348f29..be166de2d1 100644 --- a/crates/bevy_pbr/src/pbr_material.rs +++ b/crates/bevy_pbr/src/pbr_material.rs @@ -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) -> Self { + Self::from(color.into()) + } } impl Default for StandardMaterial { diff --git a/crates/bevy_sprite/src/mesh2d/color_material.rs b/crates/bevy_sprite/src/mesh2d/color_material.rs index 78061ce06d..38d74bb473 100644 --- a/crates/bevy_sprite/src/mesh2d/color_material.rs +++ b/crates/bevy_sprite/src/mesh2d/color_material.rs @@ -51,6 +51,13 @@ pub struct ColorMaterial { pub texture: Option>, } +impl ColorMaterial { + /// Creates a new material from a given color + pub fn from_color(color: impl Into) -> Self { + Self::from(color.into()) + } +} + impl Default for ColorMaterial { fn default() -> Self { ColorMaterial {