use super::SharedString;
#[derive(Debug, Clone, Copy, PartialEq)]
pub struct ImageAsset {
pub uri: &'static str,
pub width: f32,
pub height: f32,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct FontAsset {
pub uri: &'static str,
pub family: &'static str,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct FileAsset {
pub uri: &'static str,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum AssetKind {
Image,
Font,
File,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct AssetFile {
pub uri: &'static str,
pub source: &'static str,
pub kind: AssetKind,
}
impl AssetFile {
pub fn path(&self) -> &'static str {
self.uri.strip_prefix("asset:/").unwrap_or(self.uri)
}
}
#[derive(Debug, Clone, PartialEq)]
pub struct ImageSrc {
pub(crate) uri: SharedString,
pub(crate) size: Option<(f32, f32)>,
}
impl<T: Into<SharedString>> From<T> for ImageSrc {
fn from(uri: T) -> Self {
Self {
uri: uri.into(),
size: None,
}
}
}
impl From<ImageAsset> for ImageSrc {
fn from(asset: ImageAsset) -> Self {
Self {
uri: asset.uri.into(),
size: Some((asset.width, asset.height)),
}
}
}
impl From<&ImageAsset> for ImageSrc {
fn from(asset: &ImageAsset) -> Self {
(*asset).into()
}
}