From 4172fa257776f5c6c7b406429b2244d630702458 Mon Sep 17 00:00:00 2001 From: facile pop culture reference Date: Sun, 23 Aug 2026 11:29:40 +0300 Subject: [PATCH] remove View and lifetime from Draw/Drawn --- dizzle | 2 +- src/layout.rs | 60 +++++++++--------- src/layout/area.rs | 6 +- src/layout/axis.rs | 142 +++++++++++++++++++++--------------------- src/layout/azimuth.rs | 59 +++++++++--------- src/layout/cond.rs | 10 +-- src/layout/iter.rs | 52 ++++++++-------- src/lib.rs | 88 +++++++++++++------------- src/term.rs | 37 +++++------ src/term/border.rs | 8 +-- src/term/modify.rs | 22 +++---- src/term/phat.rs | 8 +-- src/term/scroll.rs | 4 +- 13 files changed, 250 insertions(+), 248 deletions(-) diff --git a/dizzle b/dizzle index c00aed7..a3d7719 160000 --- a/dizzle +++ b/dizzle @@ -1 +1 @@ -Subproject commit c00aed72086f23aa21e6f28f9e722af61faf240e +Subproject commit a3d7719bcc955552a5dbcf755115333872e87de4 diff --git a/src/layout.rs b/src/layout.rs index 77d8658..3da607d 100644 --- a/src/layout.rs +++ b/src/layout.rs @@ -1,44 +1,44 @@ use crate::*; -impl<'a, S: Screen, T: Draw<'a, S>> Layout<'a, S> for T {} +impl<'a, S: Screen, T: Draw> Layout<'a, S> for T {} -pub trait Layout<'a, S: Screen>: Draw<'a, S> + Sized { - fn origin (self, azimuth: impl Into>) -> impl Draw<'a, S> { +pub trait Layout<'a, S: Screen>: Draw + Sized { + fn origin (self, azimuth: impl Into>) -> impl Draw { Origin(azimuth.into(), self) } - fn origin_c (self) -> impl Draw<'a, S> { + fn origin_c (self) -> impl Draw { Origin(Some(Azimuth::C), self) } - fn origin_x (self) -> impl Draw<'a, S> { + fn origin_x (self) -> impl Draw { Origin(Some(Azimuth::X), self) } - fn origin_y (self) -> impl Draw<'a, S> { + fn origin_y (self) -> impl Draw { Origin(Some(Azimuth::Y), self) } - fn origin_n (self) -> impl Draw<'a, S> { + fn origin_n (self) -> impl Draw { Origin(Some(Azimuth::N), self) } - fn origin_s (self) -> impl Draw<'a, S> { + fn origin_s (self) -> impl Draw { Origin(Some(Azimuth::S), self) } - fn origin_e (self) -> impl Draw<'a, S> { + fn origin_e (self) -> impl Draw { Origin(Some(Azimuth::E), self) } - fn origin_w (self) -> impl Draw<'a, S> { + fn origin_w (self) -> impl Draw { Origin(Some(Azimuth::W), self) } - fn origin_ne (self) -> impl Draw<'a, S> { + fn origin_ne (self) -> impl Draw { Origin(Some(Azimuth::NE), self) } - fn origin_se (self) -> impl Draw<'a, S> { + fn origin_se (self) -> impl Draw { Origin(Some(Azimuth::SE), self) } - fn origin_nw (self) -> impl Draw<'a, S> { + fn origin_nw (self) -> impl Draw { Origin(Some(Azimuth::NW), self) } - fn origin_sw (self) -> impl Draw<'a, S> { + fn origin_sw (self) -> impl Draw { Origin(Some(Azimuth::SW), self) } } @@ -76,7 +76,7 @@ impl PartialEq for Sizer { } impl Sizer { - pub const fn of <'a, T: Screen> (&self, of: impl Draw<'a, T>) -> impl Draw<'a, T> { + pub const fn of <'a, T: Screen> (&self, of: impl Draw) -> impl Draw { draw(move|to: &mut T|{ let area = of.draw(to)?; self.0.store(area.map(|a|a.w()).unwrap_or(T::Unit::zero()).into(), Relaxed); @@ -102,10 +102,10 @@ impl Sizer { #[macro_export] macro_rules! fn_kw_layout { ($name:ident |$state:ident, $output: ident, $expr:ident| $body:block) => { #[cfg(all(feature = "draw", feature = "eval"))] - pub fn $name <'a, O: Screen, S> ( - $state: &'a S, $output: &mut O, $expr: &'a str - ) -> PerhapsRef<'a, XYWH> where - S: Interpret<'a, O, Option>> + pub fn $name ( + $state: &S, $output: &mut O, $expr: &str + ) -> Perhaps> where + S: Interpret>> + Namespace + Namespace + Namespace> @@ -116,10 +116,10 @@ impl Sizer { #[macro_export] macro_rules! fn_kw_layout_tui { ($name:ident |$state:ident, $output: ident, $expr:ident| $body:block) => { #[cfg(all(feature = "draw", feature = "eval", feature = "term"))] - pub fn $name <'a, S> ( - $state: &'a S, $output: &mut Tui, $expr: &'a str - ) -> PerhapsRef<'a, XYWH> where - S: Interpret<'a, Tui, Option>> + pub fn $name ( + $state: &S, $output: &mut Tui, $expr: &str + ) -> Perhaps> where + S: Interpret>> + Namespace + Namespace + Namespace> @@ -134,9 +134,9 @@ impl Sizer { $Struct:ident { $X:ident $Y:ident $XY:ident } $kw_name:ident $name:literal |$self:ident, $to:ident| $body:block ) => { - impl> $Trait for T {} + impl> $Trait for T {} - pub trait $Trait: Draw<'a, S> + Sized { + pub trait $Trait: Draw + Sized { fn $fn_x > + Copy> (self, x: N) -> $Struct { $Struct::$X(self, x) } fn $fn_y > + Copy> (self, y: N) @@ -145,11 +145,11 @@ impl Sizer { -> $Struct { $Struct::$XY(self, x, y) } } - pub enum $Struct, X: Into>> { + pub enum $Struct, X: Into>> { __(PhantomData), $X(I, X), $Y(I, X), $XY(I, X, X), } - impl , X: Into> + Copy> Draw<'a, S> for $Struct { + impl , X: Into> + Copy> Draw for $Struct { fn draw (&$self, $to: &mut S) -> Perhaps> { $body } } @@ -175,9 +175,9 @@ impl Sizer { $Struct:ident { $X:ident $Y:ident $XY:ident } $kw_name:ident $name:literal |$self:ident, $to:ident| $body:block ) => { - impl> $Trait for T {} + impl> $Trait for T {} - pub trait $Trait: Draw<'a, S> + Sized { + pub trait $Trait: Draw + Sized { fn $fn_x (self) -> $Struct { $Struct::$X(self) } fn $fn_y (self) -> $Struct { $Struct::$Y(self) } fn $fn_xy (self) -> $Struct { $Struct::$XY(self) } @@ -187,7 +187,7 @@ impl Sizer { __(PhantomData), $X(I), $Y(I), $XY(I), } - impl <'a, S: Screen, I: Draw<'a, S>> Draw<'a, S> for $Struct { + impl <'a, S: Screen, I: Draw> Draw for $Struct { fn draw (&$self, $to: &mut S) -> Perhaps> { $body } } diff --git a/src/layout/area.rs b/src/layout/area.rs index 09f827e..11647eb 100644 --- a/src/layout/area.rs +++ b/src/layout/area.rs @@ -6,7 +6,7 @@ use crate::*; /// let _ = area(XYWH(1, 2, 3, 4), "southeast"); /// let _ = area(Some(XYWH(1, 2, 3, 4)), "southeast"); /// ``` -pub fn area <'a, S: Screen, T: Draw<'a, S>, U: Into>>> ( +pub fn area <'a, S: Screen, T: Draw, U: Into>>> ( origin: U, it: T ) -> Area { Area(origin.into(), it) @@ -17,8 +17,8 @@ pub struct Area( pub T, ); -impl<'a, S: Screen, T: Draw<'a, S>> Draw<'a, S> for Area { - fn draw (&self, to: &mut S) -> Drawn<'a, S::Unit> { +impl<'a, S: Screen, T: Draw> Draw for Area { + fn draw (&self, to: &mut S) -> Drawn { to.draw(self.0, &self.1) } } diff --git a/src/layout/axis.rs b/src/layout/axis.rs index 3f30ded..37c98df 100644 --- a/src/layout/axis.rs +++ b/src/layout/axis.rs @@ -1,30 +1,30 @@ use crate::*; -pub enum Full<'a, S: Screen, I: Draw<'a, S>> { +pub enum Full<'a, S: Screen, I: Draw> { __(PhantomData<&'a S>), W(I), H(I), WH(I), } -pub enum Exact<'a, S: Screen, I: Draw<'a, S>, X: Into>> { +pub enum Exact<'a, S: Screen, I: Draw, X: Into>> { __(PhantomData<&'a S>), W(I, X), H(I, X), WH(I, X, X), } -pub enum Push<'a, S: Screen, I: Draw<'a, S>, X: Into>> { +pub enum Push<'a, S: Screen, I: Draw, X: Into>> { __(PhantomData<&'a S>), X(I, X), Y(I, X), XY(I, X, X), } -pub enum Pull<'a, S: Screen, I: Draw<'a, S>, X: Into>> { +pub enum Pull<'a, S: Screen, I: Draw, X: Into>> { __(PhantomData<&'a S>), X(I, X), Y(I, X), XY(I, X, X), } -pub enum Min<'a, S: Screen, I: Draw<'a, S>, X: Into>> { +pub enum Min<'a, S: Screen, I: Draw, X: Into>> { __(PhantomData<&'a S>), W(I, X), H(I, X), WH(I, X, X), } -pub enum Max<'a, S: Screen, I: Draw<'a, S>, X: Into>> { +pub enum Max<'a, S: Screen, I: Draw, X: Into>> { __(PhantomData<&'a S>), W(I, X), H(I, X), WH(I, X, X), } -pub enum Pad<'a, S: Screen, I: Draw<'a, S>, X: Into>> { +pub enum Pad<'a, S: Screen, I: Draw, X: Into>> { __(PhantomData<&'a S>), X(I, X), Y(I, X), XY(I, X, X), } @@ -36,7 +36,7 @@ pub enum Pad<'a, S: Screen, I: Draw<'a, S>, X: Into>> { /// assert_eq!(check_layout("1".full_wh())?, Some(XYWH(1u16, 1, 80, 25))); /// # Ok(()) } /// ``` -pub trait LayoutFull<'a, S: Screen>: Draw<'a, S> + Sized { +pub trait LayoutFull<'a, S: Screen>: Draw + Sized { fn full_w (self) -> Full<'a, S, Self> { Full::W(self) } fn full_h (self) -> Full<'a, S, Self> { Full::H(self) } fn full_wh (self) -> Full<'a, S, Self> { Full::WH(self) } @@ -50,7 +50,7 @@ pub trait LayoutFull<'a, S: Screen>: Draw<'a, S> + Sized { /// assert_eq!(check_layout("FOOBAR\nKILROY".exact_wh(2, 1))?, Some(XYWH(1, 1, 2, 1))); /// # Ok(()) } /// ``` -pub trait LayoutExact<'a, S: Screen>: Draw<'a, S> + Sized { +pub trait LayoutExact<'a, S: Screen>: Draw + Sized { fn exact_w > + Copy> (self, w: X) -> Exact<'a, S, Self, X> { Exact::W(self, w) } fn exact_h > + Copy> (self, h: X) @@ -67,7 +67,7 @@ pub trait LayoutExact<'a, S: Screen>: Draw<'a, S> + Sized { /// assert_eq!(check_layout("123456".min_w(5))?, Some(XYWH(1u16, 1, 6, 1))); /// # Ok(()) } /// ``` -pub trait LayoutMin<'a, S: Screen>: Draw<'a, S> + Sized { +pub trait LayoutMin<'a, S: Screen>: Draw + Sized { fn min_w > + Copy> (self, w: X) -> Min<'a, S, Self, X> { Min::W(self, w) } fn min_h > + Copy> (self, h: X) @@ -76,7 +76,7 @@ pub trait LayoutMin<'a, S: Screen>: Draw<'a, S> + Sized { -> Min<'a, S, Self, X> { Min::WH(self, w, h) } } -pub trait LayoutMax<'a, S: Screen>: Draw<'a, S> + Sized { +pub trait LayoutMax<'a, S: Screen>: Draw + Sized { fn max_w > + Copy> (self, w: X) -> Max<'a, S, Self, X> { Max::W(self, w) } fn max_h > + Copy> (self, h: X) @@ -85,7 +85,7 @@ pub trait LayoutMax<'a, S: Screen>: Draw<'a, S> + Sized { -> Max<'a, S, Self, X> { Max::WH(self, w, h) } } -pub trait LayoutPad<'a, S: Screen>: Draw<'a, S> + Sized { +pub trait LayoutPad<'a, S: Screen>: Draw + Sized { fn pad_w > + Copy> (self, w: X) -> Pad<'a, S, Self, X> { Pad::X(self, w) } fn pad_h > + Copy> (self, h: X) @@ -102,7 +102,7 @@ pub trait LayoutPad<'a, S: Screen>: Draw<'a, S> + Sized { /// assert_eq!(check_layout("1".push_xy(1, 1))?, Some(XYWH(2u16, 2, 1, 1))); /// # Ok(()) } /// ``` -pub trait LayoutPush<'a, S: Screen>: Draw<'a, S> + Sized { +pub trait LayoutPush<'a, S: Screen>: Draw + Sized { fn push_x > + Copy> (self, w: X) -> Push<'a, S, Self, X> { Push::X(self, w) } fn push_y > + Copy> (self, h: X) @@ -119,7 +119,7 @@ pub trait LayoutPush<'a, S: Screen>: Draw<'a, S> + Sized { /// assert_eq!(check_layout("1".pull_xy(1, 1))?, Some(XYWH(0u16, 0, 1, 1))); /// # Ok(()) } /// ``` -pub trait LayoutPull<'a, S: Screen>: Draw<'a, S> + Sized { +pub trait LayoutPull<'a, S: Screen>: Draw + Sized { fn pull_x > + Copy> (self, w: X) -> Pull<'a, S, Self, X> { Pull::X(self, w) } fn pull_y > + Copy> (self, h: X) @@ -129,11 +129,11 @@ pub trait LayoutPull<'a, S: Screen>: Draw<'a, S> + Sized { } #[cfg(all(feature = "draw", feature = "eval"))] -pub fn kw_full <'a, O, S> (state: &'a S, to: &mut O, expr: &'a str) - -> PerhapsRef<'a, XYWH> +pub fn kw_full (state: &S, to: &mut O, expr: &str) + -> Perhaps> where - O: Screen + 'a, - S: Interpret<'a, O, Option>> + O: Screen, + S: Interpret>> + Namespace + Namespace + Namespace> @@ -143,16 +143,16 @@ where Some("full/x") | Some("full/w") => Full::W(thunk).draw(to)?, Some("full/y") | Some("full/h") => Full::H(thunk).draw(to)?, Some("full/xy") | Some("full/wh") => Full::WH(thunk).draw(to)?, - frag => return Err(format!("invalid variant: {frag:?}").into()) + frag => return Err(format!("full: invalid variant: {frag:?}").into()) }) } #[cfg(all(feature = "draw", feature = "eval"))] -pub fn kw_exact <'a, O, S> (state: &'a S, to: &mut O, expr: &'a str) - -> PerhapsRef<'a, XYWH> +pub fn kw_exact (state: &S, to: &mut O, expr: &str) + -> Perhaps> where - O: Screen + 'a, - S: Interpret<'a, O, Option>> + O: Screen, + S: Interpret>> + Namespace + Namespace + Namespace> @@ -169,16 +169,16 @@ where state.namespace(&expr.nth(1)?)?, state.namespace(&expr.nth(2)?)?, ).draw(to)?, - _ => return Err(format!("invalid variant: {:?}", expr.head()?).into()) + _ => return Err(format!("exact: invalid variant: {:?}", expr.head()?).into()) }) } #[cfg(all(feature = "draw", feature = "eval"))] -pub fn kw_min <'a, O, S> (state: &'a S, to: &mut O, expr: &'a str) - -> PerhapsRef<'a, XYWH> +pub fn kw_min (state: &S, to: &mut O, expr: &str) + -> Perhaps> where - O: Screen + 'a, - S: Interpret<'a, O, Option>> + O: Screen, + S: Interpret>> + Namespace + Namespace + Namespace> @@ -195,16 +195,16 @@ where state.namespace(&expr.nth(1)?)?, state.namespace(&expr.nth(2)?)?, ).draw(to)?, - _ => return Err(format!("invalid variant: {:?}", expr.head()?).into()) + _ => return Err(format!("min: invalid variant: {:?}", expr.head()?).into()) }) } #[cfg(all(feature = "draw", feature = "eval"))] -pub fn kw_max <'a, O, S> (state: &'a S, to: &mut O, expr: &'a str) - -> PerhapsRef<'a, XYWH> +pub fn kw_max (state: &S, to: &mut O, expr: &str) + -> Perhaps> where - O: Screen + 'a, - S: Interpret<'a, O, Option>> + O: Screen, + S: Interpret>> + Namespace + Namespace + Namespace> @@ -221,16 +221,16 @@ where state.namespace(&expr.nth(1)?)?, state.namespace(&expr.nth(2)?)?, ).draw(to)?, - _ => return Err(format!("invalid variant: {:?}", expr.head()?).into()) + _ => return Err(format!("max: invalid variant: {:?}", expr.head()?).into()) }) } #[cfg(all(feature = "draw", feature = "eval"))] -pub fn kw_push <'a, O, S> (state: &'a S, to: &mut O, expr: &'a str) - -> PerhapsRef<'a, XYWH> +pub fn kw_push (state: &S, to: &mut O, expr: &str) + -> Perhaps> where - O: Screen + 'a, - S: Interpret<'a, O, Option>> + O: Screen, + S: Interpret>> + Namespace + Namespace + Namespace> @@ -243,16 +243,16 @@ where state.namespace(&expr.nth(1)?)?, state.namespace(&expr.nth(2)?)?, ).draw(to)?, - _ => return Err(format!("invalid variant: {:?}", expr.head()?).into()) + _ => return Err(format!("push: invalid variant: {:?}", expr.head()?).into()) }) } #[cfg(all(feature = "draw", feature = "eval"))] -pub fn kw_pull <'a, O, S> (state: &'a S, to: &mut O, expr: &'a str) - -> PerhapsRef<'a, XYWH> +pub fn kw_pull (state: &S, to: &mut O, expr: &str) + -> Perhaps> where - O: Screen + 'a, - S: Interpret<'a, O, Option>> + O: Screen, + S: Interpret>> + Namespace + Namespace + Namespace> @@ -265,16 +265,16 @@ where state.namespace(&expr.nth(1)?)?, state.namespace(&expr.nth(2)?)?, ).draw(to)?, - _ => return Err(format!("invalid variant: {:?}", expr.head()?).into()) + _ => return Err(format!("pull: invalid variant: {:?}", expr.head()?).into()) }) } #[cfg(all(feature = "draw", feature = "eval"))] -pub fn kw_pad <'a, O, S> (state: &'a S, to: &mut O, expr: &'a str) - -> PerhapsRef<'a, XYWH> +pub fn kw_pad (state: &S, to: &mut O, expr: &str) + -> Perhaps> where - O: Screen + 'a, - S: Interpret<'a, O, Option>> + O: Screen, + S: Interpret>> + Namespace + Namespace + Namespace> @@ -291,12 +291,12 @@ where state.namespace(&expr.nth(1)?)?, state.namespace(&expr.nth(2)?)?, ).draw(to)?, - _ => return Err(format!("invalid variant: {:?}", expr.head()?).into()) + _ => return Err(format!("pad: invalid variant: {:?}", expr.head()?).into()) }) } -impl <'a, S: Screen, I: Draw<'a, S>> Draw<'a, S> for Full<'a, S, I> { - fn draw (&self, to: &mut S) -> Drawn<'a, S::Unit> { +impl <'a, S: Screen, I: Draw> Draw for Full<'a, S, I> { + fn draw (&self, to: &mut S) -> Drawn { let XYWH(x0, y0, w0, h0) = to.area(); let item = match self { Self::W(i) => i, Self::H(i) => i, Self::WH(i) => i, _ => unreachable!() @@ -313,8 +313,8 @@ impl <'a, S: Screen, I: Draw<'a, S>> Draw<'a, S> for Full<'a, S, I> { } } -impl <'a, S: Screen, I: Draw<'a, S>, X: Into> + Copy> Draw<'a, S> for Exact<'a, S, I, X> { - fn draw (&self, to: &mut S) -> Drawn<'a, S::Unit> { +impl <'a, S: Screen, I: Draw, X: Into> + Copy> Draw for Exact<'a, S, I, X> { + fn draw (&self, to: &mut S) -> Drawn { let XYWH(x0, y0, w0, h0) = to.area(); let (item, w1, h1) = match self { Self::W(item, w1) => (item, (*w1).into(), None), @@ -335,8 +335,8 @@ impl <'a, S: Screen, I: Draw<'a, S>, X: Into> + Copy> Draw<'a, S } } -impl <'a, S: Screen, I: Draw<'a, S>, X: Into> + Copy> Draw<'a, S> for Min<'a, S, I, X> { - fn draw (&self, to: &mut S) -> Drawn<'a, S::Unit> { +impl <'a, S: Screen, I: Draw, X: Into> + Copy> Draw for Min<'a, S, I, X> { + fn draw (&self, to: &mut S) -> Drawn { let XYWH(x0, y0, w0, h0) = to.area(); let (item, w1, h1) = match self { Self::W(item, w1) => (item, (*w1).into(), None), @@ -356,8 +356,8 @@ impl <'a, S: Screen, I: Draw<'a, S>, X: Into> + Copy> Draw<'a, S } } -impl <'a, S: Screen, I: Draw<'a, S>, X: Into> + Copy> Draw<'a, S> for Max<'a, S, I, X> { - fn draw (&self, to: &mut S) -> Drawn<'a, S::Unit> { +impl <'a, S: Screen, I: Draw, X: Into> + Copy> Draw for Max<'a, S, I, X> { + fn draw (&self, to: &mut S) -> Drawn { let XYWH(x, y, w0, h0) = to.area(); let (item, w, h) = match self { Self::W(item, w) => (item, (*w).into().unwrap_or(w0), h0), @@ -369,8 +369,8 @@ impl <'a, S: Screen, I: Draw<'a, S>, X: Into> + Copy> Draw<'a, S } } -impl <'a, S: Screen, I: Draw<'a, S>, X: Into> + Copy> Draw<'a, S> for Push<'a, S, I, X> { - fn draw (&self, to: &mut S) -> Drawn<'a, S::Unit> { +impl <'a, S: Screen, I: Draw, X: Into> + Copy> Draw for Push<'a, S, I, X> { + fn draw (&self, to: &mut S) -> Drawn { match self { Self::__(_) => unreachable!(), Self::X(item, x1) if let Some(XYWH(x, y, w, h)) = to.size(None, item)? => { @@ -387,8 +387,8 @@ impl <'a, S: Screen, I: Draw<'a, S>, X: Into> + Copy> Draw<'a, S } } -impl <'a, S: Screen, I: Draw<'a, S>, X: Into> + Copy> Draw<'a, S> for Pull<'a, S, I, X> { - fn draw (&self, to: &mut S) -> Drawn<'a, S::Unit> { +impl <'a, S: Screen, I: Draw, X: Into> + Copy> Draw for Pull<'a, S, I, X> { + fn draw (&self, to: &mut S) -> Drawn { match self { Self::__(_) => unreachable!(), Self::X(item, x1) if let Some(XYWH(x, y, w, h)) = to.size(None, item)? => { @@ -411,8 +411,8 @@ impl <'a, S: Screen, I: Draw<'a, S>, X: Into> + Copy> Draw<'a, S } } -impl <'a, S: Screen, I: Draw<'a, S>, X: Into> + Copy> Draw<'a, S> for Pad<'a, S, I, X> { - fn draw (&self, to: &mut S) -> Drawn<'a, S::Unit> { +impl <'a, S: Screen, I: Draw, X: Into> + Copy> Draw for Pad<'a, S, I, X> { + fn draw (&self, to: &mut S) -> Drawn { let XYWH(x, y, w0, h0) = to.area(); let (item, w, h) = match self { Self::X(item, w) => (item, (*w).into().unwrap_or_default(), Default::default()), @@ -430,20 +430,20 @@ impl <'a, S: Screen, I: Draw<'a, S>, X: Into> + Copy> Draw<'a, S } } -impl<'a, S: Screen, T: Draw<'a, S>> LayoutFull<'a, S> for T {} +impl<'a, S: Screen, T: Draw> LayoutFull<'a, S> for T {} -impl<'a, S: Screen, T: Draw<'a, S>> LayoutExact<'a, S> for T {} +impl<'a, S: Screen, T: Draw> LayoutExact<'a, S> for T {} -impl<'a, S: Screen, T: Draw<'a, S>> LayoutMin<'a, S> for T {} +impl<'a, S: Screen, T: Draw> LayoutMin<'a, S> for T {} -impl<'a, S: Screen, T: Draw<'a, S>> LayoutMax<'a, S> for T {} +impl<'a, S: Screen, T: Draw> LayoutMax<'a, S> for T {} -impl<'a, S: Screen, T: Draw<'a, S>> LayoutPush<'a, S> for T {} +impl<'a, S: Screen, T: Draw> LayoutPush<'a, S> for T {} -impl<'a, S: Screen, T: Draw<'a, S>> LayoutPull<'a, S> for T {} +impl<'a, S: Screen, T: Draw> LayoutPull<'a, S> for T {} -impl<'a, S: Screen, T: Draw<'a, S>> LayoutPad<'a, S> for T {} +impl<'a, S: Screen, T: Draw> LayoutPad<'a, S> for T {} -pub fn check_layout <'a> (t: impl Draw<'a, Tui>) -> Drawn<'a, u16> { +pub fn check_layout <'a> (t: impl Draw) -> Drawn { Tui::Layout(XYWH(1u16, 1, 80, 25)).size(None, t) } diff --git a/src/layout/azimuth.rs b/src/layout/azimuth.rs index dc1dd6c..9433ed3 100644 --- a/src/layout/azimuth.rs +++ b/src/layout/azimuth.rs @@ -18,8 +18,8 @@ pub struct Origin( pub(crate) T ); -impl<'a, S: Screen, T: Draw<'a, S>> Draw<'a, S> for Origin { - fn draw (&self, _to: &mut S) -> Drawn<'a, S::Unit> { +impl<'a, S: Screen, T: Draw> Draw for Origin { + fn draw (&self, _to: &mut S) -> Drawn { todo!() } } @@ -36,11 +36,11 @@ impl> HasOrigin for T { } #[cfg(all(feature = "draw", feature = "eval"))] -pub fn kw_align <'a, O, S> (state: &'a S, to: &mut O, expr: &'a str) - -> Drawn<'a, O::Unit> +pub fn kw_align (state: &S, to: &mut O, expr: &str) + -> Drawn where O: Screen, - S: Interpret<'a, O, Option>> + S: Interpret>> + Namespace + Namespace + Namespace> @@ -58,7 +58,8 @@ where Some("align/sw") => Align(Some(Azimuth::SW), thunk).draw(to)?, Some("align/ne") => Align(Some(Azimuth::NE), thunk).draw(to)?, Some("align/se") => Align(Some(Azimuth::SE), thunk).draw(to)?, - frag => return Err(format!("invalid variant: {frag:?}").into()) + Some(frag) => return Err(format!("align: invalid variant: {frag}").into()), + None => unreachable!() }) //Ok(matches!(expr.head().src()?.unwrap_or_default().split("/").next(), Some("align")).then(||{ //draw(move|output: &mut O|{state.interpret(output, &expr.nth(1))}).align( @@ -73,9 +74,9 @@ where //}).transpose()?.flatten()) } -impl<'a, S: Screen, T: Draw<'a, S>> CanAlign<'a, S> for T {} +impl<'a, S: Screen, T: Draw> CanAlign<'a, S> for T {} -pub trait CanAlign<'a, S: Screen>: Draw<'a, S> + Sized { +pub trait CanAlign<'a, S: Screen>: Draw + Sized { fn align (self, azimuth: impl Into>) -> Align { Align(azimuth.into(), self) } @@ -119,8 +120,8 @@ pub struct Align( pub(crate) T, ); -impl<'a, S: Screen, T: Draw<'a, S>> Draw<'a, S> for Align { - fn draw (&self, to: &mut S) -> Drawn<'a, S::Unit> { +impl<'a, S: Screen, T: Draw> Draw for Align { + fn draw (&self, to: &mut S) -> Drawn { let Self(azimuth, item) = self; let area0 = to.area(); let size = to.size(area0, item)?; @@ -166,7 +167,7 @@ fn_kw_layout!(kw_split |state, output, expr| { Some("bsp/w") => Split::West.stack(thunk_a, thunk_b).draw(output)?, Some("bsp/a") => Split::Above.stack(thunk_a, thunk_b).draw(output)?, Some("bsp/b") => Split::Below.stack(thunk_a, thunk_b).draw(output)?, - frag => return Err(format!("invalid variant: {frag:?}").into()) + frag => return Err(format!("split: invalid variant: {frag:?}").into()) }) }); @@ -187,7 +188,7 @@ pub struct Pair(Split, A, B); /// # fn test_split_stack () -> Usually<()> { /// use ::tengri::*; /// use Split::*; -/// fn size_of <'a, A: Draw<'a, Tui>, B: Draw<'a, Tui>> (stack: &Pair) -> Drawn<'a, S::Unit> { +/// fn size_of <'a, A: Draw, B: Draw> (stack: &Pair) -> Drawn { /// Tui::Layout(XYWH(0, 0, 80, 25)).size(None, stack) /// } /// assert_eq!(size_of(&split(East, "foo", "bar"))?, Some(XYWH(0, 0, 6, 1))); @@ -196,14 +197,14 @@ pub struct Pair(Split, A, B); /// assert_eq!(size_of(&split(East, split(South, "foo", "bar"), "baz"))?, Some(XYWH(0, 0, 6, 2))); /// # return Ok(()); } /// ``` -pub fn split <'a, S: Screen, A: Draw<'a, S>, B: Draw<'a, S>> ( +pub fn split <'a, S: Screen, A: Draw, B: Draw> ( split: Split, a: A, b: B ) -> Pair { Pair(split, a, b) } -impl<'a, S: Screen, A: Draw<'a, S>, B: Draw<'a, S>> Draw<'a, S> for Pair { - fn draw (&self, to: &mut S) -> Drawn<'a, S::Unit> { +impl<'a, S: Screen, A: Draw, B: Draw> Draw for Pair { + fn draw (&self, to: &mut S) -> Drawn { let Self(split, a, b, ..) = self; let (area_a, area_b) = stack_areas(split, to, a, b)?; let (drawn_a, drawn_b) = draw_stacks(split, to, a, area_a, None, b, area_b, None)?; @@ -214,10 +215,10 @@ impl<'a, S: Screen, A: Draw<'a, S>, B: Draw<'a, S>> Draw<'a, S> for Pair { fn draw_stacks <'a, S: Screen> ( split: &Split, to: &mut S, - a: impl Draw<'a, S>, + a: impl Draw, area_a: impl Into>>, origin_a: impl Into>, - b: impl Draw<'a, S>, + b: impl Draw, area_b: impl Into>>, origin_b: impl Into>, ) -> UsuallyRef<'a, (Option>, Option>)> { @@ -254,8 +255,8 @@ fn draw_stacks <'a, S: Screen> ( pub fn stack_areas <'a, S: Screen> ( split: &Split, to: &mut S, - a: impl Draw<'a, S>, - b: impl Draw<'a, S>, + a: impl Draw, + b: impl Draw, ) -> UsuallyRef<'a, (Option>, Option>)> { let area_a = to.size(None, a)?; Ok(match split { @@ -331,8 +332,8 @@ impl Split { /// let _ = Split::East.stack(&"", &""); /// let _ = Split::West.stack(&"", &""); /// ``` - pub const fn stack <'a, S: Screen, A: Draw<'a, S>, B: Draw<'a, S>> (&self, a: A, b: B) - -> impl Draw<'a, S> + pub const fn stack <'a, S: Screen, A: Draw, B: Draw> (&self, a: A, b: B) + -> impl Draw { Pair(*self, a, b) } @@ -346,8 +347,8 @@ impl Split { /// let _ = Split::East.half(&"", &""); /// let _ = Split::West.half(&"", &""); /// ``` - pub const fn half <'a, S: Screen, A: Draw<'a, S>, B: Draw<'a, S>> (&self, a: &A, b: &B) - -> impl Draw<'a, S> + pub const fn half <'a, S: Screen, A: Draw, B: Draw> (&self, a: &A, b: &B) + -> impl Draw { draw(move|to: &mut S|{ let (area_a, area_b) = to.xywh().split_half(self); @@ -402,27 +403,27 @@ impl Split { } -pub const fn east <'a, S: Screen, A: Draw<'a, S>, B: Draw<'a, S>> (a: A, b: B) -> impl Draw<'a, S> { +pub const fn east <'a, S: Screen, A: Draw, B: Draw> (a: A, b: B) -> impl Draw { Pair(Split::East, a, b) } -pub const fn north <'a, S: Screen, A: Draw<'a, S>, B: Draw<'a, S>> (a: A, b: B) -> impl Draw<'a, S> { +pub const fn north <'a, S: Screen, A: Draw, B: Draw> (a: A, b: B) -> impl Draw { Pair(Split::North, a, b) } -pub const fn west <'a, S: Screen, A: Draw<'a, S>, B: Draw<'a, S>> (a: A, b: B) -> impl Draw<'a, S> { +pub const fn west <'a, S: Screen, A: Draw, B: Draw> (a: A, b: B) -> impl Draw { Pair(Split::West, a, b) } -pub const fn south <'a, S: Screen, A: Draw<'a, S>, B: Draw<'a, S>> (a: A, b: B) -> impl Draw<'a, S> { +pub const fn south <'a, S: Screen, A: Draw, B: Draw> (a: A, b: B) -> impl Draw { Pair(Split::South, a, b) } -pub const fn above <'a, S: Screen, A: Draw<'a, S>, B: Draw<'a, S>> (a: A, b: B) -> impl Draw<'a, S> { +pub const fn above <'a, S: Screen, A: Draw, B: Draw> (a: A, b: B) -> impl Draw { Pair(Split::Above, a, b) } -pub const fn below <'a, S: Screen, A: Draw<'a, S>, B: Draw<'a, S>> (a: A, b: B) -> impl Draw<'a, S> { +pub const fn below <'a, S: Screen, A: Draw, B: Draw> (a: A, b: B) -> impl Draw { Pair(Split::Below, a, b) } diff --git a/src/layout/cond.rs b/src/layout/cond.rs index 5adfdd7..9dab1d1 100644 --- a/src/layout/cond.rs +++ b/src/layout/cond.rs @@ -10,11 +10,11 @@ fn_kw_layout!(kw_when |state, output, expr| { /// Only render when condition is true. /// /// ``` -/// # use ::tengri::*; fn test <'a> () -> impl Draw<'a, Tui> { +/// # use ::tengri::*; fn test <'a> () -> impl Draw { /// when(true, "Yes") /// # } /// ``` -pub const fn when <'a, T: Screen> (condition: bool, item: impl Draw<'a, T>) -> impl Draw<'a, T> { +pub const fn when <'a, T: Screen> (condition: bool, item: impl Draw) -> impl Draw { draw(move|to: &mut T|if condition { item.draw(to) } else { Ok(Default::default()) }) } @@ -29,12 +29,12 @@ fn_kw_layout!(kw_either |state, output, expr| { /// Render one thing if a condition is true and another false. /// /// ``` -/// # use ::tengri::*; fn test <'a> () -> impl Draw<'a, Tui> { +/// # use ::tengri::*; fn test <'a> () -> impl Draw { /// either(true, "Yes", "No") /// # } /// ``` pub const fn either <'a, T: Screen> ( - condition: bool, a: impl Draw<'a, T>, b: impl Draw<'a, T> -) -> impl Draw<'a, T> { + condition: bool, a: impl Draw, b: impl Draw +) -> impl Draw { draw(move|to: &mut T|if condition { a.draw(to) } else { b.draw(to) }) } diff --git a/src/layout/iter.rs b/src/layout/iter.rs index cede6d6..9454150 100644 --- a/src/layout/iter.rs +++ b/src/layout/iter.rs @@ -1,8 +1,8 @@ use super::*; -pub fn iter_south <'a, S: Screen, D: Draw<'a, S>, I: Iterator> ( +pub fn iter_south <'a, S: Screen, D: Draw, I: Iterator> ( iter: impl Fn()->I -) -> impl Draw<'a, S> { +) -> impl Draw { draw(move|to: &mut S|{ let XYWH(x, y, w, h) = to.area(); let mut y_next = y; @@ -22,9 +22,9 @@ pub fn iter_south <'a, S: Screen, D: Draw<'a, S>, I: Iterator> ( }) } -pub fn iter_east <'a, S: Screen, D: Draw<'a, S>, I: Iterator> ( +pub fn iter_east <'a, S: Screen, D: Draw, I: Iterator> ( iter: impl Fn()->I -) -> impl Draw<'a, S> { +) -> impl Draw { draw(move|to: &mut S|{ let XYWH(x, y, w, h) = to.area(); let mut x_next = x; @@ -45,16 +45,16 @@ pub fn iter_east <'a, S: Screen, D: Draw<'a, S>, I: Iterator> ( } /// Iterate over a collection of the same kind of [Draw]able: -pub fn iter <'a, S: Screen, D: 'a, I: Iterator, U: Draw<'a, S>> ( +pub fn iter <'a, S: Screen, D: 'a, I: Iterator, U: Draw> ( _iter: impl Fn()->I, _draw: impl Fn(D, usize)->U, -) -> impl Draw<'a, S> { +) -> impl Draw { draw(move|_to: &mut S|{ todo!() }) } /// Iterate over a collection of the same kind of [Draw]able: -pub fn iter_once <'a, S: Screen, D: 'a, U: Draw<'a, S>> ( +pub fn iter_once <'a, S: Screen, D: 'a, U: Draw> ( _iter: impl Iterator, _draw: impl Fn(D, usize)->U, -) -> impl Draw<'a, S> { +) -> impl Draw { draw(move|_to: &mut S|{ todo!() }) } @@ -65,55 +65,55 @@ pub fn iter_dyn < D, // Input doesn't need to be [Draw]able, output does V: Fn()->I, // Function that returns the iterator I: Iterator, // Type of the iterator - F: Fn(&D, usize)->dyn Draw<'a, S>, // Function that returns [Draw]able from iterator item -> (_items: V, _cb: F) -> impl Draw<'a, S> { + F: Fn(&D, usize)->dyn Draw, // Function that returns [Draw]able from iterator item +> (_items: V, _cb: F) -> impl Draw { draw(move|_to: &mut S|{ todo!() }) } -pub fn iter_north <'a, S: Screen, D: 'a, I: Iterator, U: Draw<'a, S>> ( +pub fn iter_north <'a, S: Screen, D: 'a, I: Iterator, U: Draw> ( _iter: impl Fn()->I, _draw: impl Fn(D, usize)->U, -) -> impl Draw<'a, S> { +) -> impl Draw { draw(move|_to: &mut S|{ todo!() }) } -pub fn iter_east_fixed <'a, S: Screen, D: 'a, I: Iterator, U: Draw<'a, S>> ( +pub fn iter_east_fixed <'a, S: Screen, D: 'a, I: Iterator, U: Draw> ( _height: S::Unit, _iter: impl Fn()->I, _draw: impl Fn(D, usize)->U, -) -> impl Draw<'a, S> { +) -> impl Draw { draw(move|_to: &mut S|{ todo!() }) } -pub fn iter_south_fixed <'a, S: Screen, D: 'a, I: Iterator, U: Draw<'a, S>> ( +pub fn iter_south_fixed <'a, S: Screen, D: 'a, I: Iterator, U: Draw> ( _height: S::Unit, _iter: impl Fn()->I, _draw: impl Fn(D, usize)->U, -) -> impl Draw<'a, S> { +) -> impl Draw { draw(move|_to: &mut S|{ todo!() }) } -pub fn iter_west <'a, S: Screen, D: 'a, I: Iterator, U: Draw<'a, S>> ( +pub fn iter_west <'a, S: Screen, D: 'a, I: Iterator, U: Draw> ( _iter: impl Fn()->I, _draw: impl Fn(D, usize)->U, -) -> impl Draw<'a, S> { +) -> impl Draw { draw(move|_to: &mut S|{ todo!() }) } -pub fn row_south <'a, S: Screen + 'a> (south: S::Unit, height: S::Unit, content: impl Draw<'a, S>) - -> impl Draw<'a, S> +pub fn row_south <'a, S: Screen + 'a> (south: S::Unit, height: S::Unit, content: impl Draw) + -> impl Draw { content.exact_h(height).push_y(south) } -pub fn row_north <'a, S: Screen + 'a> (north: S::Unit, height: S::Unit, content: impl Draw<'a, S>) - -> impl Draw<'a, S> +pub fn row_north <'a, S: Screen + 'a> (north: S::Unit, height: S::Unit, content: impl Draw) + -> impl Draw { content.exact_h(height).pull_y(north) } -pub fn col_east <'a, S: Screen + 'a> (east: S::Unit, width: S::Unit, content: impl Draw<'a, S>) - -> impl Draw<'a, S> +pub fn col_east <'a, S: Screen + 'a> (east: S::Unit, width: S::Unit, content: impl Draw) + -> impl Draw { content.exact_w(width).push_x(east) } -pub fn col_west <'a, S: Screen + 'a> (west: S::Unit, width: S::Unit, content: impl Draw<'a, S>) - -> impl Draw<'a, S> +pub fn col_west <'a, S: Screen + 'a> (west: S::Unit, width: S::Unit, content: impl Draw) + -> impl Draw { content.exact_w(width).pull_x(west) } diff --git a/src/lib.rs b/src/lib.rs index 6d5c745..aad88f6 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1268,14 +1268,14 @@ pub trait AsMutOpt { fn as_mut_opt (&mut self) -> Option<&mut T>; } fn size <'a> ( &mut self, area: impl Into>>, - draw: impl Draw<'a, Self> - ) -> Drawn<'a, Self::Unit>; + draw: impl Draw + ) -> Drawn; /// Draw fn draw <'a> ( &mut self, area: impl Into>>, - draw: impl Draw<'a, Self> - ) -> Drawn<'a, Self::Unit>; + draw: impl Draw + ) -> Drawn; } /// Implement the [Draw] trait for a particular drawable and [Screen]. @@ -1290,7 +1290,7 @@ pub trait AsMutOpt { fn as_mut_opt (&mut self) -> Option<&mut T>; } #[macro_export] macro_rules! impl_draw ( ($(<$($T:ident: $Trait:path,)+>)?| $self:ident:$Self:path, $to:ident:$To:ty - |$draw:block)=>{ impl$(<$($T:$Trait),+>)? Draw<'_, $To> for $Self { + |$draw:block)=>{ impl$(<$($T:$Trait),+>)? Draw<$To> for $Self { fn draw (&$self, $to: &mut $To) -> Perhaps::Unit>> $draw } }; ($(<$($T:ident: $Trait:path,)+>)?| @@ -1321,48 +1321,48 @@ pub trait AsMutOpt { fn as_mut_opt (&mut self) -> Option<&mut T>; } /// } /// } /// ``` - pub trait Draw<'a, S: Screen> { - fn draw (&self, to: &mut S) -> Drawn<'a, S::Unit>; + pub trait Draw { + fn draw (&self, to: &mut S) -> Drawn; } - /// Emit a [Draw]able. - /// - /// Speculative. How to avoid conflicts with [Draw] proper? - pub trait View { - fn view (&self) -> impl Draw; - } + ///// Emit a [Draw]able. + ///// + ///// Speculative. How to avoid conflicts with [Draw] proper? + //pub trait View { + //fn view (&self) -> impl Draw ; + //} - impl View for () { - fn view (&self) -> impl Draw { - () - } - } + //impl View for () { + //fn view (&self) -> impl Draw { + //() + //} + //} - /// Return a [Draw]able. - /// - /// ``` - /// # use tengri::*; - /// let _ = view::(||"drawable"); - /// let _ = view::(||Some("drawable")); - /// ``` - pub const fn view Draw<'a, S>, F: Fn()->T> (view: F) -> impl View { - ViewThunk(view, PhantomData) - } + ///// Return a [Draw]able. + ///// + ///// ``` + ///// # use tengri::*; + ///// let _ = view::(||"drawable"); + ///// let _ = view::(||Some("drawable")); + ///// ``` + //pub const fn view Draw, F: Fn()->T> (view: F) -> impl View { + //ViewThunk(view, PhantomData) + //} - /// Because we can't implement [Draw] for `F: FnOnce...` without conflicts. - pub struct ViewThunk(pub F, std::marker::PhantomData); + ///// Because we can't implement [Draw] for `F: FnOnce...` without conflicts. + //pub struct ViewThunk(pub F, std::marker::PhantomData); - impl Draw<'a, S>, F: Fn()->T> View for ViewThunk { - fn view (&self) -> impl Draw { - self.0() - } - } + //impl Draw, F: Fn()->T> View for ViewThunk { + //fn view (&self) -> impl Draw { + //self.0() + //} + //} /// Because we can't implement [Draw] for `F: FnOnce...` without conflicts. pub struct DrawThunk(pub F, std::marker::PhantomData); - impl<'a, T: Screen, F: Fn(&mut T)->PerhapsRef<'a, XYWH>> Draw<'a, T> for DrawThunk { - fn draw (&self, to: &mut T) -> PerhapsRef<'a, XYWH> { + implDrawn> Draw for DrawThunk { + fn draw (&self, to: &mut T) -> Drawn { to.clip(None, &self.0) } } @@ -1379,16 +1379,16 @@ pub trait AsMutOpt { fn as_mut_opt (&mut self) -> Option<&mut T>; } DrawThunk(item, std::marker::PhantomData) } - pub type Drawn<'a, U> = PerhapsRef<'a, XYWH>; + pub type Drawn = Perhaps>; - impl<'a, S: Screen> Draw<'a, S> for () { - fn draw (&self, _: &mut S) -> Drawn<'a, S::Unit> { + impl<'a, S: Screen> Draw for () { + fn draw (&self, _: &mut S) -> Drawn { Ok(None) } } - impl<'a, S: Screen, D: Draw<'a, S>> Draw<'a, S> for Option { - fn draw (&self, to: &mut S) -> Drawn<'a, S::Unit> { + impl<'a, S: Screen, D: Draw> Draw for Option { + fn draw (&self, to: &mut S) -> Drawn { self.as_ref().map(|it|it.draw(to)).transpose().map(Option::unwrap_or_default) } } @@ -1405,8 +1405,8 @@ pub trait AsMutOpt { fn as_mut_opt (&mut self) -> Option<&mut T>; } //} //} - impl<'a, T: Screen, V: Draw<'a, T>> Draw<'a, T> for &V { - fn draw (&self, to: &mut T) -> Drawn<'a, T::Unit> { + impl<'a, T: Screen, V: Draw> Draw for &V { + fn draw (&self, to: &mut T) -> Drawn { (*self).draw(to) } } diff --git a/src/term.rs b/src/term.rs index 97ba47d..f4b739b 100644 --- a/src/term.rs +++ b/src/term.rs @@ -97,13 +97,13 @@ impl Screen for Tui { self.into() } fn size <'a> ( - &mut self, area: impl Into>>, draw: impl Draw<'a, Self>, - ) -> Drawn<'a, Self::Unit> { + &mut self, area: impl Into>>, draw: impl Draw, + ) -> Drawn { Self::Layout(self.area()).clip(area, &|to|draw.draw(to)) } fn draw <'a> ( - &mut self, area: impl Into>>, draw: impl Draw<'a, Tui> - ) -> Drawn<'a, Self::Unit> { + &mut self, area: impl Into>>, draw: impl Draw + ) -> Drawn { self.clip(area, &|to|draw.draw(to)) } fn clip ( @@ -132,7 +132,7 @@ impl Tui { })); } pub fn run_main (exit: Exit, state: Arc>) -> Usually<()> where - T: View + Apply> + Send + Sync + 'static + T: Draw + Apply> + Send + Sync + 'static { let scan = Duration::from_millis(100); let frame = Duration::from_millis(10); @@ -142,7 +142,7 @@ impl Tui { } /// Spawn the TUI input and output threadsl. pub fn io < - T: View + Apply> + Send + Sync + 'static, + T: Draw + Apply> + Send + Sync + 'static, W: Write + Send + Sync + 'static, > ( exited: &Arc, @@ -252,7 +252,8 @@ impl Tui { /// }); /// ``` pub fn output < - W: Write + Send + Sync + 'static, T: View + Send + Sync + 'static + W: Write + Send + Sync + 'static, + T: Draw + Send + Sync + 'static > ( exited: &Arc, state: &Arc>, @@ -271,7 +272,7 @@ impl Tui { let Size { width, height } = backend.size().expect("get size failed"); if let Ok(state) = state.try_read() { prev.resize(&mut backend, width, height); - state.view().draw(&mut next).expect("draw failed"); // TODO draw error + state.draw(&mut next).expect("draw failed"); // TODO draw error prev.redraw(&mut backend, &mut next); } let timer = format!("{:>3.3}ms", perf.used.load(Relaxed)); @@ -289,7 +290,7 @@ impl Tui { /// let _ = tengri::Tui::catcher(&variant); /// } /// ``` - pub fn catcher <'a, T: Draw<'a, Tui>> (result: &Usually) -> impl Draw<'a, Tui> { + pub fn catcher <'a, T: Draw> (result: &Usually) -> impl Draw { draw(move|to: &mut Tui|match result { Ok(content) => content.draw(to), Err(e) => { @@ -369,7 +370,7 @@ impl<'a: 'b, 'b> From<&'a mut Tui> for &'b mut XYWH { } } -pub const fn fill_char <'a> (c: char) -> impl Draw<'a, Tui> { +pub const fn fill_char <'a> (c: char) -> impl Draw { draw(move|to: &mut Tui|Ok(Some(to.update(&|cell,_,_|{ cell.set_char(c); })))) @@ -378,8 +379,8 @@ pub const fn fill_char <'a> (c: char) -> impl Draw<'a, Tui> { /// FIXME: Don't use `format!` but implement number blitting pub struct ShowSize; -impl<'a> Draw<'a, Tui> for ShowSize { - fn draw (&self, to: &mut Tui) -> Drawn<'a, u16> { +impl<'a> Draw for ShowSize { + fn draw (&self, to: &mut Tui) -> Drawn { let area = to.area(); let info = format!("{area:?}"); to.text(&info, area.0, area.1, info.len() as u16) @@ -388,8 +389,8 @@ impl<'a> Draw<'a, Tui> for ShowSize { pub struct ShowSizeOf(pub T); -impl<'a, T: Draw<'a, Tui>> Draw<'a, Tui> for ShowSizeOf { - fn draw (&self, to: &mut Tui) -> Drawn<'a, u16> { +impl<'a, T: Draw> Draw for ShowSizeOf { + fn draw (&self, to: &mut Tui) -> Drawn { Ok(self.0.draw(to)?.map(|used|{ let _ = to.text(&format!("{used:?}"), used.0, used.1, u16::MAX); used @@ -474,8 +475,8 @@ impl<'a, T: Draw<'a, Tui>> Draw<'a, Tui> for ShowSizeOf { self.as_ref().draw(to) }); - impl<'a> Draw<'a, Tui> for &str { - fn draw (&self, to: &mut Tui) -> Drawn<'a, u16> { + impl<'a> Draw for &str { + fn draw (&self, to: &mut Tui) -> Drawn { let XYWH(x, y, w, h) = to.area(); let mut max_w = 0u16; let mut max_h = 0u16; @@ -494,8 +495,8 @@ impl<'a, T: Draw<'a, Tui>> Draw<'a, Tui> for ShowSizeOf { } } - impl<'a, T: AsRef> Draw<'a, Tui> for TrimStr<'a, T> { - fn draw (&self, to: &mut Tui) -> Drawn<'a, u16> { + impl<'a, T: AsRef> Draw for TrimStr<'a, T> { + fn draw (&self, to: &mut Tui) -> Drawn { let text = self.1.as_ref(); let area = layout_text_u16(text, to.area())?.unwrap(); let XYWH(x, y, w, ..) = to.area(); diff --git a/src/term/border.rs b/src/term/border.rs index c7167ab..a6f78bb 100644 --- a/src/term/border.rs +++ b/src/term/border.rs @@ -6,8 +6,8 @@ use crate::*; /// /// TODO /// ``` pub fn border <'a> ( - on: bool, style: impl BorderStyle<'a>, item: impl Draw<'a, Tui> -) -> impl Draw<'a, Tui> { + on: bool, style: impl BorderStyle<'a>, item: impl Draw +) -> impl Draw { let content = item.pad_wh(1, 1); let outline = when(on, draw(move|to: &mut Tui|{ let XYWH(x, y, w, h) = to.area(); @@ -49,7 +49,7 @@ macro_rules! border { } #[derive(Copy, Clone)] pub struct $T(pub bool, pub Style); //impl Layout for $T {} - impl<'a> Draw<'a, Tui> for $T { + impl<'a> Draw for $T { fn draw (&self, to: &mut Tui) -> Perhaps> { when(self.enabled(), draw(|to: &mut Tui|BorderStyle::draw(*self, to).map(Some))).draw(to) } @@ -163,7 +163,7 @@ border! { } } -pub trait BorderStyle<'a>: Draw<'a, Tui> + Copy { +pub trait BorderStyle<'a>: Draw + Copy { fn enabled (&self) -> bool; fn border_n (&self) -> &str { Self::N } fn border_s (&self) -> &str { Self::S } diff --git a/src/term/modify.rs b/src/term/modify.rs index 6c8fe70..491e738 100644 --- a/src/term/modify.rs +++ b/src/term/modify.rs @@ -56,8 +56,8 @@ impl Tui { } /// Apply foreground color. -pub const fn fg <'a> (fg: Color, item: impl Draw<'a, Tui>) - -> impl Draw<'a, Tui> +pub const fn fg <'a> (fg: Color, item: impl Draw) + -> impl Draw { draw(move|to: &mut Tui|{ if let Some(size) = to.size(None, &item)? { @@ -72,8 +72,8 @@ pub const fn fg <'a> (fg: Color, item: impl Draw<'a, Tui>) } /// Apply background color. -pub const fn bg <'a> (bg: Color, item: impl Draw<'a, Tui>) - -> impl Draw<'a, Tui> +pub const fn bg <'a> (bg: Color, item: impl Draw) + -> impl Draw { draw(move|to: &mut Tui|{ if let Some(size) = to.size(None, &item)? { @@ -87,8 +87,8 @@ pub const fn bg <'a> (bg: Color, item: impl Draw<'a, Tui>) }) } -pub const fn fg_bg <'a> (fg: Color, bg: Color, item: impl Draw<'a, Tui>) - -> impl Draw<'a, Tui> +pub const fn fg_bg <'a> (fg: Color, bg: Color, item: impl Draw) + -> impl Draw { draw(move|to: &mut Tui|{ if let Some(size) = to.size(None, &item)? { @@ -103,8 +103,8 @@ pub const fn fg_bg <'a> (fg: Color, bg: Color, item: impl Draw<'a, Tui>) } /// Draw contents with modifier applied. -pub const fn modify <'a> (on: bool, modifier: Modifier, item: impl Draw<'a, Tui>) - -> impl Draw<'a, Tui> +pub const fn modify <'a> (on: bool, modifier: Modifier, item: impl Draw) + -> impl Draw { draw(move|to: &mut Tui|{ fill_mod(on, modifier).draw(to)?; @@ -112,7 +112,7 @@ pub const fn modify <'a> (on: bool, modifier: Modifier, item: impl Draw<'a, Tui> }) } -pub const fn fill_mod <'a> (on: bool, modifier: Modifier) -> impl Draw<'a, Tui> { +pub const fn fill_mod <'a> (on: bool, modifier: Modifier) -> impl Draw { draw(move|to: &mut Tui|Ok(Some({ if on { to.update(&|cell,_,_|cell.modifier.insert(modifier)) @@ -123,11 +123,11 @@ pub const fn fill_mod <'a> (on: bool, modifier: Modifier) -> impl Draw<'a, Tui> } /// Draw contents with bold modifier applied. -pub const fn bold <'a> (on: bool, item: impl Draw<'a, Tui>) -> impl Draw<'a, Tui> { +pub const fn bold <'a> (on: bool, item: impl Draw) -> impl Draw { modify(on, Modifier::BOLD, item) } -pub const fn fill_ul <'a> (color: Option) -> impl Draw<'a, Tui> { +pub const fn fill_ul <'a> (color: Option) -> impl Draw { draw(move|to: &mut Tui|Ok(Some(if let Some(color) = color { to.update(&|cell,_,_|{ cell.modifier.insert(Modifier::UNDERLINED); diff --git a/src/term/phat.rs b/src/term/phat.rs index e494a20..21e3c83 100644 --- a/src/term/phat.rs +++ b/src/term/phat.rs @@ -6,8 +6,8 @@ use crate::*; /// /// TODO /// ``` pub fn phat <'a> ( - w: u16, h: u16, [fg, bg, hi, lo]: [Color;4], draw: impl Draw<'a, Tui> -) -> impl Draw<'a, Tui> { + w: u16, h: u16, [fg, bg, hi, lo]: [Color;4], draw: impl Draw +) -> impl Draw { let top = phat_lo(bg, hi).exact_h(1); let low = phat_hi(bg, lo).exact_h(1); let draw = fg_bg(fg, bg, draw); @@ -19,11 +19,11 @@ pub const LO: &'static str = "▄"; pub const HI: &'static str = "▀"; /// A phat line -fn phat_lo <'a> (fg: Color, bg: Color) -> impl Draw<'a, Tui> { +fn phat_lo <'a> (fg: Color, bg: Color) -> impl Draw { fg_bg(fg, bg, x_repeat(LO)).exact_h(1) } /// A phat line -fn phat_hi <'a> (fg: Color, bg: Color) -> impl Draw<'a, Tui> { +fn phat_hi <'a> (fg: Color, bg: Color) -> impl Draw { fg_bg(fg, bg, x_repeat(HI)).exact_h(1) } diff --git a/src/term/scroll.rs b/src/term/scroll.rs index 8dc16a8..4c2d154 100644 --- a/src/term/scroll.rs +++ b/src/term/scroll.rs @@ -6,7 +6,7 @@ pub const ICON_INC_V: &[char] = &['▼']; pub const ICON_DEC_H: &[char] = &[' ', '🞀', ' ']; pub const ICON_INC_H: &[char] = &[' ', '🞂', ' ']; -pub fn x_scroll <'a> () -> impl Draw<'a, Tui> { +pub fn x_scroll <'a> () -> impl Draw { draw(|to: &mut Tui|{ let XYWH(x1, y1, w, _h) = to.area(); let x2 = x1 + w; @@ -37,7 +37,7 @@ pub fn x_scroll <'a> () -> impl Draw<'a, Tui> { }) } -pub fn y_scroll <'a> () -> impl Draw<'a, Tui> { +pub fn y_scroll <'a> () -> impl Draw { draw(|to: &mut Tui|{ let XYWH(x1, y1, _w, h) = to.area(); let y2 = y1 + h;