Draft widget nodes and wire interaction
This commit is contained in:
parent
27ac85a9d9
commit
8834772fa7
10 changed files with 223 additions and 22 deletions
|
|
@ -1,4 +1,7 @@
|
|||
use crate::{Color, Widget};
|
||||
use crate::{Bus, Color, Widget};
|
||||
|
||||
use dodrio::bumpalo;
|
||||
use std::rc::Rc;
|
||||
|
||||
pub struct Element<'a, Message> {
|
||||
pub(crate) widget: Box<dyn Widget<Message> + 'a>,
|
||||
|
|
@ -11,7 +14,7 @@ impl<'a, Message> Element<'a, Message> {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn explain(self, color: Color) -> Element<'a, Message> {
|
||||
pub fn explain(self, _color: Color) -> Element<'a, Message> {
|
||||
self
|
||||
}
|
||||
|
||||
|
|
@ -29,7 +32,7 @@ impl<'a, Message> Element<'a, Message> {
|
|||
|
||||
struct Map<'a, A, B> {
|
||||
widget: Box<dyn Widget<A> + 'a>,
|
||||
mapper: Box<dyn Fn(A) -> B>,
|
||||
mapper: Rc<Box<dyn Fn(A) -> B>>,
|
||||
}
|
||||
|
||||
impl<'a, A, B> Map<'a, A, B> {
|
||||
|
|
@ -39,9 +42,21 @@ impl<'a, A, B> Map<'a, A, B> {
|
|||
{
|
||||
Map {
|
||||
widget,
|
||||
mapper: Box::new(mapper),
|
||||
mapper: Rc::new(Box::new(mapper)),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a, A, B> Widget<B> for Map<'a, A, B> {}
|
||||
impl<'a, A, B> Widget<B> for Map<'a, A, B>
|
||||
where
|
||||
A: 'static,
|
||||
B: 'static,
|
||||
{
|
||||
fn node<'b>(
|
||||
&self,
|
||||
bump: &'b bumpalo::Bump,
|
||||
bus: &Bus<B>,
|
||||
) -> dodrio::Node<'b> {
|
||||
self.widget.node(bump, &bus.map(self.mapper.clone()))
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue