use crate::draw::dynamic_texture_atlas::{DynamicTextureAtlas, PageId};
use crate::draw::store::SharedTexture;
#[derive(Clone, Debug, Default)]
pub struct TileAtlasTextures {
glyph_page: Option<PageId>,
icon_page: Option<PageId>,
glyph: Option<SharedTexture>,
icon: Option<SharedTexture>,
}
impl TileAtlasTextures {
pub(crate) fn new(glyph: PageId, icon: PageId) -> Self {
TileAtlasTextures { glyph_page: Some(glyph), icon_page: Some(icon), glyph: None, icon: None }
}
pub(crate) fn resolve(&mut self, atlas: &DynamicTextureAtlas) {
if self.glyph.is_none() {
self.glyph = self.glyph_page.and_then(|page| atlas.page_texture(page)).cloned();
}
if self.icon.is_none() {
self.icon = self.icon_page.and_then(|page| atlas.page_texture(page)).cloned();
}
}
#[must_use]
pub fn glyph(&self) -> Option<&SharedTexture> {
self.glyph.as_ref()
}
#[must_use]
pub fn icon(&self) -> Option<&SharedTexture> {
self.icon.as_ref()
}
}