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();

View file

@ -99,6 +99,11 @@ impl ArrangerViewMode {
}
}
}
impl Layout<Tui> for Arranger<Tui> {
fn layout (&self, area: [u16;4]) -> Perhaps<[u16;4]> {
todo!()
}
}
/// Render arranger to terminal
impl Render<Tui> for Arranger<Tui> {
fn render (&self, to: &mut Tui) -> Perhaps<[u16;4]> {

View file

@ -1,5 +1,10 @@
use crate::*;
impl Layout<Tui> for Sequencer {
fn layout (&self, area: [u16;4]) -> Perhaps<[u16;4]> {
todo!()
}
}
impl<'a> Render<Tui> for Sequencer {
fn render (&self, to: &mut Tui) -> Perhaps<[u16;4]> {
self.horizontal_draw(to)?;

View file

@ -5,19 +5,16 @@ impl Sequencer {
const H_KEYS_OFFSET: usize = 5;
pub(crate) fn horizontal_draw <'a> (&self, to: &mut Tui) -> Usually<()> {
let mut area = to.area();
let area = to.area();
Split::down()
.add_ref(&SequenceName(&self))
.add_ref(&SequenceRange)
.add_ref(&SequenceLoopRange)
.add_ref(&SequenceNoteRange)
.render(to.with_area(area.x(), area.y(), area.h(), 10))?;
area.x = area.x() + 10;
area.width = area.w().saturating_sub(10);
area.height = area.h().min(66);
.render(to.with_area(area.x(), area.y(), 10, area.h()))?;
let area = [area.x() + 10, area.y(), area.w().saturating_sub(10), area.h().min(66)];
Lozenge(Style::default().fg(Nord::BG2)).draw(to.with_rect(area))?;
area.x = area.x() + 1;
area.width = area.w().saturating_sub(1);
let area = [area.x() + 1, area.y(), area.w().saturating_sub(1), area.h()];
Layered::new()
.add_ref(&SequenceKeys(&self))
.add_ref(&self.phrase.as_ref().map(|phrase|SequenceTimer(&self, phrase.clone())))

View file

@ -2,22 +2,21 @@ use crate::*;
const CORNERS: Corners = Corners(NOT_DIM_GREEN);
impl Layout<Tui> for TransportToolbar {
fn layout (&self, area: [u16;4]) -> Perhaps<[u16;4]> {
Ok(Some([area.x(), area.y(), area.w(), 2]))
}
}
impl Render<Tui> for TransportToolbar {
fn render (&self, to: &mut Tui) -> Perhaps<[u16;4]> {
let area = to.area();
let area = [area.x(), area.y(), area.w(), 2];
let area = Split::right()
Split::right()
.add_ref(&self.playing)
.add_ref(&self.bpm)
.add_ref(&self.quant)
.add_ref(&self.sync)
.add_ref(&self.clock)
.render(to.with_rect(area))?;
//if self.is_focused() {
//fill_bg(buf, area, COLOR_BG0);
//CORNERS_DIM.draw(buf, area)?;
//}
Ok(area)
.render(to.with_rect(self.layout(to.area())?.unwrap()))
}
}