From 27ac85a9d98474904c422a891e54888376dec00a Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Sat, 14 Sep 2019 20:54:50 +0200 Subject: Draft web runtime and widgets --- web/src/widget/image.rs | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 web/src/widget/image.rs (limited to 'web/src/widget/image.rs') diff --git a/web/src/widget/image.rs b/web/src/widget/image.rs new file mode 100644 index 00000000..ac144fd8 --- /dev/null +++ b/web/src/widget/image.rs @@ -0,0 +1,11 @@ +use crate::{Element, Widget}; + +pub type Image<'a> = iced::Image<&'a str>; + +impl<'a, Message> Widget for Image<'a> {} + +impl<'a, Message> From> for Element<'a, Message> { + fn from(image: Image<'a>) -> Element<'a, Message> { + Element::new(image) + } +} -- cgit From 655978f480c32bc696f0d5fe2fff834bfbf238ea Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Sun, 15 Sep 2019 18:53:13 +0200 Subject: Draft nodes for missing widgets --- web/src/widget/image.rs | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) (limited to 'web/src/widget/image.rs') diff --git a/web/src/widget/image.rs b/web/src/widget/image.rs index ac144fd8..a882faff 100644 --- a/web/src/widget/image.rs +++ b/web/src/widget/image.rs @@ -1,8 +1,29 @@ -use crate::{Element, Widget}; +use crate::{Bus, Element, Widget}; + +use dodrio::bumpalo; pub type Image<'a> = iced::Image<&'a str>; -impl<'a, Message> Widget for Image<'a> {} +impl<'a, Message> Widget for Image<'a> { + fn node<'b>( + &self, + bump: &'b bumpalo::Bump, + _bus: &Bus, + ) -> dodrio::Node<'b> { + use dodrio::builder::*; + + let src = bumpalo::format!(in bump, "{}", self.image); + + let mut image = img(bump).attr("src", src.into_bump_str()); + + if let Some(width) = self.width { + let width = bumpalo::format!(in bump, "{}", width); + image = image.attr("width", width.into_bump_str()); + } + + image.finish() + } +} impl<'a, Message> From> for Element<'a, Message> { fn from(image: Image<'a>) -> Element<'a, Message> { -- cgit From b9e0f7494881ad7cdfbcbc16878ecc6ef717753f Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Fri, 20 Sep 2019 19:15:31 +0200 Subject: Create `iced_core` and `iced_native` --- web/src/widget/image.rs | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) (limited to 'web/src/widget/image.rs') diff --git a/web/src/widget/image.rs b/web/src/widget/image.rs index a882faff..48ff539f 100644 --- a/web/src/widget/image.rs +++ b/web/src/widget/image.rs @@ -1,8 +1,8 @@ -use crate::{Bus, Element, Widget}; +use crate::{Bus, Element, Length, Widget}; use dodrio::bumpalo; -pub type Image<'a> = iced::Image<&'a str>; +pub type Image<'a> = iced_core::Image<&'a str>; impl<'a, Message> Widget for Image<'a> { fn node<'b>( @@ -12,13 +12,21 @@ impl<'a, Message> Widget for Image<'a> { ) -> dodrio::Node<'b> { use dodrio::builder::*; - let src = bumpalo::format!(in bump, "{}", self.image); + let src = bumpalo::format!(in bump, "{}", self.handle); let mut image = img(bump).attr("src", src.into_bump_str()); - if let Some(width) = self.width { - let width = bumpalo::format!(in bump, "{}", width); - image = image.attr("width", width.into_bump_str()); + 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(), + ); + } } image.finish() -- cgit From 86dede4c4cc2bca9be7d2e6bd831daa98bd7043d Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Sat, 21 Sep 2019 13:38:14 +0200 Subject: Make example work on web and update READMEs --- web/src/widget/image.rs | 2 ++ 1 file changed, 2 insertions(+) (limited to 'web/src/widget/image.rs') diff --git a/web/src/widget/image.rs b/web/src/widget/image.rs index 48ff539f..fd4ff0df 100644 --- a/web/src/widget/image.rs +++ b/web/src/widget/image.rs @@ -29,6 +29,8 @@ impl<'a, Message> Widget for Image<'a> { } } + // TODO: Complete styling + image.finish() } } -- cgit