Add Widget and Node

This commit is contained in:
Joscha 2024-03-07 13:58:10 +01:00
parent eb04b3fb50
commit bea5e03834
5 changed files with 102 additions and 1 deletions

View file

@ -0,0 +1,23 @@
use taffy::{AvailableSpace, Size};
use crate::{Node, View};
pub trait Widget {
#[allow(unused_variables)]
fn size(&mut self, known: Size<Option<f32>>, available: Size<AvailableSpace>) -> Size<f32> {
Size::ZERO
}
fn draw_below(&mut self, view: &mut View<'_>) -> anyhow::Result<()>;
fn draw_above(&mut self, view: &mut View<'_>) -> anyhow::Result<()>;
}
pub trait WidgetExt {
fn node(self) -> Node;
}
impl<W: Widget + 'static> WidgetExt for W {
fn node(self) -> Node {
Node::empty().widget(self)
}
}