fixes and refactors

- use macros for the evals
- move some space stuff into submodules
- partial update to doctests
This commit is contained in:
i do not exist 2026-04-24 01:34:43 +03:00
parent b44dc02f33
commit e074712459
9 changed files with 464 additions and 380 deletions

View file

@ -1,4 +1,4 @@
use crate::{*, lang::*, color::*, space::*};
use crate::{*, space::*};
/// Drawable that supports dynamic dispatch.
///
@ -13,12 +13,12 @@ use crate::{*, lang::*, color::*, space::*};
/// a [Draw]able.
///
/// ```
/// use tengri::draw::*;
/// use tengri::{*, draw::*, space::*};
/// struct TestScreen(bool);
/// impl Screen for TestScreen { type Unit = u16; }
/// struct TestWidget(bool);
/// impl Draw<TestScreen> for TestWidget {
/// fn draw (&self, screen: &mut T) -> Usually<XYWH<u16>> {
/// fn draw (&self, screen: &mut TestScreen) -> Usually<XYWH<u16>> {
/// screen.0 |= self.0;
/// }
/// }
@ -31,12 +31,12 @@ pub trait Draw<T: Screen> {
fn draw (self, to: &mut T) -> Usually<XYWH<T::Unit>>;
}
impl<T: Screen, D: Draw<T>> Draw<T> for &D {
fn draw (self, to: &mut T) -> Usually<XYWH<T::Unit>> {
fn draw (self, __: &mut T) -> Usually<XYWH<T::Unit>> {
todo!()
}
}
impl<T: Screen, D: Draw<T>> Draw<T> for Option<D> {
fn draw (self, to: &mut T) -> Usually<XYWH<T::Unit>> {
fn draw (self, __: &mut T) -> Usually<XYWH<T::Unit>> {
todo!()
}
}
@ -66,8 +66,9 @@ impl<T: Screen, F: FnOnce(&mut T)->Usually<XYWH<T::Unit>>> Draw<T> for Thunk<T,
/// Only render when condition is true.
///
/// ```
/// # fn test () -> impl tengri::Draw<tengri::Tui> {
/// tengri::when(true, "Yes")
/// # use tengri::draw::*;
/// # fn test () -> impl tengri::draw::Draw<tengri::term::Tui> {
/// when(true, "Yes")
/// # }
/// ```
pub const fn when <T: Screen> (condition: bool, draw: impl Draw<T>) -> impl Draw<T> {
@ -77,8 +78,9 @@ pub const fn when <T: Screen> (condition: bool, draw: impl Draw<T>) -> impl Draw
/// Render one thing if a condition is true and another false.
///
/// ```
/// # fn test () -> impl tengri::Draw<tengri::Tui> {
/// tengri::either(true, "Yes", "No")
/// # use tengri::draw::*;
/// # fn test () -> impl tengri::draw::Draw<tengri::term::Tui> {
/// either(true, "Yes", "No")
/// # }
/// ```
pub const fn either <T: Screen> (condition: bool, a: impl Draw<T>, b: impl Draw<T>) -> impl Draw<T> {
@ -88,13 +90,13 @@ pub const fn either <T: Screen> (condition: bool, a: impl Draw<T>, b: impl Draw<
/// Output target.
///
/// ```
/// use tengri::*;
/// use tengri::draw::*;
///
/// struct TestOut(impl TwoD<u16>);
/// struct TestOut<T: Screen<Unit = u16>>(T);
///
/// impl Screen for TestOut {
/// impl<T: Screen<Unit = u16>> Screen<T> for TestOut {
/// type Unit = u16;
/// fn place_at <T: Draw<Self> + ?Sized> (&mut self, area: impl TwoD<u16>, _: &T) {
/// fn place_at <D: Draw<Self> + ?Sized> (&mut self, area: T, _: D) {
/// println!("placed: {area:?}");
/// ()
/// }
@ -114,7 +116,7 @@ pub trait Screen: Space<Self::Unit> + Send + Sync + Sized {
}
/// Render drawable in subarea specified by `area`
fn place_at <'t, T: Draw<Self> + ?Sized> (
&mut self, area: XYWH<Self::Unit>, content: &'t T
&mut self, _area: XYWH<Self::Unit>, _content: &'t T
) {
unimplemented!()
}