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

50 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::Radio;
2019-09-14 20:54:50 +02:00
2019-09-15 18:53:13 +02:00
impl<Message> Widget<Message> for Radio<Message>
where
Message: 'static + Copy,
{
fn node<'b>(
&self,
bump: &'b bumpalo::Bump,
bus: &Bus<Message>,
) -> 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;
// TODO: Complete styling
2019-09-15 18:53:13 +02:00
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()
}
}
2019-09-14 20:54:50 +02:00
impl<'a, Message> From<Radio<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(radio: Radio<Message>) -> Element<'a, Message> {
Element::new(radio)
}
}