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/radio.rs | 40 +++++++++++++++++++++++++++++++++++++--- 1 file changed, 37 insertions(+), 3 deletions(-) (limited to 'web/src/widget/radio.rs') diff --git a/web/src/widget/radio.rs b/web/src/widget/radio.rs index 0c28b46f..df08a977 100644 --- a/web/src/widget/radio.rs +++ b/web/src/widget/radio.rs @@ -1,12 +1,46 @@ -use crate::{Color, Element, Widget}; +use crate::{Bus, Color, Element, Widget}; + +use dodrio::bumpalo; pub type Radio = iced::Radio; -impl Widget for Radio {} +impl Widget for Radio +where + Message: 'static + Copy, +{ + fn node<'b>( + &self, + bump: &'b bumpalo::Bump, + bus: &Bus, + ) -> dodrio::Node<'b> { + use dodrio::builder::*; + + let radio_label = bumpalo::format!(in bump, "{}", self.label); + + let event_bus = bus.clone(); + let on_click = self.on_click; + + label(bump) + .attr("style", "display: block") + .children(vec![ + input(bump) + .attr("type", "radio") + .bool_attr("checked", self.is_selected) + .on("click", move |root, vdom, _event| { + event_bus.publish(on_click, root); + + vdom.schedule_render(); + }) + .finish(), + text(radio_label.into_bump_str()), + ]) + .finish() + } +} impl<'a, Message> From> for Element<'a, Message> where - Message: 'static, + Message: 'static + Copy, { fn from(radio: Radio) -> Element<'a, Message> { Element::new(radio) -- cgit