use super::SharedString;
use crate::geometry::{Points, Size};
#[derive(Debug, Clone, Copy, PartialEq)]
pub struct ImageAsset {
pub url: &'static str,
pub size: Size<Points>,
pub scales: &'static [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)>,
pub(crate) scales: crate::ImageScales,
}
impl<T: Into<SharedString>> From<T> for ImageSrc {
fn from(uri: T) -> Self {
Self {
uri: uri.into(),
size: None,
scales: crate::ImageScales::NONE,
}
}
}
impl From<ImageAsset> for ImageSrc {
fn from(asset: ImageAsset) -> Self {
Self {
uri: asset.url.into(),
size: Some((asset.size.width.0, asset.size.height.0)),
scales: asset.scales.iter().copied().collect(),
}
}
}
impl From<&ImageAsset> for ImageSrc {
fn from(asset: &ImageAsset) -> Self {
(*asset).into()
}
}
crate::static_reactive!(
ImageSrc: ImageSrc,
ImageAsset,
&ImageAsset,
super::SharedString,
String,
&'static str
);