use bevy::{sprite::TextureAtlas, ui::UiTextureAtlasImage};
use super::builder::{MaybeHandleOrPath, StyleBuilder};
#[allow(missing_docs)]
pub trait StyleBuilderTextureAtlas {
fn texture_atlas<'p>(&mut self, path: impl Into<MaybeHandleOrPath<'p, TextureAtlas>>) -> &mut Self;
fn texture_atlas_tile(&mut self, index: usize) -> &mut Self;
fn texture_atlas_tile_flipped(
&mut self,
tile_index: usize,
flip_x: bool,
flip_y: bool,
) -> &mut Self;
}
impl<'a, 'w> StyleBuilderTextureAtlas for StyleBuilder<'a, 'w> {
fn texture_atlas<'p>(&mut self, path: impl Into<MaybeHandleOrPath<'p, TextureAtlas>>) -> &mut Self {
todo!("Implement texture atlas loading");
}
fn texture_atlas_tile(&mut self, index: usize) -> &mut Self {
match self.target.get_mut::<UiTextureAtlasImage>() {
Some(mut uii) => {
uii.index = index;
}
None => {
self.target.insert(UiTextureAtlasImage {
index,
flip_x: false,
flip_y: false,
});
}
};
self
}
fn texture_atlas_tile_flipped(
&mut self,
index: usize,
flip_x: bool,
flip_y: bool,
) -> &mut Self {
match self.target.get_mut::<UiTextureAtlasImage>() {
Some(mut uii) => {
uii.index = index;
uii.flip_x = flip_x;
uii.flip_y = flip_y;
}
None => {
self.target.insert(UiTextureAtlasImage {
index,
flip_x,
flip_y,
});
}
};
self
}
}