diff --git a/crates/bevy_sprite/src/texture_atlas_builder.rs b/crates/bevy_sprite/src/texture_atlas_builder.rs index c8294abf5cf6c..4c030d14e3cc9 100644 --- a/crates/bevy_sprite/src/texture_atlas_builder.rs +++ b/crates/bevy_sprite/src/texture_atlas_builder.rs @@ -59,25 +59,25 @@ pub type TextureAtlasBuilderResult = Result; impl<'a> TextureAtlasBuilder<'a> { /// Sets the initial size of the atlas in pixels. - pub fn initial_size(mut self, size: UVec2) -> Self { + pub fn initial_size(&mut self, size: UVec2) -> &mut Self { self.initial_size = size; self } /// Sets the max size of the atlas in pixels. - pub fn max_size(mut self, size: UVec2) -> Self { + pub fn max_size(&mut self, size: UVec2) -> &mut Self { self.max_size = size; self } /// Sets the texture format for textures in the atlas. - pub fn format(mut self, format: TextureFormat) -> Self { + pub fn format(&mut self, format: TextureFormat) -> &mut Self { self.format = format; self } /// Control whether the added texture should be converted to the atlas format, if different. - pub fn auto_format_conversion(mut self, auto_format_conversion: bool) -> Self { + pub fn auto_format_conversion(&mut self, auto_format_conversion: bool) -> &mut Self { self.auto_format_conversion = auto_format_conversion; self } @@ -86,7 +86,11 @@ impl<'a> TextureAtlasBuilder<'a> { /// /// Optionally an asset id can be passed that can later be used with the texture layout to retrieve the index of this texture. /// The insertion order will reflect the index of the added texture in the finished texture atlas. - pub fn add_texture(mut self, image_id: Option>, texture: &'a Image) -> Self { + pub fn add_texture( + &mut self, + image_id: Option>, + texture: &'a Image, + ) -> &mut Self { self.textures_to_place.push((image_id, texture)); self } @@ -94,7 +98,7 @@ impl<'a> TextureAtlasBuilder<'a> { /// Sets the amount of padding in pixels to add between the textures in the texture atlas. /// /// The `x` value provide will be added to the right edge, while the `y` value will be added to the bottom edge. - pub fn padding(mut self, padding: UVec2) -> Self { + pub fn padding(&mut self, padding: UVec2) -> &mut Self { self.padding = padding; self } @@ -149,6 +153,14 @@ impl<'a> TextureAtlasBuilder<'a> { } } + #[deprecated( + since = "0.14.0", + note = "TextureAtlasBuilder::finish() was not idiomatic. Use TextureAtlasBuilder::build() instead." + )] + pub fn finish(self) -> Result<(TextureAtlasLayout, Image), TextureAtlasBuilderError> { + self.build() + } + /// Consumes the builder, and returns the newly created texture atlas and /// the associated atlas layout. /// diff --git a/examples/2d/texture_atlas.rs b/examples/2d/texture_atlas.rs index 298e66d1bfbbb..45c95c22876fd 100644 --- a/examples/2d/texture_atlas.rs +++ b/examples/2d/texture_atlas.rs @@ -207,8 +207,8 @@ fn create_texture_atlas( textures: &mut ResMut>, ) -> (TextureAtlasLayout, Handle) { // Build a texture atlas using the individual sprites - let mut texture_atlas_builder = - TextureAtlasBuilder::default().padding(padding.unwrap_or_default()); + let mut texture_atlas_builder = TextureAtlasBuilder::default(); + texture_atlas_builder.padding(padding.unwrap_or_default()); for handle in folder.handles.iter() { let id = handle.id().typed_unchecked::(); let Some(texture) = textures.get(id) else { @@ -219,7 +219,7 @@ fn create_texture_atlas( continue; }; - texture_atlas_builder = texture_atlas_builder.add_texture(Some(id), texture); + texture_atlas_builder.add_texture(Some(id), texture); } let (texture_atlas_layout, texture) = texture_atlas_builder.build().unwrap();