compiles, once again.

now 616 errors downstream...
This commit is contained in:
same mf who else 2026-03-21 20:12:51 +02:00
parent eb899906f9
commit cdc513060d
8 changed files with 196 additions and 201 deletions

View file

@ -1,7 +1,7 @@
use crate::{*, lang::*, color::*, space::*};
/// Drawable that supports dynamic dispatch.
///
///
/// ```
/// use tengri::draw::*;
/// struct TestScreen(bool);
@ -18,31 +18,16 @@ use crate::{*, lang::*, color::*, space::*};
/// TestWidget(false).draw(&mut screen);
/// ```
pub trait Draw<T: Screen> {
fn draw (&self, to: &mut T) -> Usually<XYWH<T::Unit>>;
fn draw (self, to: &mut T) -> Usually<XYWH<T::Unit>>;
}
impl<T: Screen> Draw<T> for () {
fn draw (&self, __: &mut T) -> Usually<XYWH<T::Unit>> {
fn draw (self, __: &mut T) -> Usually<XYWH<T::Unit>> {
Ok(Default::default())
}
}
impl<T: Screen, D: Draw<T>> Draw<T> for &D {
fn draw (&self, to: &mut T) -> Usually<XYWH<T::Unit>> {
(*self).draw(to)
}
}
impl<T: Screen, D: Draw<T>> Draw<T> for Arc<D> {
fn draw (&self, to: &mut T) -> Usually<XYWH<T::Unit>> {
(**self).draw(to)
}
}
impl<T: Screen, D: Draw<T>> Draw<T> for RwLock<D> {
fn draw (&self, to: &mut T) -> Usually<XYWH<T::Unit>> {
self.read().unwrap().draw(to)
}
}
impl<T: Screen, D: Draw<T>> Draw<T> for Option<D> {
fn draw (&self, to: &mut T) -> Usually<XYWH<T::Unit>> {
Ok(self.as_ref().map(|draw|draw.draw(to)).transpose()?.unwrap_or_default())
fn draw (self, to: &mut T) -> Usually<XYWH<T::Unit>> {
Ok(self.map(|draw|draw.draw(to)).transpose()?.unwrap_or_default())
}
}
@ -55,8 +40,8 @@ pub const fn thunk <T: Screen, F: FnOnce(&mut T)->Usually<XYWH<T::Unit>>> (draw:
Thunk(draw, std::marker::PhantomData)
}
impl<T: Screen, F: FnOnce(&mut T)->Usually<XYWH<T::Unit>>> Draw<T> for Thunk<T, F> {
fn draw (&self, to: &mut T) -> Usually<XYWH<T::Unit>> {
(&self.0)(to)
fn draw (self, to: &mut T) -> Usually<XYWH<T::Unit>> {
(self.0)(to)
}
}