summaryrefslogtreecommitdiffstats
path: root/web/src/widget/button.rs
diff options
context:
space:
mode:
authorLibravatar Héctor Ramón <hector0193@gmail.com>2019-11-24 19:15:28 +0100
committerLibravatar GitHub <noreply@github.com>2019-11-24 19:15:28 +0100
commitbbcd16c3358e641b8ab1877b802d1f7c5709943d (patch)
tree72c805ce46792f3c038d2d7ea127263ae965a779 /web/src/widget/button.rs
parent700390bdb297a5fc2eb356b10f9ed2656cc75daa (diff)
parent2b2a0f12c75032453fbefd2491d3ef51ff0ba88e (diff)
downloadiced-bbcd16c3358e641b8ab1877b802d1f7c5709943d.tar.gz
iced-bbcd16c3358e641b8ab1877b802d1f7c5709943d.tar.bz2
iced-bbcd16c3358e641b8ab1877b802d1f7c5709943d.zip
Merge pull request #66 from hecrj/feature/new-web-tour
Make `tour` work with `iced_web` again
Diffstat (limited to 'web/src/widget/button.rs')
-rw-r--r--web/src/widget/button.rs42
1 files changed, 34 insertions, 8 deletions
diff --git a/web/src/widget/button.rs b/web/src/widget/button.rs
index 1c13f34d..889c0ab1 100644
--- a/web/src/widget/button.rs
+++ b/web/src/widget/button.rs
@@ -4,7 +4,7 @@
//!
//! [`Button`]: struct.Button.html
//! [`State`]: struct.State.html
-use crate::{Background, Bus, Element, Length, Widget};
+use crate::{style, Background, Bus, Element, Length, Style, Widget};
use dodrio::bumpalo;
@@ -120,23 +120,49 @@ impl State {
impl<'a, Message> Widget<Message> for Button<'a, Message>
where
- Message: 'static + Copy,
+ Message: 'static + Clone,
{
fn node<'b>(
&self,
bump: &'b bumpalo::Bump,
bus: &Bus<Message>,
+ style_sheet: &mut style::Sheet<'b>,
) -> dodrio::Node<'b> {
use dodrio::builder::*;
- let mut node =
- button(bump).children(vec![self.content.node(bump, bus)]);
-
- if let Some(on_press) = self.on_press {
+ let padding_class =
+ style_sheet.insert(bump, Style::Padding(self.padding));
+
+ let background = match self.background {
+ None => String::from("none"),
+ Some(background) => match background {
+ Background::Color(color) => style::color(color),
+ },
+ };
+
+ let mut node = button(bump)
+ .attr(
+ "class",
+ bumpalo::format!(in bump, "{}", padding_class).into_bump_str(),
+ )
+ .attr(
+ "style",
+ bumpalo::format!(
+ in bump,
+ "background: {}; border-radius: {}px; min-width: {}px",
+ background,
+ self.border_radius,
+ self.min_width
+ )
+ .into_bump_str(),
+ )
+ .children(vec![self.content.node(bump, bus, style_sheet)]);
+
+ if let Some(on_press) = self.on_press.clone() {
let event_bus = bus.clone();
node = node.on("click", move |root, vdom, _event| {
- event_bus.publish(on_press, root);
+ event_bus.publish(on_press.clone(), root);
vdom.schedule_render();
});
@@ -150,7 +176,7 @@ where
impl<'a, Message> From<Button<'a, Message>> for Element<'a, Message>
where
- Message: 'static + Copy,
+ Message: 'static + Clone,
{
fn from(button: Button<'a, Message>) -> Element<'a, Message> {
Element::new(button)