From 2352b72377439c7cb0944ec14aadf9d16853cffd Mon Sep 17 00:00:00 2001 From: unspeaker Date: Tue, 17 Sep 2024 00:38:22 +0300 Subject: [PATCH] generalize Fixed and bring back some more of the arranger --- crates/tek_core/src/space.rs | 22 ++++++++++- crates/tek_core/src/tui.rs | 23 +---------- crates/tek_sequencer/src/arranger.rs | 56 +++++++++++++-------------- crates/tek_sequencer/src/transport.rs | 2 +- 4 files changed, 51 insertions(+), 52 deletions(-) diff --git a/crates/tek_core/src/space.rs b/crates/tek_core/src/space.rs index 4120fe18..cf8de063 100644 --- a/crates/tek_core/src/space.rs +++ b/crates/tek_core/src/space.rs @@ -298,12 +298,32 @@ pub enum Fixed { /// Enforce fixed width and height XY(U, U, T), } - impl Fixed { pub fn inner (&self) -> &T { match self { Self::X(_, i) => i, Self::Y(_, i) => i, Self::XY(_, _, i) => i, } } } +impl> Widget for Fixed { + type Engine = E; + fn layout (&self, to: E::Size) -> Perhaps { + Ok(match self { + Self::X(w, _) => + if to.w() >= *w { Some([*w, to.h()].into()) } else { None }, + Self::Y(h, _) => + if to.h() >= *h { Some([to.w(), *h].into()) } else { None }, + Self::XY(w, h, _) + => if to.w() >= *w && to.h() >= *h { Some([*w, *h].into()) } else { None }, + }) + } + fn render (&self, to: &mut E::Output) -> Usually<()> { + // 🡘 🡙 ←🡙→ + if let Some(size) = self.layout(to.area().wh().into())? { + to.render_in(to.area().clip(size).into(), self.inner()) + } else { + Ok(()) + } + } +} /// Enforce minimum size of drawing area pub enum Min { diff --git a/crates/tek_core/src/tui.rs b/crates/tek_core/src/tui.rs index 59cb0c88..463b05c8 100644 --- a/crates/tek_core/src/tui.rs +++ b/crates/tek_core/src/tui.rs @@ -282,7 +282,7 @@ impl Widget for &str { type Engine = Tui; fn layout (&self, _: [u16;2]) -> Perhaps<[u16;2]> { // TODO: line breaks - Ok(Some([self.len() as u16, 1])) + Ok(Some([self.chars().count() as u16, 1])) } fn render (&self, to: &mut TuiOutput) -> Usually<()> { let [x, y, ..] = to.area(); @@ -296,7 +296,7 @@ pub struct Styled>(pub Option