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.
This commit is contained in:
Martín Maita 2025-05-04 10:11:59 +02:00 committed by GitHub
parent 2affecdb07
commit 8c34cbbb27
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -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<TextureAtlasLayout>) -> Self {
self.layout = layout;
self
}
}
impl From<Handle<TextureAtlasLayout>> for TextureAtlas {