Skip to content

Commit

Permalink
impl From<Color> for ClearColorConfig (#10734)
Browse files Browse the repository at this point in the history
# Objective

I tried setting `ClearColorConfig` in my app via `Color::FOO.into()`
expecting it to work, but the impl was missing.

## Solution

- Add `impl From<Color> for ClearColorConfig`
- Change examples to use this impl

## Changelog

### Added

- `ClearColorConfig` can be constructed via `.into()` on a `Color`

---------

Signed-off-by: Torstein Grindvik <torstein.grindvik@muybridge.com>
Co-authored-by: Torstein Grindvik <torstein.grindvik@muybridge.com>
  • Loading branch information
torsteingrindvik and Torstein Grindvik authored Nov 26, 2023
1 parent 4788315 commit 73bb310
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 7 deletions.
6 changes: 6 additions & 0 deletions crates/bevy_core_pipeline/src/clear_color.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,12 @@ pub enum ClearColorConfig {
None,
}

impl From<Color> for ClearColorConfig {
fn from(color: Color) -> Self {
Self::Custom(color)
}
}

/// A [`Resource`] that stores the color that is used to clear the screen between frames.
///
/// This color appears as the "background" color for simple apps,
Expand Down
3 changes: 1 addition & 2 deletions examples/3d/render_to_texture.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
use std::f32::consts::PI;

use bevy::{
core_pipeline::clear_color::ClearColorConfig,
prelude::*,
render::{
camera::RenderTarget,
Expand Down Expand Up @@ -97,7 +96,7 @@ fn setup(
commands.spawn((
Camera3dBundle {
camera_3d: Camera3d {
clear_color: ClearColorConfig::Custom(Color::WHITE),
clear_color: Color::WHITE.into(),
..default()
},
camera: Camera {
Expand Down
7 changes: 2 additions & 5 deletions examples/shader/post_processing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,7 @@
//! This is a fairly low level example and assumes some familiarity with rendering concepts and wgpu.
use bevy::{
core_pipeline::{
clear_color::ClearColorConfig, core_3d,
fullscreen_vertex_shader::fullscreen_shader_vertex_state,
},
core_pipeline::{core_3d, fullscreen_vertex_shader::fullscreen_shader_vertex_state},
ecs::query::QueryItem,
prelude::*,
render::{
Expand Down Expand Up @@ -330,7 +327,7 @@ fn setup(
transform: Transform::from_translation(Vec3::new(0.0, 0.0, 5.0))
.looking_at(Vec3::default(), Vec3::Y),
camera_3d: Camera3d {
clear_color: ClearColorConfig::Custom(Color::WHITE),
clear_color: Color::WHITE.into(),
..default()
},
..default()
Expand Down

0 comments on commit 73bb310

Please sign in to comment.