use crate::{Bounds, Element, IntoElement, Pixels, StyleRefinement, Styled, WindowContext}; pub fn canvas(callback: impl 'static + FnOnce(Bounds, &mut WindowContext)) -> Canvas { Canvas { paint_callback: Box::new(callback), style: Default::default(), } } pub struct Canvas { paint_callback: Box, &mut WindowContext)>, style: StyleRefinement, } impl IntoElement for Canvas { type Element = Self; fn element_id(&self) -> Option { None } fn into_element(self) -> Self::Element { self } } impl Element for Canvas { type State = (); fn layout( &mut self, _: Option, cx: &mut WindowContext, ) -> (crate::LayoutId, Self::State) { let layout_id = cx.request_layout(&self.style.clone().into(), []); (layout_id, ()) } fn paint(self, bounds: Bounds, _: &mut (), cx: &mut WindowContext) { (self.paint_callback)(bounds, cx) } } impl Styled for Canvas { fn style(&mut self) -> &mut crate::StyleRefinement { &mut self.style } }