Skip to content

Commit 46e8c6b

Browse files
authored
Consistency between Wireframe2d and Wireframe (#14720)
# Objective - Wireframe plugins have inconsistencies between 3D and 2D versions. This PR addresses the following - 2d version uses `Srgba` for colors, 3d version uses `Color`. ## Solution - This PR brings consistency by doing the following change - `Wireframe2d` now uses `Color` instead of `Srgba` ## Testing - `wireframe_2d` and `wireframe` examples were verified and they work as before. --- ## Migration Guide - `Wireframe2dConfig`.`default_color` type is now `Color` instead of `Srgba`. Use `.into()` to convert between them. - `Wireframe2dColor`.`color` type is now `Color` instead of `Srgba`. Use `.into()` to convert between them.
1 parent 882973a commit 46e8c6b

File tree

2 files changed

+18
-11
lines changed

2 files changed

+18
-11
lines changed

crates/bevy_sprite/src/mesh2d/wireframe2d.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use crate::{Material2d, Material2dKey, Material2dPlugin, Mesh2dHandle};
22
use bevy_app::{Plugin, Startup, Update};
33
use bevy_asset::{load_internal_asset, Asset, Assets, Handle};
4-
use bevy_color::{LinearRgba, Srgba};
4+
use bevy_color::{Color, LinearRgba};
55
use bevy_ecs::prelude::*;
66
use bevy_reflect::{std_traits::ReflectDefault, Reflect, TypePath};
77
use bevy_render::{
@@ -67,7 +67,7 @@ pub struct Wireframe2d;
6767
#[derive(Component, Debug, Clone, Default, Reflect)]
6868
#[reflect(Component, Default)]
6969
pub struct Wireframe2dColor {
70-
pub color: Srgba,
70+
pub color: Color,
7171
}
7272

7373
/// Disables wireframe rendering for any entity it is attached to.
@@ -81,13 +81,13 @@ pub struct NoWireframe2d;
8181
#[derive(Resource, Debug, Clone, Default, ExtractResource, Reflect)]
8282
#[reflect(Resource)]
8383
pub struct Wireframe2dConfig {
84-
/// Whether to show wireframes for all meshes.
84+
/// Whether to show wireframes for all 2D meshes.
8585
/// Can be overridden for individual meshes by adding a [`Wireframe2d`] or [`NoWireframe2d`] component.
8686
pub global: bool,
8787
/// If [`Self::global`] is set, any [`Entity`] that does not have a [`Wireframe2d`] component attached to it will have
8888
/// wireframes using this color. Otherwise, this will be the fallback color for any entity that has a [`Wireframe2d`],
8989
/// but no [`Wireframe2dColor`].
90-
pub default_color: Srgba,
90+
pub default_color: Color,
9191
}
9292

9393
#[derive(Resource)]

examples/2d/wireframe_2d.rs

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ fn main() {
4444
global: true,
4545
// Controls the default color of all wireframes. Used as the default color for global wireframes.
4646
// Can be changed per mesh using the `Wireframe2dColor` component.
47-
default_color: WHITE,
47+
default_color: WHITE.into(),
4848
})
4949
.add_systems(Startup, setup)
5050
.add_systems(Update, update_colors)
@@ -91,7 +91,9 @@ fn setup(
9191
Wireframe2d,
9292
// This lets you configure the wireframe color of this entity.
9393
// If not set, this will use the color in `WireframeConfig`
94-
Wireframe2dColor { color: GREEN },
94+
Wireframe2dColor {
95+
color: GREEN.into(),
96+
},
9597
));
9698

9799
// Camera
@@ -126,7 +128,8 @@ Wireframe2dConfig
126128
-------------
127129
Global: {}
128130
Color: {:?}",
129-
config.global, config.default_color,
131+
config.global,
132+
config.default_color.to_srgba(),
130133
);
131134

132135
// Toggle showing a wireframe on all meshes
@@ -136,17 +139,21 @@ Color: {:?}",
136139

137140
// Toggle the global wireframe color
138141
if keyboard_input.just_pressed(KeyCode::KeyX) {
139-
config.default_color = if config.default_color == WHITE {
140-
RED
142+
config.default_color = if config.default_color == WHITE.into() {
143+
RED.into()
141144
} else {
142-
WHITE
145+
WHITE.into()
143146
};
144147
}
145148

146149
// Toggle the color of a wireframe using `Wireframe2dColor` and not the global color
147150
if keyboard_input.just_pressed(KeyCode::KeyC) {
148151
for mut color in &mut wireframe_colors {
149-
color.color = if color.color == GREEN { RED } else { GREEN };
152+
color.color = if color.color == GREEN.into() {
153+
RED.into()
154+
} else {
155+
GREEN.into()
156+
};
150157
}
151158
}
152159
}

0 commit comments

Comments
 (0)