diff --git a/Cargo.lock b/Cargo.lock index 7a54f8de..996ad770 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2544,26 +2544,16 @@ dependencies = [ "suil-rs", "symphonia", "tek_core", - "tek_proc", "vst", "wavers", "winit", ] -[[package]] -name = "tek_proc" -version = "0.1.0" -dependencies = [ - "quote", - "syn 2.0.77", -] - [[package]] name = "tek_sequencer" version = "0.1.0" dependencies = [ "tek_core", - "tek_proc", ] [[package]] diff --git a/crates/tek_core/examples/demo.rs b/crates/tek_core/examples/demo.rs index 6d81dede..d0711e9c 100644 --- a/crates/tek_core/examples/demo.rs +++ b/crates/tek_core/examples/demo.rs @@ -36,26 +36,30 @@ impl Demo { impl Content for Demo { type Engine = Tui; fn content (&self) -> impl Widget { - Align::Center(Layers::new(|add|{ + let border_style = Style::default().fg(Color::Rgb(0,0,0)); + Align::Center(Layers::new(move|add|{ add(&Background(Color::Rgb(0,128,128)))?; add(&Outset::XY(1, 1, Split::down(|add|{ add(&Layers::new(|add|{ - add(&Background(Color::Rgb(255,255,0)))?; + add(&Background(Color::Rgb(128,96,0)))?; + add(&Border(Square(border_style)))?; add(&Outset::XY(2, 1, "..."))?; Ok(()) }))?; add(&Layers::new(|add|{ - add(&Background(Color::Rgb(255,128,0)))?; + add(&Background(Color::Rgb(128,64,0)))?; + add(&Border(Lozenge(border_style)))?; add(&Outset::XY(4, 2, "---"))?; Ok(()) }))?; add(&Layers::new(|add|{ - add(&Background(Color::Rgb(128,128,0)))?; + add(&Background(Color::Rgb(96,64,0)))?; + add(&Border(SquareBold(border_style)))?; add(&Outset::XY(6, 3, "~~~"))?; Ok(()) }))?; diff --git a/crates/tek_core/src/space.rs b/crates/tek_core/src/space.rs index 2d21e87b..706926d5 100644 --- a/crates/tek_core/src/space.rs +++ b/crates/tek_core/src/space.rs @@ -22,8 +22,8 @@ pub trait Area: Copy { fn y (&self) -> N; fn w (&self) -> N; fn h (&self) -> N; - fn x2 (&self) -> N { self.x() + self.w() } - fn y2 (&self) -> N { self.y() + self.h() } + fn x2 (&self) -> N { self.x() + self.w() - 1.into() } + fn y2 (&self) -> N { self.y() + self.h() - 1.into() } fn xywh (&self) -> [N;4] { [self.x(), self.y(), self.w(), self.h()] } diff --git a/crates/tek_core/src/tui.rs b/crates/tek_core/src/tui.rs index 01e82bc7..f7afaa7c 100644 --- a/crates/tek_core/src/tui.rs +++ b/crates/tek_core/src/tui.rs @@ -619,21 +619,35 @@ impl> Widget for Outset { }.render(to) } } -//impl> Content for Outset { - //type Engine = Tui; - //fn content (&self) -> impl Widget { - //match *self { - //Self::X(x, ref inner) => - //Grow::X(x + x, inner as &dyn Widget), - //Self::Y(y, ref inner) => - //Grow::Y(y + y, inner as &dyn Widget), - //Self::XY(x, y, ref inner) => - //Grow::XY(x, y, inner as &dyn Widget), - //} - //} -//} -pub trait BorderStyle { +pub struct Border(pub S); + +impl Widget for Border { + type Engine = Tui; + fn layout (&self, to: [u16;4]) -> Perhaps<[u16;4]> { + Outset::XY(1, 1, "").layout(to) + } + fn render (&self, to: &mut Tui) -> Perhaps<[u16;4]> { + let area = to.area(); + if area.w() > 2 && area.y() > 2 { + to.blit(&self.0.nw(), area.x(), area.y(), self.0.style())?; + to.blit(&self.0.ne(), area.x() + area.w() - 1, area.y(), self.0.style())?; + to.blit(&self.0.sw(), area.x(), area.y() + area.h() - 1, self.0.style())?; + to.blit(&self.0.se(), area.x() + area.w() - 1, area.y() + area.h() - 1, self.0.style())?; + for x in area.x()+1..area.x()+area.w()-1 { + to.blit(&self.0.n(), x, area.y(), self.0.style())?; + to.blit(&self.0.s(), x, area.y() + area.h() - 1, self.0.style())?; + } + for y in area.y()+1..area.y()+area.h()-1 { + to.blit(&self.0.w(), area.x(), y, self.0.style())?; + to.blit(&self.0.e(), area.x() + area.w() - 1, y, self.0.style())?; + } + } + Ok(Some(area)) + } +} + +pub trait BorderStyle: Send + Sync { const NW: &'static str = ""; const N: &'static str = ""; const NE: &'static str = ""; @@ -643,6 +657,31 @@ pub trait BorderStyle { const SW: &'static str = ""; const W: &'static str = ""; + fn n (&self) -> &str { + Self::N + } + fn s (&self) -> &str { + Self::S + } + fn e (&self) -> &str { + Self::E + } + fn w (&self) -> &str { + Self::W + } + fn nw (&self) -> &str { + Self::NW + } + fn ne (&self) -> &str { + Self::NE + } + fn sw (&self) -> &str { + Self::SW + } + fn se (&self) -> &str { + Self::SE + } + #[inline] fn draw <'a> (&self, to: &mut Tui) -> Perhaps<[u16;4]> { self.draw_horizontal(to, None)?; @@ -743,8 +782,11 @@ macro_rules! border { )+} } +pub struct Square(pub Style); +pub struct SquareBold(pub Style); +pub struct Tab(pub Style); pub struct Lozenge(pub Style); -pub struct LozengeV(pub Style); +pub struct Brace(pub Style); pub struct LozengeDotted(pub Style); pub struct Quarter(pub Style); pub struct QuarterV(pub Style); @@ -752,6 +794,30 @@ pub struct Chamfer(pub Style); pub struct Corners(pub Style); border! { + Square { + "┌" "─" "┐" + "│" "│" + "└" "─" "┘" + fn style (&self) -> Option