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

49 lines
1.2 KiB
Rust
Raw Normal View History

2019-09-19 18:47:01 +02:00
use crate::{Bus, Element, Widget};
2019-09-15 18:53:13 +02:00
use dodrio::bumpalo;
2019-09-14 20:54:50 +02:00
2019-09-20 19:15:31 +02:00
pub use iced_core::Checkbox;
2019-09-14 20:54:50 +02:00
2019-09-15 18:53:13 +02:00
impl<Message> Widget<Message> for Checkbox<Message>
where
Message: 'static + Copy,
{
fn node<'b>(
&self,
bump: &'b bumpalo::Bump,
bus: &Bus<Message>,
) -> dodrio::Node<'b> {
use dodrio::builder::*;
let checkbox_label = bumpalo::format!(in bump, "{}", self.label);
let event_bus = bus.clone();
let msg = (self.on_toggle)(!self.is_checked);
// TODO: Complete styling
2019-09-15 18:53:13 +02:00
label(bump)
.children(vec![
input(bump)
.attr("type", "checkbox")
.bool_attr("checked", self.is_checked)
.on("click", move |root, vdom, _event| {
event_bus.publish(msg, root);
vdom.schedule_render();
})
.finish(),
text(checkbox_label.into_bump_str()),
])
.finish()
}
}
2019-09-14 20:54:50 +02:00
impl<'a, Message> From<Checkbox<Message>> for Element<'a, Message>
where
2019-09-15 18:53:13 +02:00
Message: 'static + Copy,
2019-09-14 20:54:50 +02:00
{
fn from(checkbox: Checkbox<Message>) -> Element<'a, Message> {
Element::new(checkbox)
}
}