iced-yoda/web/src/widget/image.rs

43 lines
1,010 B
Rust
Raw Normal View History

2019-09-20 19:15:31 +02:00
use crate::{Bus, Element, Length, Widget};
2019-09-15 18:53:13 +02:00
use dodrio::bumpalo;
2019-09-14 20:54:50 +02:00
pub use iced_core::Image;
2019-09-14 20:54:50 +02:00
impl<Message> Widget<Message> for Image {
2019-09-15 18:53:13 +02:00
fn node<'b>(
&self,
bump: &'b bumpalo::Bump,
_bus: &Bus<Message>,
) -> dodrio::Node<'b> {
use dodrio::builder::*;
let src = bumpalo::format!(in bump, "{}", self.path);
2019-09-15 18:53:13 +02:00
let mut image = img(bump).attr("src", src.into_bump_str());
2019-09-20 19:15:31 +02:00
match self.width {
Length::Shrink => {}
Length::Fill => {
image = image.attr("width", "100%");
}
Length::Units(px) => {
image = image.attr(
"width",
bumpalo::format!(in bump, "{}px", px).into_bump_str(),
);
}
2019-09-15 18:53:13 +02:00
}
// TODO: Complete styling
2019-09-15 18:53:13 +02:00
image.finish()
}
}
2019-09-14 20:54:50 +02:00
impl<'a, Message> From<Image> for Element<'a, Message> {
fn from(image: Image) -> Element<'a, Message> {
2019-09-14 20:54:50 +02:00
Element::new(image)
}
}