diff --git a/crates/tek_layout/src/layers.rs b/crates/tek_layout/src/layers.rs index 0269a727..ddf2382c 100644 --- a/crates/tek_layout/src/layers.rs +++ b/crates/tek_layout/src/layers.rs @@ -1,9 +1,5 @@ use crate::*; -#[macro_export] macro_rules! lay { - ($($expr:expr),* $(,)?) => { Layers::new(move|add|{ $(add(&$expr)?;)* Ok(()) }) } -} - pub struct Layers< E: Engine, F: Send + Sync + Fn(&mut dyn FnMut(&dyn Render)->Usually<()>)->Usually<()> diff --git a/crates/tek_layout/src/lib.rs b/crates/tek_layout/src/lib.rs index 81497eb3..2e7806a4 100644 --- a/crates/tek_layout/src/lib.rs +++ b/crates/tek_layout/src/lib.rs @@ -8,11 +8,47 @@ submod! { fixed grow inset + layers max + measure min outset pull push + scroll shrink split + stack +} + +#[macro_export] macro_rules! lay { + ($($expr:expr),* $(,)?) => { Layers::new(move|add|{ $(add(&$expr)?;)* Ok(()) }) } +} + +#[macro_export] macro_rules! col { + ($($expr:expr),* $(,)?) => { Stack::down(move|add|{ $(add(&$expr)?;)* Ok(()) }) }; + ($pat:pat in $collection:expr => $item:expr) => { + Stack::down(move |add|{ + for $pat in $collection { add(&$item)?; } + Ok(()) + }) + } +} +#[macro_export] macro_rules! col_up { + ($($expr:expr),* $(,)?) => { Stack::down(move|add|{ $(add(&$expr)?;)* Ok(()) }) }; + ($pat:pat in $collection:expr => $item:expr) => { + Stack::up(move |add|{ + for $pat in $collection { add(&$item)?; } + Ok(()) + }) + } +} +#[macro_export] macro_rules! row { + ($($expr:expr),* $(,)?) => { Stack::right(move|add|{ $(add(&$expr)?;)* Ok(()) }) }; + ($pat:pat in $collection:expr => $item:expr) => { + Stack::right(move |add|{ + for $pat in $collection { add(&$item)?; } + Ok(()) + }) + } } diff --git a/crates/tek_layout/src/max.rs b/crates/tek_layout/src/max.rs index e0d36928..7939264c 100644 --- a/crates/tek_layout/src/max.rs +++ b/crates/tek_layout/src/max.rs @@ -1,5 +1,7 @@ use crate::*; +impl> LayoutMax for W {} + pub trait LayoutMax: Render + Sized { fn max_x (self, x: E::Unit) -> Max { Max::X(x, self) } fn max_y (self, y: E::Unit) -> Max { Max::Y(y, self) } diff --git a/crates/tek_layout/src/min.rs b/crates/tek_layout/src/min.rs index 299ecbb1..2cba806c 100644 --- a/crates/tek_layout/src/min.rs +++ b/crates/tek_layout/src/min.rs @@ -1,5 +1,7 @@ use crate::*; +impl> LayoutMin for W {} + pub trait LayoutMin: Render + Sized { fn min_x (self, x: E::Unit) -> Min { Min::X(x, self) } fn min_y (self, y: E::Unit) -> Min { Min::Y(y, self) } diff --git a/crates/tek_layout/src/stack.rs b/crates/tek_layout/src/stack.rs index 82c6e46e..d2b6f285 100644 --- a/crates/tek_layout/src/stack.rs +++ b/crates/tek_layout/src/stack.rs @@ -1,33 +1,5 @@ use crate::*; -#[macro_export] macro_rules! col { - ($($expr:expr),* $(,)?) => { Stack::down(move|add|{ $(add(&$expr)?;)* Ok(()) }) }; - ($pat:pat in $collection:expr => $item:expr) => { - Stack::down(move |add|{ - for $pat in $collection { add(&$item)?; } - Ok(()) - }) - } -} -#[macro_export] macro_rules! col_up { - ($($expr:expr),* $(,)?) => { Stack::down(move|add|{ $(add(&$expr)?;)* Ok(()) }) }; - ($pat:pat in $collection:expr => $item:expr) => { - Stack::up(move |add|{ - for $pat in $collection { add(&$item)?; } - Ok(()) - }) - } -} -#[macro_export] macro_rules! row { - ($($expr:expr),* $(,)?) => { Stack::right(move|add|{ $(add(&$expr)?;)* Ok(()) }) }; - ($pat:pat in $collection:expr => $item:expr) => { - Stack::right(move |add|{ - for $pat in $collection { add(&$item)?; } - Ok(()) - }) - } -} - pub struct Stack< E: Engine, F: Send + Sync + Fn(&mut dyn FnMut(&dyn Render)->Usually<()>)->Usually<()> diff --git a/crates/tek_tui/src/lib.rs b/crates/tek_tui/src/lib.rs index 45849006..7ef99545 100644 --- a/crates/tek_tui/src/lib.rs +++ b/crates/tek_tui/src/lib.rs @@ -1,6 +1,7 @@ pub(crate) use crossterm::event::{KeyCode, KeyModifiers}; pub(crate) use tek_core::midly::{num::u7, live::LiveEvent, MidiMessage}; pub(crate) use tek_core::{*, jack::*}; +pub(crate) use tek_layout::*; pub(crate) use tek_api::*; pub(crate) use std::collections::BTreeMap; @@ -81,8 +82,8 @@ impl TuiTheme { } pub trait FocusWrap { - fn wrap <'a, W: Render> (self, focus: T, content: &'a W) - -> impl Render + 'a; + fn wrap <'a, W: Render> (self, focus: T, content: &'a W) + -> impl Render + 'a; } pub fn to_focus_command (input: &TuiInput) -> Option { @@ -145,12 +146,12 @@ pub fn to_focus_command (input: &TuiInput) -> Option { } } -pub trait StatusBar: Render { +pub trait StatusBar: Render { type State: Send + Sync; fn hotkey_fg () -> Color where Self: Sized; fn update (&mut self, state: &Self::State) where Self: Sized; - fn command (commands: &[[impl Render;3]]) - -> impl Render + '_ + fn command (commands: &[[impl Render;3]]) + -> impl Render + '_ where Self: Sized { @@ -167,7 +168,7 @@ pub trait StatusBar: Render { }) } - fn with <'a> (state: &'a Self::State, content: impl Render) -> impl Render + fn with <'a> (state: &'a Self::State, content: impl Render) -> impl Render where Self: Sized, &'a Self::State: Into { Stack::up(move |add|{ @@ -181,9 +182,9 @@ fn content_with_menu_and_status <'a, A, S, C> ( content: &'a A, menu_bar: &'a Option>, status_bar: &'a Option -) -> impl Render + 'a +) -> impl Render + 'a where - A: Render, + A: Render, S: Send + Sync + 'a, C: Command { diff --git a/crates/tek_tui/src/todo_tui_mixer.rs b/crates/tek_tui/src/todo_tui_mixer.rs index 5112819a..c8203770 100644 --- a/crates/tek_tui/src/todo_tui_mixer.rs +++ b/crates/tek_tui/src/todo_tui_mixer.rs @@ -95,8 +95,7 @@ pub struct TrackView<'a, E: Engine> { pub entered: bool, } -impl<'a> Render for TrackView<'a, Tui> { - type Engine = Tui; +impl<'a> Render for TrackView<'a, Tui> { fn min_size (&self, area: [u16;2]) -> Perhaps<[u16;2]> { todo!() } @@ -130,9 +129,8 @@ impl<'a> Render for TrackView<'a, Tui> { } } -impl Content for Mixer { - type Engine = Tui; - fn content (&self) -> impl Render { +impl Content for Mixer { + fn content (&self) -> impl Render { Stack::right(|add| { for channel in self.tracks.iter() { add(channel)?; @@ -142,9 +140,8 @@ impl Content for Mixer { } } -impl Content for Track { - type Engine = Tui; - fn content (&self) -> impl Render { +impl Content for Track { + fn content (&self) -> impl Render { TrackView { chain: Some(&self), direction: tek_core::Direction::Right, diff --git a/crates/tek_tui/src/todo_tui_plugin.rs b/crates/tek_tui/src/todo_tui_plugin.rs index 999a486a..54cf0704 100644 --- a/crates/tek_tui/src/todo_tui_plugin.rs +++ b/crates/tek_tui/src/todo_tui_plugin.rs @@ -31,8 +31,7 @@ impl Plugin { }) } } -impl Render for Plugin { - type Engine = Tui; +impl Render for Plugin { fn min_size (&self, to: [u16;2]) -> Perhaps<[u16;2]> { Ok(Some(to)) } diff --git a/crates/tek_tui/src/todo_tui_sampler.rs b/crates/tek_tui/src/todo_tui_sampler.rs index d39dfe81..791144dc 100644 --- a/crates/tek_tui/src/todo_tui_sampler.rs +++ b/crates/tek_tui/src/todo_tui_sampler.rs @@ -316,8 +316,7 @@ impl Sample { } } -impl Render for SamplerView { - type Engine = Tui; +impl Render for SamplerView { fn min_size (&self, to: [u16;2]) -> Perhaps<[u16;2]> { todo!() } @@ -371,8 +370,7 @@ fn draw_sample ( Ok(label1.len() + label2.len() + 4) } -impl Render for AddSampleModal { - type Engine = Tui; +impl Render for AddSampleModal { fn min_size (&self, to: [u16;2]) -> Perhaps<[u16;2]> { todo!() //Align::Center(()).layout(to) diff --git a/crates/tek_tui/src/tui_app_arranger.rs b/crates/tek_tui/src/tui_app_arranger.rs index 7045151b..9155f9cf 100644 --- a/crates/tek_tui/src/tui_app_arranger.rs +++ b/crates/tek_tui/src/tui_app_arranger.rs @@ -152,9 +152,8 @@ impl StatusBar for ArrangerStatus { } } -impl Content for ArrangerStatus { - type Engine = Tui; - fn content (&self) -> impl Render { +impl Content for ArrangerStatus { + fn content (&self) -> impl Render { let label = match self { Self::Transport => "TRANSPORT", Self::ArrangerMix => "PROJECT", diff --git a/crates/tek_tui/src/tui_app_transport.rs b/crates/tek_tui/src/tui_app_transport.rs index 46f14e0e..3c689839 100644 --- a/crates/tek_tui/src/tui_app_transport.rs +++ b/crates/tek_tui/src/tui_app_transport.rs @@ -50,8 +50,8 @@ pub enum TransportFocus { } impl FocusWrap for TransportFocus { - fn wrap <'a, W: Render> (self, focus: TransportFocus, content: &'a W) - -> impl Render + 'a + fn wrap <'a, W: Render> (self, focus: TransportFocus, content: &'a W) + -> impl Render + 'a { let focused = focus == self; let corners = focused.then_some(CORNERS); @@ -61,8 +61,8 @@ impl FocusWrap for TransportFocus { } impl FocusWrap for Option { - fn wrap <'a, W: Render> (self, focus: TransportFocus, content: &'a W) - -> impl Render + 'a + fn wrap <'a, W: Render> (self, focus: TransportFocus, content: &'a W) + -> impl Render + 'a { let focused = Some(focus) == self; let corners = focused.then_some(CORNERS); @@ -95,9 +95,8 @@ impl StatusBar for TransportStatusBar { } } -impl Content for TransportStatusBar { - type Engine = Tui; - fn content (&self) -> impl Render { +impl Content for TransportStatusBar { + fn content (&self) -> impl Render { todo!(); "" } diff --git a/crates/tek_tui/src/tui_engine_output.rs b/crates/tek_tui/src/tui_engine_output.rs index 27249810..70021358 100644 --- a/crates/tek_tui/src/tui_engine_output.rs +++ b/crates/tek_tui/src/tui_engine_output.rs @@ -11,7 +11,7 @@ impl Output for TuiOutput { #[inline] fn area_mut (&mut self) -> &mut [u16;4] { &mut self.area } #[inline] fn render_in (&mut self, area: [u16;4], - widget: &dyn Render + widget: &dyn Render ) -> Usually<()> { let last = self.area(); *self.area_mut() = area; @@ -124,8 +124,8 @@ pub fn buffer_update (buf: &mut Buffer, area: [u16;4], callback: &impl Fn(&mut C } } } -//impl Render for &str { - //type Engine = Tui; +//impl Render for &str { + //type Tui; //fn min_size (&self, _: [u16;2]) -> Perhaps<[u16;2]> { //// TODO: line breaks //Ok(Some([self.chars().count() as u16, 1])) @@ -136,8 +136,8 @@ pub fn buffer_update (buf: &mut Buffer, area: [u16;4], callback: &impl Fn(&mut C //Ok(to.blit(&self, x, y, None)) //} //} -//impl Render for String { - //type Engine = Tui; +//impl Render for String { + //type Tui; //fn min_size (&self, _: [u16;2]) -> Perhaps<[u16;2]> { //// TODO: line breaks //Ok(Some([self.chars().count() as u16, 1])) @@ -148,8 +148,8 @@ pub fn buffer_update (buf: &mut Buffer, area: [u16;4], callback: &impl Fn(&mut C //Ok(to.blit(&self, x, y, None)) //} //} -//impl> Render for DebugOverlay { - //type Engine = Tui; +//impl> Render for DebugOverlay { + //type Tui; //fn min_size (&self, to: [u16;2]) -> Perhaps<[u16;2]> { //self.0.min_size(to) //} diff --git a/crates/tek_tui/src/tui_engine_style.rs b/crates/tek_tui/src/tui_engine_style.rs index 9caa3d68..bd287daf 100644 --- a/crates/tek_tui/src/tui_engine_style.rs +++ b/crates/tek_tui/src/tui_engine_style.rs @@ -1,7 +1,8 @@ use crate::*; -pub struct Styled>(pub Option