Add Widget and Node
This commit is contained in:
parent
eb04b3fb50
commit
bea5e03834
5 changed files with 102 additions and 1 deletions
23
showbits-common/src/widget.rs
Normal file
23
showbits-common/src/widget.rs
Normal 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)
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue