diff --git a/web/src/bus.rs b/web/src/bus.rs index 09908679..b3984aff 100644 --- a/web/src/bus.rs +++ b/web/src/bus.rs @@ -8,11 +8,18 @@ use std::rc::Rc; /// /// [`Application`]: trait.Application.html #[allow(missing_debug_implementations)] -#[derive(Clone)] pub struct Bus { publish: Rc>, } +impl Clone for Bus { + fn clone(&self) -> Self { + Self { + publish: Rc::clone(&self.publish), + } + } +} + impl Bus where Message: 'static, diff --git a/web/src/widget/checkbox.rs b/web/src/widget/checkbox.rs index b81a0d52..34d13a1b 100644 --- a/web/src/widget/checkbox.rs +++ b/web/src/widget/checkbox.rs @@ -1,6 +1,7 @@ use crate::{style, Bus, Color, Element, Widget}; use dodrio::bumpalo; +use std::rc::Rc; /// A box that can be checked. /// @@ -22,7 +23,7 @@ use dodrio::bumpalo; #[allow(missing_debug_implementations)] pub struct Checkbox { is_checked: bool, - on_toggle: Box Message>, + on_toggle: Rc Message>, label: String, label_color: Option, } @@ -44,7 +45,7 @@ impl Checkbox { { Checkbox { is_checked, - on_toggle: Box::new(f), + on_toggle: Rc::new(f), label: String::from(label), label_color: None, } @@ -61,7 +62,7 @@ impl Checkbox { impl Widget for Checkbox where - Message: 'static + Clone, + Message: 'static, { fn node<'b>( &self, @@ -74,7 +75,8 @@ where let checkbox_label = bumpalo::format!(in bump, "{}", self.label); let event_bus = bus.clone(); - let msg = (self.on_toggle)(!self.is_checked); + let on_toggle = self.on_toggle.clone(); + let is_checked = self.is_checked; // TODO: Complete styling label(bump) @@ -83,7 +85,8 @@ where .attr("type", "checkbox") .bool_attr("checked", self.is_checked) .on("click", move |root, vdom, _event| { - event_bus.publish(msg.clone(), root); + let msg = on_toggle(!is_checked); + event_bus.publish(msg, root); vdom.schedule_render(); }) @@ -96,7 +99,7 @@ where impl<'a, Message> From> for Element<'a, Message> where - Message: 'static + Clone, + Message: 'static, { fn from(checkbox: Checkbox) -> Element<'a, Message> { Element::new(checkbox) diff --git a/web/src/widget/scrollable.rs b/web/src/widget/scrollable.rs index 710bb70a..f146e007 100644 --- a/web/src/widget/scrollable.rs +++ b/web/src/widget/scrollable.rs @@ -134,7 +134,7 @@ where impl<'a, Message> From> for Element<'a, Message> where - Message: 'static + Clone, + Message: 'static, { fn from(scrollable: Scrollable<'a, Message>) -> Element<'a, Message> { Element::new(scrollable) diff --git a/web/src/widget/slider.rs b/web/src/widget/slider.rs index 5b203e07..fc955781 100644 --- a/web/src/widget/slider.rs +++ b/web/src/widget/slider.rs @@ -82,7 +82,7 @@ impl<'a, Message> Slider<'a, Message> { impl<'a, Message> Widget for Slider<'a, Message> where - Message: 'static + Clone, + Message: 'static, { fn node<'b>( &self, @@ -130,7 +130,7 @@ where impl<'a, Message> From> for Element<'a, Message> where - Message: 'static + Clone, + Message: 'static, { fn from(slider: Slider<'a, Message>) -> Element<'a, Message> { Element::new(slider) diff --git a/web/src/widget/text_input.rs b/web/src/widget/text_input.rs index eedc25bc..a478874a 100644 --- a/web/src/widget/text_input.rs +++ b/web/src/widget/text_input.rs @@ -82,7 +82,7 @@ impl<'a, Message> TextInput<'a, Message> { self.is_secure = true; self } - + /// Sets the width of the [`TextInput`]. /// /// [`TextInput`]: struct.TextInput.html