use vizia_style::Url;
use crate::prelude::*;
pub struct Image {}
impl Image {
pub fn new<T: ToString>(cx: &mut Context, img: impl Res<T>) -> Handle<'_, Self> {
let img = img.get_value(cx);
let img = BackgroundImage::Url(Url { url: img.to_string().into() });
Self {}.build(cx, |_| {}).background_image(img)
}
}
impl View for Image {
fn element(&self) -> Option<&'static str> {
Some("image")
}
}
pub struct Svg {}
impl Svg {
pub fn new<T>(cx: &mut Context, data: impl Res<T>) -> Handle<Self>
where
T: AsRef<[u8]> + 'static,
{
let svg_data = data.get_value(cx);
let h = format!("{:x}", fxhash::hash64(svg_data.as_ref()));
let mut handle = Self {}.build(cx, |_| {});
handle.context().load_svg(&h, svg_data.as_ref(), ImageRetentionPolicy::DropWhenNoObservers);
handle.background_image(format!("'{}'", h).as_str()).hoverable(false)
}
}
impl View for Svg {
fn element(&self) -> Option<&'static str> {
Some("svg")
}
}