diff --git a/output/src/content.rs b/output/src/content.rs index f63e98b..7a633f2 100644 --- a/output/src/content.rs +++ b/output/src/content.rs @@ -1,111 +1,32 @@ use crate::*; -pub trait HasContent { fn content (&self) -> impl Content; } + pub trait Content: Draw + Layout {} + impl + Layout> Content for T {} -impl<'a, O: Out> AsRef + 'a> for dyn Content + 'a { fn as_ref (&self) -> &(dyn Draw + 'a) { self } } -impl<'a, O: Out> AsRef + 'a> for dyn Content + 'a { fn as_ref (&self) -> &(dyn Layout + 'a) { self } } -/// Drawable with dynamic dispatch. -pub trait Draw { fn draw (&self, to: &mut O); } -impl Draw for () { fn draw (&self, to: &mut O) {} } -impl Draw for fn(&mut O) { fn draw (&self, to: &mut O) { (*self)(to) } } -impl Draw for Box> { fn draw (&self, to: &mut O) { (**self).draw(to) } } -impl> Draw for &D { fn draw (&self, to: &mut O) { (*self).draw(to) } } -impl> Draw for &mut D { fn draw (&self, to: &mut O) { (**self).draw(to) } } -impl> Draw for Option { fn draw (&self, to: &mut O) { if let Some(draw) = self { draw.draw(to) } } } -/// Drawable area of display. -pub trait Layout { - fn x (&self, to: O::Area) -> O::Unit { to.x() } - fn y (&self, to: O::Area) -> O::Unit { to.y() } - fn min_w (&self, to: O::Area) -> O::Unit { 0.into() } - fn max_w (&self, to: O::Area) -> O::Unit { to.w() } - fn w (&self, to: O::Area) -> O::Unit { - to.w().max(self.min_w(to)).min(self.max_w(to)) - } - fn min_h (&self, to: O::Area) -> O::Unit { 0.into() } - fn max_h (&self, to: O::Area) -> O::Unit { to.h() } - fn h (&self, to: O::Area) -> O::Unit { - to.h().max(self.min_h(to)).min(self.max_h(to)) - } - fn layout (&self, to: O::Area) -> O::Area { - [self.x(to), self.y(to), self.w(to), self.h(to)].into() - } + +impl<'a, O: Out> AsRef + 'a> for dyn Content + 'a { + fn as_ref (&self) -> &(dyn Draw + 'a) { self } } -impl Layout for () { - fn x (&self, a: O::Area) -> O::Unit { a.x() } - fn y (&self, a: O::Area) -> O::Unit { a.y() } - fn w (&self, _: O::Area) -> O::Unit { 0.into() } - fn min_w (&self, _: O::Area) -> O::Unit { 0.into() } - fn max_w (&self, _: O::Area) -> O::Unit { 0.into() } - fn h (&self, _: O::Area) -> O::Unit { 0.into() } - fn min_h (&self, _: O::Area) -> O::Unit { 0.into() } - fn max_h (&self, _: O::Area) -> O::Unit { 0.into() } - fn layout (&self, a: O::Area) -> O::Area { [a.x(), a.y(), 0.into(), 0.into()].into() } +impl<'a, O: Out> AsRef + 'a> for dyn Content + 'a { + fn as_ref (&self) -> &(dyn Layout + 'a) { self } } -impl> Layout for &L { - fn x (&self, a: O::Area) -> O::Unit { (*self).x(a) } - fn y (&self, a: O::Area) -> O::Unit { (*self).y(a) } - fn w (&self, a: O::Area) -> O::Unit { (*self).w(a) } - fn min_w (&self, a: O::Area) -> O::Unit { (*self).min_w(a) } - fn max_w (&self, a: O::Area) -> O::Unit { (*self).max_w(a) } - fn h (&self, a: O::Area) -> O::Unit { (*self).h(a) } - fn min_h (&self, a: O::Area) -> O::Unit { (*self).min_h(a) } - fn max_h (&self, a: O::Area) -> O::Unit { (*self).max_h(a) } - fn layout (&self, a: O::Area) -> O::Area { (*self).layout(a) } +pub trait HasContent { + fn content (&self) -> impl Content; } -impl> Layout for &mut L { - fn x (&self, a: O::Area) -> O::Unit { (**self).x(a) } - fn y (&self, a: O::Area) -> O::Unit { (**self).y(a) } - fn w (&self, a: O::Area) -> O::Unit { (**self).w(a) } - fn min_w (&self, a: O::Area) -> O::Unit { (**self).min_w(a) } - fn max_w (&self, a: O::Area) -> O::Unit { (**self).max_w(a) } - fn h (&self, a: O::Area) -> O::Unit { (**self).h(a) } - fn min_h (&self, a: O::Area) -> O::Unit { (**self).min_h(a) } - fn max_h (&self, a: O::Area) -> O::Unit { (**self).max_h(a) } - fn layout (&self, a: O::Area) -> O::Area { (**self).layout(a) } + +pub struct Bounded(pub O::Area, pub D); +impl> HasContent for Bounded { + fn content (&self) -> impl Content { &self.1 } } -impl Layout for Box> { - fn x (&self, a: O::Area) -> O::Unit { (**self).x(a) } - fn y (&self, a: O::Area) -> O::Unit { (**self).y(a) } - fn w (&self, a: O::Area) -> O::Unit { (**self).w(a) } - fn min_w (&self, a: O::Area) -> O::Unit { (**self).min_w(a) } - fn max_w (&self, a: O::Area) -> O::Unit { (**self).max_w(a) } - fn h (&self, a: O::Area) -> O::Unit { (**self).h(a) } - fn min_h (&self, a: O::Area) -> O::Unit { (**self).min_h(a) } - fn max_h (&self, a: O::Area) -> O::Unit { (**self).max_h(a) } - fn layout (&self, a: O::Area) -> O::Area { (**self).layout(a) } -} - -impl> Layout for Option { - fn x (&self, to: O::Area) -> O::Unit { - self.as_ref().map(|c|c.x(to)).unwrap_or(to.x()) - } - fn y (&self, to: O::Area) -> O::Unit { - self.as_ref().map(|c|c.y(to)).unwrap_or(to.y()) - } - fn min_w (&self, to: O::Area) -> O::Unit { - self.as_ref().map(|c|c.min_w(to)).unwrap_or(0.into()) - } - fn max_w (&self, to: O::Area) -> O::Unit { - self.as_ref().map(|c|c.max_w(to)).unwrap_or(0.into()) - } - fn w (&self, to: O::Area) -> O::Unit { - self.as_ref().map(|c|c.w(to)).unwrap_or(0.into()) - } - fn min_h (&self, to: O::Area) -> O::Unit { - self.as_ref().map(|c|c.min_h(to)).unwrap_or(0.into()) - } - fn max_h (&self, to: O::Area) -> O::Unit { - self.as_ref().map(|c|c.max_h(to)).unwrap_or(0.into()) - } - fn h (&self, to: O::Area) -> O::Unit { - self.as_ref().map(|c|c.h(to)).unwrap_or(0.into()) - } - fn layout (&self, to: O::Area) -> O::Area { - self.as_ref().map(|c|c.layout([self.x(to), self.y(to), self.w(to), self.h(to)].into())) - .unwrap_or([to.x(), to.y(), 0.into(), 0.into()].into()) +impl> Draw for Bounded { + fn draw (&self, to: &mut O) { + let area = to.area(); + *to.area_mut() = self.0; + self.1.draw(to); + *to.area_mut() = area; } } diff --git a/output/src/draw.rs b/output/src/draw.rs index 9826267..cfeefa5 100644 --- a/output/src/draw.rs +++ b/output/src/draw.rs @@ -1,27 +1,10 @@ use crate::*; -pub struct Bound(pub O::Area, pub D); - -impl> HasContent for Bound { - fn content (&self) -> &impl Content { &self.1 } -} - -impl Layout for Bound { - fn x (&self, _: O::Area) -> O::Unit { self.0.x() } - fn y (&self, _: O::Area) -> O::Unit { self.0.y() } - fn w (&self, _: O::Area) -> O::Unit { self.0.w() } - fn min_w (&self, _: O::Area) -> O::Unit { self.0.w() } - fn max_w (&self, _: O::Area) -> O::Unit { self.0.w() } - fn h (&self, _: O::Area) -> O::Unit { self.0.h() } - fn min_h (&self, _: O::Area) -> O::Unit { self.0.w() } - fn max_h (&self, _: O::Area) -> O::Unit { self.0.w() } -} - -impl> Draw for Bound { - fn draw (&self, to: &mut O) { - let area = to.area(); - *to.area_mut() = self.0; - self.1.draw(to); - *to.area_mut() = area; - } -} +/// Drawable with dynamic dispatch. +pub trait Draw { fn draw (&self, to: &mut O); } +impl Draw for () { fn draw (&self, to: &mut O) {} } +impl Draw for fn(&mut O) { fn draw (&self, to: &mut O) { (*self)(to) } } +impl Draw for Box> { fn draw (&self, to: &mut O) { (**self).draw(to) } } +impl> Draw for &D { fn draw (&self, to: &mut O) { (*self).draw(to) } } +impl> Draw for &mut D { fn draw (&self, to: &mut O) { (**self).draw(to) } } +impl> Draw for Option { fn draw (&self, to: &mut O) { if let Some(draw) = self { draw.draw(to) } } } diff --git a/output/src/layout.rs b/output/src/layout.rs index 85ca20a..0776da4 100644 --- a/output/src/layout.rs +++ b/output/src/layout.rs @@ -8,3 +8,101 @@ mod layout_pad; pub use self::layout_pad::*; mod layout_move; pub use self::layout_move::*; mod layout_size; pub use self::layout_size::*; mod layout_stack; //pub use self::layout_stack::*; + +/// Drawable area of display. +pub trait Layout { + fn x (&self, to: O::Area) -> O::Unit { to.x() } + fn y (&self, to: O::Area) -> O::Unit { to.y() } + fn min_w (&self, to: O::Area) -> O::Unit { 0.into() } + fn max_w (&self, to: O::Area) -> O::Unit { to.w() } + fn w (&self, to: O::Area) -> O::Unit { + to.w().max(self.min_w(to)).min(self.max_w(to)) + } + fn min_h (&self, to: O::Area) -> O::Unit { 0.into() } + fn max_h (&self, to: O::Area) -> O::Unit { to.h() } + fn h (&self, to: O::Area) -> O::Unit { + to.h().max(self.min_h(to)).min(self.max_h(to)) + } + fn layout (&self, to: O::Area) -> O::Area { + [self.x(to), self.y(to), self.w(to), self.h(to)].into() + } +} + +impl Layout for () { + fn x (&self, a: O::Area) -> O::Unit { a.x() } + fn y (&self, a: O::Area) -> O::Unit { a.y() } + fn w (&self, _: O::Area) -> O::Unit { 0.into() } + fn min_w (&self, _: O::Area) -> O::Unit { 0.into() } + fn max_w (&self, _: O::Area) -> O::Unit { 0.into() } + fn h (&self, _: O::Area) -> O::Unit { 0.into() } + fn min_h (&self, _: O::Area) -> O::Unit { 0.into() } + fn max_h (&self, _: O::Area) -> O::Unit { 0.into() } + fn layout (&self, a: O::Area) -> O::Area { [a.x(), a.y(), 0.into(), 0.into()].into() } +} + +impl> Layout for &L { + fn x (&self, a: O::Area) -> O::Unit { (*self).x(a) } + fn y (&self, a: O::Area) -> O::Unit { (*self).y(a) } + fn w (&self, a: O::Area) -> O::Unit { (*self).w(a) } + fn min_w (&self, a: O::Area) -> O::Unit { (*self).min_w(a) } + fn max_w (&self, a: O::Area) -> O::Unit { (*self).max_w(a) } + fn h (&self, a: O::Area) -> O::Unit { (*self).h(a) } + fn min_h (&self, a: O::Area) -> O::Unit { (*self).min_h(a) } + fn max_h (&self, a: O::Area) -> O::Unit { (*self).max_h(a) } + fn layout (&self, a: O::Area) -> O::Area { (*self).layout(a) } +} + +impl> Layout for &mut L { + fn x (&self, a: O::Area) -> O::Unit { (**self).x(a) } + fn y (&self, a: O::Area) -> O::Unit { (**self).y(a) } + fn w (&self, a: O::Area) -> O::Unit { (**self).w(a) } + fn min_w (&self, a: O::Area) -> O::Unit { (**self).min_w(a) } + fn max_w (&self, a: O::Area) -> O::Unit { (**self).max_w(a) } + fn h (&self, a: O::Area) -> O::Unit { (**self).h(a) } + fn min_h (&self, a: O::Area) -> O::Unit { (**self).min_h(a) } + fn max_h (&self, a: O::Area) -> O::Unit { (**self).max_h(a) } + fn layout (&self, a: O::Area) -> O::Area { (**self).layout(a) } +} + +impl Layout for Box> { + fn x (&self, a: O::Area) -> O::Unit { (**self).x(a) } + fn y (&self, a: O::Area) -> O::Unit { (**self).y(a) } + fn w (&self, a: O::Area) -> O::Unit { (**self).w(a) } + fn min_w (&self, a: O::Area) -> O::Unit { (**self).min_w(a) } + fn max_w (&self, a: O::Area) -> O::Unit { (**self).max_w(a) } + fn h (&self, a: O::Area) -> O::Unit { (**self).h(a) } + fn min_h (&self, a: O::Area) -> O::Unit { (**self).min_h(a) } + fn max_h (&self, a: O::Area) -> O::Unit { (**self).max_h(a) } + fn layout (&self, a: O::Area) -> O::Area { (**self).layout(a) } +} + +impl> Layout for Option { + fn x (&self, to: O::Area) -> O::Unit { + self.as_ref().map(|c|c.x(to)).unwrap_or(to.x()) + } + fn y (&self, to: O::Area) -> O::Unit { + self.as_ref().map(|c|c.y(to)).unwrap_or(to.y()) + } + fn min_w (&self, to: O::Area) -> O::Unit { + self.as_ref().map(|c|c.min_w(to)).unwrap_or(0.into()) + } + fn max_w (&self, to: O::Area) -> O::Unit { + self.as_ref().map(|c|c.max_w(to)).unwrap_or(0.into()) + } + fn w (&self, to: O::Area) -> O::Unit { + self.as_ref().map(|c|c.w(to)).unwrap_or(0.into()) + } + fn min_h (&self, to: O::Area) -> O::Unit { + self.as_ref().map(|c|c.min_h(to)).unwrap_or(0.into()) + } + fn max_h (&self, to: O::Area) -> O::Unit { + self.as_ref().map(|c|c.max_h(to)).unwrap_or(0.into()) + } + fn h (&self, to: O::Area) -> O::Unit { + self.as_ref().map(|c|c.h(to)).unwrap_or(0.into()) + } + fn layout (&self, to: O::Area) -> O::Area { + self.as_ref().map(|c|c.layout([self.x(to), self.y(to), self.w(to), self.h(to)].into())) + .unwrap_or([to.x(), to.y(), 0.into(), 0.into()].into()) + } +} diff --git a/output/src/layout/layout_align.rs b/output/src/layout/layout_align.rs index 6fab1b7..0ccdd20 100644 --- a/output/src/layout/layout_align.rs +++ b/output/src/layout/layout_align.rs @@ -47,7 +47,7 @@ impl Align { #[inline] pub const fn se (a: T) -> Self { Self(Alignment::SE, a) } } impl> Draw for Align { - fn draw (&self, to: &mut O) { Bound(self.layout(to.area()), &self.1).draw(to) } + fn draw (&self, to: &mut O) { Bounded(self.layout(to.area()), &self.1).draw(to) } } impl> Layout for Align { fn x (&self, to: O::Area) -> O::Unit { diff --git a/output/src/layout/layout_cond.rs b/output/src/layout/layout_cond.rs index 65ebc5b..485d5b3 100644 --- a/output/src/layout/layout_cond.rs +++ b/output/src/layout/layout_cond.rs @@ -15,7 +15,7 @@ impl> Layout for When { impl> Draw for When { fn draw (&self, to: &mut O) { let Self(cond, item, ..) = self; - if *cond { Bound(self.layout(to.area()), item).draw(to) } + if *cond { Bounded(self.layout(to.area()), item).draw(to) } } } @@ -37,7 +37,7 @@ impl, B: Content> Draw for Either { fn draw (&self, to: &mut E) { let Self(cond, a, b, ..) = self; let area = self.layout(to.area()); - if *cond { Bound(area, a).draw(to) } else { Bound(area, b).draw(to) } + if *cond { Bounded(area, a).draw(to) } else { Bounded(area, b).draw(to) } } } diff --git a/output/src/layout/layout_move.rs b/output/src/layout/layout_move.rs index 163d2e3..c634cc3 100644 --- a/output/src/layout/layout_move.rs +++ b/output/src/layout/layout_move.rs @@ -9,7 +9,7 @@ impl Push { #[inline] pub fn dy (&self) -> U { match self { Self::Y(y, ..) | Self::XY(_, y, _) => *y, Self::X(_, _) => 0.into() } } } impl> Draw for Push { - fn draw (&self, to: &mut O) { Bound(self.layout(to.area()), self.inner()).draw(to) } + fn draw (&self, to: &mut O) { Bounded(self.layout(to.area()), self.inner()).draw(to) } } impl> Layout for Push { fn x (&self, area: O::Area) -> O::Unit { area.x().plus(self.dx()) } @@ -25,7 +25,7 @@ impl Pull { #[inline] pub fn dy (&self) -> U { match self { Self::Y(y, ..) | Self::XY(_, y, _) => *y, Self::X(_, _) => 0.into() } } } impl> Draw for Pull { - fn draw (&self, to: &mut O) { Bound(self.layout(to.area()), self.inner()).draw(to) } + fn draw (&self, to: &mut O) { Bounded(self.layout(to.area()), self.inner()).draw(to) } } impl> Layout for Pull { fn x (&self, area: O::Area) -> O::Unit { area.x().minus(self.dx()) } diff --git a/output/src/layout/layout_pad.rs b/output/src/layout/layout_pad.rs index 0570c23..b625ef8 100644 --- a/output/src/layout/layout_pad.rs +++ b/output/src/layout/layout_pad.rs @@ -9,7 +9,7 @@ impl Pad { #[inline] pub fn dy (&self) -> U { match self { X(_, _) => 0.into(), Y(y, _) => *y, XY(_, y, _) => *y, } } } impl> Draw for Pad { - fn draw (&self, to: &mut O) { Bound(self.layout(to.area()), self.inner()).draw(to) } + fn draw (&self, to: &mut O) { Bounded(self.layout(to.area()), self.inner()).draw(to) } } impl> Layout for Pad { fn x (&self, area: O::Area) -> O::Unit { diff --git a/output/src/layout/layout_size.rs b/output/src/layout/layout_size.rs index a9d4932..6ef5f7c 100644 --- a/output/src/layout/layout_size.rs +++ b/output/src/layout/layout_size.rs @@ -7,7 +7,7 @@ impl Fill { #[inline] pub const fn dy (&self) -> bool { match self { Self::Y(_) | Self::XY(_) => true, _ => false } } } impl> Draw for Fill { - fn draw (&self, to: &mut O) { Bound(self.layout(to.area()), self.inner()).draw(to) } + fn draw (&self, to: &mut O) { Bounded(self.layout(to.area()), self.inner()).draw(to) } } impl> Layout for Fill { fn x (&self, area: O::Area) -> O::Unit { if self.dx() { area.x() } else { self.inner().x(area) } } @@ -29,7 +29,7 @@ impl Fixed { #[inline] pub const fn dy (&self) -> Option { match self { Self::Y(y, _) | Self::XY(y, ..) => Some(*y), _ => None } } } impl> Draw for Fixed { - fn draw (&self, to: &mut O) { Bound(self.layout(to.area()), self.inner()).draw(to) } + fn draw (&self, to: &mut O) { Bounded(self.layout(to.area()), self.inner()).draw(to) } } impl> Layout for Fixed { fn w (&self, area: O::Area) -> O::Unit { self.dx().unwrap_or(self.inner().w(area)) } @@ -49,7 +49,7 @@ impl Max { #[inline] pub const fn dy (&self) -> Option { match self { Self::Y(y, _) | Self::XY(y, ..) => Some(*y), _ => None } } } impl> Draw for Max { - fn draw (&self, to: &mut O) { Bound(self.layout(to.area()), self.inner()).draw(to) } + fn draw (&self, to: &mut O) { Bounded(self.layout(to.area()), self.inner()).draw(to) } } impl> Layout for Max { fn layout (&self, area: E::Area) -> E::Area { @@ -71,7 +71,7 @@ impl Min { #[inline] pub const fn dy (&self) -> Option { match self { Self::Y(y, _) | Self::XY(y, ..) => Some(*y), _ => None } } } impl> Draw for Min { - fn draw (&self, to: &mut O) { Bound(self.layout(to.area()), self.inner()).draw(to) } + fn draw (&self, to: &mut O) { Bounded(self.layout(to.area()), self.inner()).draw(to) } } impl> Layout for Min { fn layout (&self, area: E::Area) -> E::Area { @@ -93,7 +93,7 @@ impl Expand { #[inline] pub const fn dy (&self) -> Option { match self { Self::Y(y, _) | Self::XY(y, ..) => Some(*y), _ => None } } } impl> Draw for Expand { - fn draw (&self, to: &mut O) { Bound(self.layout(to.area()), self.inner()).draw(to) } + fn draw (&self, to: &mut O) { Bounded(self.layout(to.area()), self.inner()).draw(to) } } impl> Layout for Expand { fn w (&self, to: O::Area) -> O::Unit { self.inner().w(to).plus(self.dx().unwrap_or_default()) } @@ -109,7 +109,7 @@ impl Shrink { #[inline] pub const fn dy (&self) -> Option { match self { Self::Y(y, _) | Self::XY(y, ..) => Some(*y), _ => None } } } impl> Draw for Shrink { - fn draw (&self, to: &mut O) { Bound(self.layout(to.area()), self.inner()).draw(to) } + fn draw (&self, to: &mut O) { Bounded(self.layout(to.area()), self.inner()).draw(to) } } impl> Layout for Shrink { fn layout (&self, to: E::Area) -> E::Area { diff --git a/output/src/output.rs b/output/src/output.rs index 6a32109..5da748f 100644 --- a/output/src/output.rs +++ b/output/src/output.rs @@ -7,6 +7,7 @@ #![feature(const_option_ops)] #![feature(const_trait_impl)] #![feature(const_default)] +#![feature(trait_alias)] //#![feature(non_lifetime_binders)] pub(crate) use self::Direction::*; diff --git a/output/src/space/space_measure.rs b/output/src/space/space_measure.rs index f508554..b785bdb 100644 --- a/output/src/space/space_measure.rs +++ b/output/src/space/space_measure.rs @@ -2,28 +2,30 @@ use crate::*; /// A widget that tracks its render width and height #[derive(Default)] -pub struct Measure { - _engine: PhantomData, +pub struct Measure { + _engine: PhantomData, pub x: Arc, pub y: Arc, } -impl PartialEq for Measure { +impl PartialEq for Measure { fn eq (&self, other: &Self) -> bool { self.x.load(Relaxed) == other.x.load(Relaxed) && self.y.load(Relaxed) == other.y.load(Relaxed) } } +impl Layout for Measure {} + // TODO: 🡘 🡙 ←🡙→ indicator to expand window when too small -impl Draw for Measure { - fn draw (&self, to: &mut E) { +impl Draw for Measure { + fn draw (&self, to: &mut O) { self.x.store(to.area().w().into(), Relaxed); self.y.store(to.area().h().into(), Relaxed); } } -impl Clone for Measure { +impl Clone for Measure { fn clone (&self) -> Self { Self { _engine: Default::default(), @@ -33,7 +35,7 @@ impl Clone for Measure { } } -impl std::fmt::Debug for Measure { +impl std::fmt::Debug for Measure { fn fmt (&self, f: &mut std::fmt::Formatter<'_>) -> std::result::Result<(), std::fmt::Error> { f.debug_struct("Measure") .field("width", &self.x) @@ -42,7 +44,7 @@ impl std::fmt::Debug for Measure { } } -impl Measure { +impl Measure { pub fn new () -> Self { Self { _engine: PhantomData::default(), @@ -75,7 +77,7 @@ impl Measure { pub fn format (&self) -> Arc { format!("{}x{}", self.w(), self.h()).into() } - pub fn of > (&self, item: T) -> Bsp, T> { + pub fn of > (&self, item: T) -> Bsp, T> { Bsp::b(Fill::XY(self), item) } } diff --git a/tui/src/tui.rs b/tui/src/tui.rs index c54a44e..853d99d 100644 --- a/tui/src/tui.rs +++ b/tui/src/tui.rs @@ -1,4 +1,5 @@ #![feature(type_changing_struct_update)] +#![feature(trait_alias)] #[cfg(test)] mod tui_test; mod tui_engine; pub use self::tui_engine::*; mod tui_content; pub use self::tui_content::*; diff --git a/tui/src/tui_content/tui_field.rs b/tui/src/tui_content/tui_field.rs index 833a082..38ecb2d 100644 --- a/tui/src/tui_content/tui_field.rs +++ b/tui/src/tui_content/tui_field.rs @@ -1,5 +1,12 @@ use crate::*; +impl Draw for FieldH { + fn draw (&self, to: &mut TuiOut) { to.place(&self.content()) } +} +impl Draw for FieldV { + fn draw (&self, to: &mut TuiOut) { to.place(&self.content()) } +} + // TODO: pub struct Field { pub direction: Direction, diff --git a/tui/src/tui_engine.rs b/tui/src/tui_engine.rs index 8ca21e4..4fce13a 100644 --- a/tui/src/tui_engine.rs +++ b/tui/src/tui_engine.rs @@ -73,12 +73,18 @@ impl Tui { } } -pub trait TuiRun + Handle + 'static> { +pub trait TuiDraw = Draw; +pub trait TuiLayout = Layout; +pub trait TuiContent = Content; +pub trait TuiHandle = Handle; +pub trait TuiWidget = TuiDraw + TuiHandle; + +pub trait TuiRun { /// Run an app in the main loop. - fn run (&self, state: &Arc>) -> Usually<()>; + fn run (&self, state: &Arc>) -> Usually<()>; } -impl + Handle + Send + Sync + 'static> TuiRun for Arc> { +impl TuiRun for Arc> { fn run (&self, state: &Arc>) -> Usually<()> { let _input_thread = TuiIn::run_input(self, state, Duration::from_millis(100)); self.write().unwrap().setup()?;