errors fixed, renders nothing :(

This commit is contained in:
🪞👃🪞 2024-09-07 18:43:24 +03:00
parent b3f0f60400
commit 4cca03352a
9 changed files with 47 additions and 44 deletions

View file

@ -13,12 +13,11 @@ impl<'a, E: Engine> Render<E> for Collected<'a, E> {
}
}
}
impl<'a, E: Engine> Layout<E> for &Collected<'a, E> {
impl<'a, E: Engine> Layout<E> for Collected<'a, E> {
fn layout (&self, area: E::Area) -> Perhaps<E::Area> {
match *self {
Collected::Box(inner) => (*inner).layout(area),
Collected::Ref(inner) => (*inner).layout(area),
match self {
Self::Box(inner) => (*inner).layout(area),
Self::Ref(inner) => (*inner).layout(area),
}
}
}

View file

@ -14,6 +14,21 @@ pub fn center_box (area: Rect, w: u16, h: u16) -> Rect {
pub trait Layout<E: Engine>: Render<E> {
fn layout (&self, area: E::Area) -> Perhaps<E::Area>;
}
impl<E: Engine, T: Layout<E>> Layout<E> for &T {
fn layout (&self, area: E::Area) -> Perhaps<E::Area> {
(*self).layout(area)
}
}
impl<E: Engine, T: Layout<E>> Layout<E> for Option<T> {
fn layout (&self, area: E::Area) -> Perhaps<E::Area> {
match self {
Some(layout) => layout.layout(area),
None => Ok(None)
}
}
}
/// Enforce minimum size of drawing area
pub enum Min<U: Number, L> { W(U, L), H(U, L), WH(U, U, L), }
/// Enforce maximum size of drawing area

View file

@ -5,6 +5,12 @@ pub trait Render<E: Engine>: Send + Sync {
fn render (&self, to: &mut E) -> Perhaps<E::Rendered>;
}
impl<E: Engine> Render<E> for () {
fn render (&self, to: &mut E) -> Perhaps<E::Rendered> {
Ok(None)
}
}
/// Options can be rendered optionally.
impl<R, E: Engine> Render<E> for Option<R> where R: Render<E> {
fn render (&self, to: &mut E) -> Perhaps<E::Rendered> {

View file

@ -198,20 +198,6 @@ pub enum TuiEvent {
// Jack(JackEvent)
}
/// Rendering unit struct to Ratatui returns zero-sized [Area] at render coordinates.
impl Render<Tui> for () {
fn render (&self, to: &mut Tui) -> Perhaps<[u16;4]> {
self.layout(to.area())
}
}
/// Layout of unit struct in Ratatui is zero-sized [Area] at render coordinates.
impl Layout<Tui> for () {
fn layout (&self, area: [u16;4]) -> Perhaps<[u16;4]> {
Ok(Some([area.x(), area.y(), 0, 0]))
}
}
impl Area<u16> for Rect {
fn x (&self) -> u16 { self.x }
fn y (&self) -> u16 { self.y }

View file

@ -1,14 +1,5 @@
use crate::*;
impl<T: Layout<Tui>> Layout<Tui> for Option<T> {
fn layout (&self, area: [u16;4]) -> Perhaps<[u16;4]> {
match self {
Some(layout) => layout.layout(area),
None => ().layout(area)
}
}
}
impl<'a> Render<Tui> for Layers<'a, Tui> {
fn render (&self, to: &mut Tui) -> Perhaps<[u16;4]> {
let area = to.area();