use taffy::{AvailableSpace, Layout, Size}; use crate::{Node, View}; pub trait Widget { /// Used for the measure function in /// [`taffy::TaffyTree::compute_layout_with_measure`]. #[allow(unused_variables)] fn size( &mut self, ctx: &mut C, known: Size>, available: Size, ) -> Size { Size::ZERO } /// Called before all children are drawn. /// /// Prefer this over [`Self::draw_above`] when implementing a leaf widget. #[allow(unused_variables)] fn draw_below( &mut self, ctx: &mut C, view: &mut View<'_>, layout: &Layout, ) -> anyhow::Result<()> { Ok(()) } /// Called after all children are drawn. #[allow(unused_variables)] fn draw_above( &mut self, ctx: &mut C, view: &mut View<'_>, layout: &Layout, ) -> anyhow::Result<()> { Ok(()) } } pub type BoxedWidget = Box>; pub trait WidgetExt { fn node(self) -> Node; } impl + 'static> WidgetExt for W { fn node(self) -> Node { Node::empty().with_widget(self) } }