From 8c34cbbb27847a78a6b41b0c983f1b9bb7e36190 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mart=C3=ADn=20Maita?= <47983254+mnmaita@users.noreply.github.com> Date: Sun, 4 May 2025 10:11:59 +0200 Subject: [PATCH] Add TextureAtlas convenience methods (#19023) # Objective - Add a few useful methods to `TextureAtlas`. ## Solution - Added `TextureAtlas::with_index()`. - Added `TextureAtlas::with_layout()`. ## Testing - CI checks. --- crates/bevy_image/src/texture_atlas.rs | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/crates/bevy_image/src/texture_atlas.rs b/crates/bevy_image/src/texture_atlas.rs index b5b68b0c41..4caeed8c07 100644 --- a/crates/bevy_image/src/texture_atlas.rs +++ b/crates/bevy_image/src/texture_atlas.rs @@ -222,6 +222,18 @@ impl TextureAtlas { let atlas = texture_atlases.get(&self.layout)?; atlas.textures.get(self.index).copied() } + + /// Returns this [`TextureAtlas`] with the specified index. + pub fn with_index(mut self, index: usize) -> Self { + self.index = index; + self + } + + /// Returns this [`TextureAtlas`] with the specified [`TextureAtlasLayout`] handle. + pub fn with_layout(mut self, layout: Handle) -> Self { + self.layout = layout; + self + } } impl From> for TextureAtlas {