use crate::element::{self, Element}; use crate::Widget; pub struct Button { content: Element, on_press: Option, } impl Button { pub fn new( content: impl element::Descriptor + 'static, ) -> Self { Button { content: Element::new(content), on_press: None, } } pub fn on_press(mut self, on_press: Message) -> Self { self.on_press = Some(on_press); self } } impl element::Descriptor for Button where Message: 'static + Clone, Renderer: 'static, { fn tag(&self) -> std::any::TypeId { std::any::TypeId::of::() } fn build(&self) -> Box> { Box::new(State { is_pressed: false }) } fn children(&self) -> &[Element] { std::slice::from_ref(&self.content) } fn clone(&self) -> Box> { Box::new(Clone::clone(self)) } } impl Clone for Button where Message: Clone, { fn clone(&self) -> Self { Self { content: self.content.clone(), on_press: self.on_press.clone(), } } } pub struct State { is_pressed: bool, } impl Widget for State {}