diff --git a/dizzle b/dizzle index 0050385..af2a107 160000 --- a/dizzle +++ b/dizzle @@ -1 +1 @@ -Subproject commit 0050385e63ea5d3ab9be7c495dae5fc635396cf0 +Subproject commit af2a10751f87caef8e5526d1f692c941b8de8357 diff --git a/src/draw.rs b/src/draw.rs index a672576..64738bd 100644 --- a/src/draw.rs +++ b/src/draw.rs @@ -24,15 +24,7 @@ use crate::*; pub trait Screen: Xy + Wh + Send + Sync + Sized { type Unit: Coord; /// Render drawable in subarea specified by `area` - fn show (&mut self, content: impl Draw) -> Perhaps>; - /// Get current clipping area - fn area (&self) -> XYWH; - /// Set clipping area - fn clip ( - &mut self, - area: impl Into>>, - draw: impl FnOnce(&mut Self)->T - ) -> T; + fn show > (&mut self, content: T) -> Perhaps>; } /// Implement the [Draw] trait for a particular drawable and [Screen]. diff --git a/src/draw/coord.rs b/src/draw/coord.rs index 053258e..40d784d 100644 --- a/src/draw/coord.rs +++ b/src/draw/coord.rs @@ -33,8 +33,3 @@ pub trait Coord: Send + Sync + Copy /// Convert to [AtomicUsize]. fn atomic (self) -> AtomicUsize { AtomicUsize::new(self.into()) } } - -/// TUI works in u16 coordinates. -impl Coord for u16 { - fn plus (self, other: Self) -> Self { self.saturating_add(other) } -} diff --git a/src/draw/layout.rs b/src/draw/layout.rs index 0c892aa..71dca39 100644 --- a/src/draw/layout.rs +++ b/src/draw/layout.rs @@ -71,16 +71,16 @@ pub trait Layout: Draw + Sized { Push::XY(self, x.into(), y.into()) } - fn align (self, azimuth: impl Into>) -> Align { + fn align (self, azimuth: impl Into>) -> impl Draw { Align(azimuth.into(), self) } - fn align_c (self) -> Align { + fn align_c (self) -> impl Draw { Align(Some(Azimuth::C), self) } - fn align_x (self) -> Align { + fn align_x (self) -> impl Draw { Align(Some(Azimuth::X), self) } - fn align_y (self) -> Align { + fn align_y (self) -> impl Draw { Align(Some(Azimuth::Y), self) } @@ -287,27 +287,8 @@ impl_draw!(, X: Into>,>|self: Pad pub struct Align(Option, T); -impl_draw!(,>|self: Align, to: S|{ - use Azimuth::*; - let XYWH(x0, y0, w0, h0) = to.area(); - if let Some(XYWH(x, y, w, h)) = self.1.layout(to.area())? { - to.clip(match self.0 { - Some(NW) => XYWH(x0, y0, w, h), - Some(N) => XYWH(x0 + w0.sub(w) / 2.into(), y0, w, h), - Some(NE) => XYWH((x0 + w0).sub(w), y0, w, h), - Some(W) => XYWH(x0, y0 + h0.sub(h) / 2.into(), w, h), - Some(C) => XYWH(x0 + w0.sub(w) / 2.into(), y0 + h0.sub(h) / 2.into(), w, h), - Some(E) => XYWH((x0 + w0).sub(w), y0 + h0.sub(h) / 2.into(), w, h), - Some(SW) => XYWH(x0, (y0 + h0).sub(h), w, h), - Some(S) => XYWH(x0 + w0.sub(w) / 2.into(), (y0 + h0).sub(h), w, h), - Some(SE) => XYWH((x0 + w0).sub(w), (y0 + h0).sub(h), w, h), - Some(X) => XYWH(x0 + w0.sub(w) / 2.into(), y, w, h), - Some(Y) => XYWH(x, y0 + h0.sub(h) / 2.into(), w, h), - None => to.area() - }, |to|self.1.draw(to)) - } else { - self.1.draw(to) - } +impl_draw!(,>|self: Align, _to: S|{ + todo!() }); /// Where is [0, 0] located? @@ -334,13 +315,10 @@ pub fn area , U: Into>>> ( Area(origin.into(), it) } -pub struct Area>( - pub Option>, - pub T -); +pub struct Area>(Option>, T); -impl_draw!(,>|self: Area, to: S|{ - to.clip(self.0, |to|self.1.draw(to)) +impl_draw!(,>|self: Area, _to: S|{ + todo!() }); pub struct Origin(Option, T); diff --git a/src/draw/split.rs b/src/draw/split.rs index 1cee49c..37ef914 100644 --- a/src/draw/split.rs +++ b/src/draw/split.rs @@ -1,26 +1,27 @@ use super::*; +use Azimuth::*; -pub const fn east , B: Draw> (a: A, b: B) -> impl Draw { +pub const fn east (a: impl Draw, b: impl Draw) -> impl Draw { Split::East.half(a, b) } -pub const fn north , B: Draw> (a: A, b: B) -> impl Draw { +pub const fn north (a: impl Draw, b: impl Draw) -> impl Draw { Split::North.half(a, b) } -pub const fn west , B: Draw> (a: A, b: B) -> impl Draw { +pub const fn west (a: impl Draw, b: impl Draw) -> impl Draw { Split::West.half(a, b) } -pub const fn south , B: Draw> (a: A, b: B) -> impl Draw { +pub const fn south (a: impl Draw, b: impl Draw) -> impl Draw { Split::South.half(a, b) } -pub const fn above , B: Draw> (a: A, b: B) -> impl Draw { +pub const fn above (a: impl Draw, b: impl Draw) -> impl Draw { Split::Above.half(a, b) } -pub const fn below , B: Draw> (a: A, b: B) -> impl Draw { +pub const fn below (a: impl Draw, b: impl Draw) -> impl Draw { Split::Below.half(a, b) } @@ -46,8 +47,8 @@ impl Split { /// let _ = Split::East.half("", ""); /// let _ = Split::West.half("", ""); /// ``` - pub const fn half , B: Draw> (&self, a: A, b: B) -> impl Draw { - thunk(move|to: &mut S|{ + pub const fn half (&self, a: impl Draw, b: impl Draw) -> impl Draw { + thunk(move|to: &mut T|{ let (area_a, area_b) = to.xywh().split_half(self); let (origin_a, origin_b) = self.origins(); let a = a.align(origin_a); diff --git a/src/eval.rs b/src/eval.rs index d103a0a..423cb64 100644 --- a/src/eval.rs +++ b/src/eval.rs @@ -119,17 +119,19 @@ pub fn eval_view <'a, O: Screen + 'a, S> ( ).draw(output), // Second `frags.next()` calls returns the namespace member. - Some("bsp") => eval_enum!("bsp", output, state, frags.next(), arg0, Split { - "n" => North, - "s" => South, - "e" => East, - "w" => West, - "a" => Above, - "b" => Below - }).half( - thunk(move|output: &mut O|{state.interpret(output, &arg0)}), - thunk(move|output: &mut O|{state.interpret(output, &arg1)}), - ).draw(output), + Some("bsp") => { + eval_enum!("bsp", output, state, frags.next(), arg0, Split { + "n" => North, + "s" => South, + "e" => East, + "w" => West, + "a" => Above, + "b" => Below + }).half( + thunk(move|output: &mut O|{state.interpret(output, &arg0)}), + thunk(move|output: &mut O|{state.interpret(output, &arg1)}), + ).draw(output) + }, Some("align") => { let content = thunk(move|output: &mut O|{state.interpret(output, &arg0)}); diff --git a/src/term/output.rs b/src/term/output.rs index 237860b..b91f919 100644 --- a/src/term/output.rs +++ b/src/term/output.rs @@ -1,10 +1,13 @@ use crate::*; use ratatui::{prelude::{Style, Position, Backend, Color}}; +/// TUI works in u16 coordinates. +impl Coord for u16 { fn plus (self, other: Self) -> Self { self.saturating_add(other) } } + impl Screen for Tui { type Unit = u16; /// Render drawable in subarea specified by `area` - fn show (&mut self, content: impl Draw) -> Perhaps> { + fn show <'t, T: Draw> (&mut self, content: T) -> Perhaps> { let previous_area = self.1; Ok(if let Some(area) = content.layout(self.1)? { self.1 = area; @@ -18,25 +21,6 @@ impl Screen for Tui { None }) } - - /// Get current clipping area - fn area (&self) -> XYWH { - self.1 - } - - fn clip ( - &mut self, - area: impl Into>>, - draw: impl FnOnce(&mut Self)->T - ) -> T { - let prev = self.1; - if let Some(area) = area.into() { - self.1 = area.into(); - } - let result = draw(self); - self.1 = prev; - result - } } /// Enable TUI output for state struct.