Skip to content

Commit 4b138af

Browse files
Rename bevy_sprite::sprite::ScalingMode to SpriteScalingMode (#21100)
# Objective There are two enums both called `ScalingMode`, `bevy_sprite::sprite::ScalingMode` and `bevy_camera::projection::ScalingMode`, in violition of the one namespace rule. Part of #19285 ## Solution Rename `bevy_sprite::sprite::ScalingMode` to `bevy_sprite::sprite::SpriteScalingMode`. Chose to rename the sprite enum as `bevy_camera::projection::ScalingMode` is much older and `OrthographicProjectionScalingMode` is a bit long. --------- Co-authored-by: Alice Cecile <[email protected]>
1 parent 8a2d9c1 commit 4b138af

File tree

5 files changed

+42
-34
lines changed

5 files changed

+42
-34
lines changed

crates/bevy_sprite/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ pub mod prelude {
3333
pub use crate::{
3434
sprite::{Sprite, SpriteImageMode},
3535
texture_slice::{BorderRect, SliceScaleMode, TextureSlice, TextureSlicer},
36-
ScalingMode,
36+
SpriteScalingMode,
3737
};
3838
}
3939

crates/bevy_sprite/src/sprite.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ pub enum SpriteImageMode {
169169
Auto,
170170
/// The texture will be scaled to fit the rect bounds defined in [`Sprite::custom_size`].
171171
/// Otherwise no scaling will be applied.
172-
Scale(ScalingMode),
172+
Scale(SpriteScalingMode),
173173
/// The texture will be cut in 9 slices, keeping the texture in proportions on resize
174174
Sliced(TextureSlicer),
175175
/// The texture will be repeated if stretched beyond `stretched_value`
@@ -194,10 +194,10 @@ impl SpriteImageMode {
194194
)
195195
}
196196

197-
/// Returns [`ScalingMode`] if scale is presented or [`Option::None`] otherwise.
197+
/// Returns [`SpriteScalingMode`] if scale is presented or [`Option::None`] otherwise.
198198
#[inline]
199199
#[must_use]
200-
pub const fn scale(&self) -> Option<ScalingMode> {
200+
pub const fn scale(&self) -> Option<SpriteScalingMode> {
201201
if let SpriteImageMode::Scale(scale) = self {
202202
Some(*scale)
203203
} else {
@@ -211,7 +211,7 @@ impl SpriteImageMode {
211211
/// Can be used in [`SpriteImageMode::Scale`].
212212
#[derive(Debug, Clone, Copy, PartialEq, Default, Reflect)]
213213
#[reflect(Debug, Default, Clone)]
214-
pub enum ScalingMode {
214+
pub enum SpriteScalingMode {
215215
/// Scale the texture uniformly (maintain the texture's aspect ratio)
216216
/// so that both dimensions (width and height) of the texture will be equal
217217
/// to or larger than the corresponding dimension of the target rectangle.

crates/bevy_sprite_render/src/render/mod.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ use bevy_render::{
3939
Extract,
4040
};
4141
use bevy_shader::{Shader, ShaderDefVal};
42-
use bevy_sprite::{Anchor, ScalingMode, Sprite};
42+
use bevy_sprite::{Anchor, Sprite, SpriteScalingMode};
4343
use bevy_transform::components::GlobalTransform;
4444
use bevy_utils::default;
4545
use bytemuck::{Pod, Zeroable};
@@ -334,7 +334,7 @@ pub enum ExtractedSpriteKind {
334334
Single {
335335
anchor: Vec2,
336336
rect: Option<Rect>,
337-
scaling_mode: Option<ScalingMode>,
337+
scaling_mode: Option<SpriteScalingMode>,
338338
custom_size: Option<Vec2>,
339339
},
340340
/// Indexes into the list of [`ExtractedSlice`]s stored in the [`ExtractedSlices`] resource
@@ -965,7 +965,7 @@ impl<P: PhaseItem> RenderCommand<P> for DrawSpriteBatch {
965965

966966
/// Scales a texture to fit within a given quad size with keeping the aspect ratio.
967967
fn apply_scaling(
968-
scaling_mode: ScalingMode,
968+
scaling_mode: SpriteScalingMode,
969969
texture_size: Vec2,
970970
quad_size: &mut Vec2,
971971
quad_translation: &mut Vec2,
@@ -977,7 +977,7 @@ fn apply_scaling(
977977
let quad_tex_scale = quad_ratio / texture_ratio;
978978

979979
match scaling_mode {
980-
ScalingMode::FillCenter => {
980+
SpriteScalingMode::FillCenter => {
981981
if quad_ratio > texture_ratio {
982982
// offset texture to center by y coordinate
983983
uv_offset_scale.y += (uv_offset_scale.w - uv_offset_scale.w * tex_quad_scale) * 0.5;
@@ -989,23 +989,23 @@ fn apply_scaling(
989989
uv_offset_scale.z *= quad_tex_scale;
990990
};
991991
}
992-
ScalingMode::FillStart => {
992+
SpriteScalingMode::FillStart => {
993993
if quad_ratio > texture_ratio {
994994
uv_offset_scale.y += uv_offset_scale.w - uv_offset_scale.w * tex_quad_scale;
995995
uv_offset_scale.w *= tex_quad_scale;
996996
} else {
997997
uv_offset_scale.z *= quad_tex_scale;
998998
}
999999
}
1000-
ScalingMode::FillEnd => {
1000+
SpriteScalingMode::FillEnd => {
10011001
if quad_ratio > texture_ratio {
10021002
uv_offset_scale.w *= tex_quad_scale;
10031003
} else {
10041004
uv_offset_scale.x += uv_offset_scale.z - uv_offset_scale.z * quad_tex_scale;
10051005
uv_offset_scale.z *= quad_tex_scale;
10061006
}
10071007
}
1008-
ScalingMode::FitCenter => {
1008+
SpriteScalingMode::FitCenter => {
10091009
if texture_ratio > quad_ratio {
10101010
// Scale based on width
10111011
quad_size.y *= quad_tex_scale;
@@ -1014,7 +1014,7 @@ fn apply_scaling(
10141014
quad_size.x *= tex_quad_scale;
10151015
}
10161016
}
1017-
ScalingMode::FitStart => {
1017+
SpriteScalingMode::FitStart => {
10181018
if texture_ratio > quad_ratio {
10191019
// The quad is scaled to match the image ratio, and the quad translation is adjusted
10201020
// to start of the quad within the original quad size.
@@ -1031,7 +1031,7 @@ fn apply_scaling(
10311031
*quad_size = new_quad;
10321032
}
10331033
}
1034-
ScalingMode::FitEnd => {
1034+
SpriteScalingMode::FitEnd => {
10351035
if texture_ratio > quad_ratio {
10361036
let scale = Vec2::new(1.0, quad_tex_scale);
10371037
let new_quad = *quad_size * scale;

examples/2d/sprite_scale.rs

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -31,49 +31,49 @@ fn setup_sprites(mut commands: Commands, asset_server: Res<AssetServer>) {
3131
text: "Fill Center".to_string(),
3232
transform: Transform::from_translation(Vec3::new(-450., 230., 0.)),
3333
texture: square.clone(),
34-
image_mode: SpriteImageMode::Scale(ScalingMode::FillCenter),
34+
image_mode: SpriteImageMode::Scale(SpriteScalingMode::FillCenter),
3535
},
3636
Rect {
3737
size: Vec2::new(100., 225.),
3838
text: "Fill Start".to_string(),
3939
transform: Transform::from_translation(Vec3::new(-330., 230., 0.)),
4040
texture: square.clone(),
41-
image_mode: SpriteImageMode::Scale(ScalingMode::FillStart),
41+
image_mode: SpriteImageMode::Scale(SpriteScalingMode::FillStart),
4242
},
4343
Rect {
4444
size: Vec2::new(100., 225.),
4545
text: "Fill End".to_string(),
4646
transform: Transform::from_translation(Vec3::new(-210., 230., 0.)),
4747
texture: square.clone(),
48-
image_mode: SpriteImageMode::Scale(ScalingMode::FillEnd),
48+
image_mode: SpriteImageMode::Scale(SpriteScalingMode::FillEnd),
4949
},
5050
Rect {
5151
size: Vec2::new(300., 100.),
5252
text: "Fill Start Horizontal".to_string(),
5353
transform: Transform::from_translation(Vec3::new(10., 290., 0.)),
5454
texture: square.clone(),
55-
image_mode: SpriteImageMode::Scale(ScalingMode::FillStart),
55+
image_mode: SpriteImageMode::Scale(SpriteScalingMode::FillStart),
5656
},
5757
Rect {
5858
size: Vec2::new(300., 100.),
5959
text: "Fill End Horizontal".to_string(),
6060
transform: Transform::from_translation(Vec3::new(10., 155., 0.)),
6161
texture: square.clone(),
62-
image_mode: SpriteImageMode::Scale(ScalingMode::FillEnd),
62+
image_mode: SpriteImageMode::Scale(SpriteScalingMode::FillEnd),
6363
},
6464
Rect {
6565
size: Vec2::new(200., 200.),
6666
text: "Fill Center".to_string(),
6767
transform: Transform::from_translation(Vec3::new(280., 230., 0.)),
6868
texture: banner.clone(),
69-
image_mode: SpriteImageMode::Scale(ScalingMode::FillCenter),
69+
image_mode: SpriteImageMode::Scale(SpriteScalingMode::FillCenter),
7070
},
7171
Rect {
7272
size: Vec2::new(200., 100.),
7373
text: "Fill Center".to_string(),
7474
transform: Transform::from_translation(Vec3::new(500., 230., 0.)),
7575
texture: square.clone(),
76-
image_mode: SpriteImageMode::Scale(ScalingMode::FillCenter),
76+
image_mode: SpriteImageMode::Scale(SpriteScalingMode::FillCenter),
7777
},
7878
Rect {
7979
size: Vec2::new(100., 100.),
@@ -87,28 +87,28 @@ fn setup_sprites(mut commands: Commands, asset_server: Res<AssetServer>) {
8787
text: "Fit Center".to_string(),
8888
transform: Transform::from_translation(Vec3::new(-400., -40., 0.)),
8989
texture: banner.clone(),
90-
image_mode: SpriteImageMode::Scale(ScalingMode::FitCenter),
90+
image_mode: SpriteImageMode::Scale(SpriteScalingMode::FitCenter),
9191
},
9292
Rect {
9393
size: Vec2::new(200., 200.),
9494
text: "Fit Start".to_string(),
9595
transform: Transform::from_translation(Vec3::new(-180., -40., 0.)),
9696
texture: banner.clone(),
97-
image_mode: SpriteImageMode::Scale(ScalingMode::FitStart),
97+
image_mode: SpriteImageMode::Scale(SpriteScalingMode::FitStart),
9898
},
9999
Rect {
100100
size: Vec2::new(200., 200.),
101101
text: "Fit End".to_string(),
102102
transform: Transform::from_translation(Vec3::new(40., -40., 0.)),
103103
texture: banner.clone(),
104-
image_mode: SpriteImageMode::Scale(ScalingMode::FitEnd),
104+
image_mode: SpriteImageMode::Scale(SpriteScalingMode::FitEnd),
105105
},
106106
Rect {
107107
size: Vec2::new(100., 200.),
108108
text: "Fit Center".to_string(),
109109
transform: Transform::from_translation(Vec3::new(210., -40., 0.)),
110110
texture: banner.clone(),
111-
image_mode: SpriteImageMode::Scale(ScalingMode::FitCenter),
111+
image_mode: SpriteImageMode::Scale(SpriteScalingMode::FitCenter),
112112
},
113113
];
114114

@@ -166,7 +166,7 @@ fn setup_texture_atlas(
166166
text: "Fill Center".to_string(),
167167
transform: Transform::from_translation(Vec3::new(-570., -300., 0.)),
168168
texture: gabe.clone(),
169-
image_mode: SpriteImageMode::Scale(ScalingMode::FillCenter),
169+
image_mode: SpriteImageMode::Scale(SpriteScalingMode::FillCenter),
170170
atlas: gabe_atlas.clone(),
171171
indices: animation_indices_gabe.clone(),
172172
timer: AnimationTimer(Timer::from_seconds(0.1, TimerMode::Repeating)),
@@ -176,7 +176,7 @@ fn setup_texture_atlas(
176176
text: "Fill Start".to_string(),
177177
transform: Transform::from_translation(Vec3::new(-430., -200., 0.)),
178178
texture: gabe.clone(),
179-
image_mode: SpriteImageMode::Scale(ScalingMode::FillStart),
179+
image_mode: SpriteImageMode::Scale(SpriteScalingMode::FillStart),
180180
atlas: gabe_atlas.clone(),
181181
indices: animation_indices_gabe.clone(),
182182
timer: AnimationTimer(Timer::from_seconds(0.1, TimerMode::Repeating)),
@@ -186,7 +186,7 @@ fn setup_texture_atlas(
186186
text: "Fill End".to_string(),
187187
transform: Transform::from_translation(Vec3::new(-430., -300., 0.)),
188188
texture: gabe.clone(),
189-
image_mode: SpriteImageMode::Scale(ScalingMode::FillEnd),
189+
image_mode: SpriteImageMode::Scale(SpriteScalingMode::FillEnd),
190190
atlas: gabe_atlas.clone(),
191191
indices: animation_indices_gabe.clone(),
192192
timer: AnimationTimer(Timer::from_seconds(0.1, TimerMode::Repeating)),
@@ -196,7 +196,7 @@ fn setup_texture_atlas(
196196
text: "Fill Center".to_string(),
197197
transform: Transform::from_translation(Vec3::new(-300., -250., 0.)),
198198
texture: gabe.clone(),
199-
image_mode: SpriteImageMode::Scale(ScalingMode::FillCenter),
199+
image_mode: SpriteImageMode::Scale(SpriteScalingMode::FillCenter),
200200
atlas: gabe_atlas.clone(),
201201
indices: animation_indices_gabe.clone(),
202202
timer: AnimationTimer(Timer::from_seconds(0.1, TimerMode::Repeating)),
@@ -206,7 +206,7 @@ fn setup_texture_atlas(
206206
text: "Fill Start".to_string(),
207207
transform: Transform::from_translation(Vec3::new(-190., -250., 0.)),
208208
texture: gabe.clone(),
209-
image_mode: SpriteImageMode::Scale(ScalingMode::FillStart),
209+
image_mode: SpriteImageMode::Scale(SpriteScalingMode::FillStart),
210210
atlas: gabe_atlas.clone(),
211211
indices: animation_indices_gabe.clone(),
212212
timer: AnimationTimer(Timer::from_seconds(0.1, TimerMode::Repeating)),
@@ -216,7 +216,7 @@ fn setup_texture_atlas(
216216
text: "Fill End".to_string(),
217217
transform: Transform::from_translation(Vec3::new(-90., -250., 0.)),
218218
texture: gabe.clone(),
219-
image_mode: SpriteImageMode::Scale(ScalingMode::FillEnd),
219+
image_mode: SpriteImageMode::Scale(SpriteScalingMode::FillEnd),
220220
atlas: gabe_atlas.clone(),
221221
indices: animation_indices_gabe.clone(),
222222
timer: AnimationTimer(Timer::from_seconds(0.1, TimerMode::Repeating)),
@@ -226,7 +226,7 @@ fn setup_texture_atlas(
226226
text: "Fit Center".to_string(),
227227
transform: Transform::from_translation(Vec3::new(20., -200., 0.)),
228228
texture: gabe.clone(),
229-
image_mode: SpriteImageMode::Scale(ScalingMode::FitCenter),
229+
image_mode: SpriteImageMode::Scale(SpriteScalingMode::FitCenter),
230230
atlas: gabe_atlas.clone(),
231231
indices: animation_indices_gabe.clone(),
232232
timer: AnimationTimer(Timer::from_seconds(0.1, TimerMode::Repeating)),
@@ -236,7 +236,7 @@ fn setup_texture_atlas(
236236
text: "Fit Start".to_string(),
237237
transform: Transform::from_translation(Vec3::new(20., -300., 0.)),
238238
texture: gabe.clone(),
239-
image_mode: SpriteImageMode::Scale(ScalingMode::FitStart),
239+
image_mode: SpriteImageMode::Scale(SpriteScalingMode::FitStart),
240240
atlas: gabe_atlas.clone(),
241241
indices: animation_indices_gabe.clone(),
242242
timer: AnimationTimer(Timer::from_seconds(0.1, TimerMode::Repeating)),
@@ -246,7 +246,7 @@ fn setup_texture_atlas(
246246
text: "Fit End".to_string(),
247247
transform: Transform::from_translation(Vec3::new(160., -200., 0.)),
248248
texture: gabe.clone(),
249-
image_mode: SpriteImageMode::Scale(ScalingMode::FitEnd),
249+
image_mode: SpriteImageMode::Scale(SpriteScalingMode::FitEnd),
250250
atlas: gabe_atlas.clone(),
251251
indices: animation_indices_gabe.clone(),
252252
timer: AnimationTimer(Timer::from_seconds(0.1, TimerMode::Repeating)),
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
---
2+
title: Rename `ScalingMode` to `SpriteScalingMode`
3+
pull_requests: [21100]
4+
---
5+
6+
In the previous release, both `bevy_sprite::sprite` and `bevy_camera::projection` defined an enum named `ScalingMode`, in violation of our one-namespace rule.
7+
8+
To resolve this, the `ScalingMode` enum from `bevy::sprite` has been renamed to `SpriteScalingMode`.

0 commit comments

Comments
 (0)