diff --git a/crates/tek_core/src/render.rs b/crates/tek_core/src/render.rs index b58a1c35..4e09170f 100644 --- a/crates/tek_core/src/render.rs +++ b/crates/tek_core/src/render.rs @@ -111,18 +111,6 @@ impl<'a> Render for Box { } } -//impl<'a, T: Fn(&mut Buffer, Rect) -> Usually + Send + Sync + 'a> Render for T { - //fn render (&self, b: &mut Buffer, a: Rect) -> Usually { - //(*self)(b, a) - //} -//} - -impl<'a> Render for Box Usually + Send + Sync + 'a> { - fn render (&self, b: &mut Buffer, a: Rect) -> Usually { - (*self)(b, a) - } -} - impl Render for Arc { fn render (&self, b: &mut Buffer, a: Rect) -> Usually { self.as_ref().render(b, a) @@ -141,6 +129,18 @@ impl Render for RwLock { } } +//impl<'a, T: Fn(&mut Buffer, Rect) -> Usually + Send + Sync + 'a> Render for T { + //fn render (&self, b: &mut Buffer, a: Rect) -> Usually { + //(*self)(b, a) + //} +//} + +impl<'a> Render for Box Usually + Send + Sync + 'a> { + fn render (&self, b: &mut Buffer, a: Rect) -> Usually { + (*self)(b, a) + } +} + pub fn center_box (area: Rect, w: u16, h: u16) -> Rect { let width = w.min(area.width * 3 / 5); let height = h.min(area.width * 3 / 5); diff --git a/crates/tek_core/src/render_collect.rs b/crates/tek_core/src/render_collect.rs index f1c2a00f..b0fa85cd 100644 --- a/crates/tek_core/src/render_collect.rs +++ b/crates/tek_core/src/render_collect.rs @@ -27,7 +27,9 @@ impl<'a> Collection<'a> { pub trait Collect<'a> { fn add_box (self, item: Box) -> Self; fn add_ref (self, item: &'a dyn Render) -> Self; - fn add (self, item: T) -> Self where Self: Sized { + fn add (self, item: T) -> Self + where Self: Sized + { self.add_box(Box::new(item)) } } diff --git a/crates/tek_core/src/render_split.rs b/crates/tek_core/src/render_split.rs index 6c9f7741..72b29f7f 100644 --- a/crates/tek_core/src/render_split.rs +++ b/crates/tek_core/src/render_split.rs @@ -9,12 +9,6 @@ pub enum Direction { } impl Direction { - //pub fn split <'a, const N: usize> (&self, items: [&'a (dyn Render + Sync);N]) -> Split<'a, N> { - //Split(*self, items) - //} - pub fn split_focus <'a> (&self, index: usize, items: Renderables<'a>, style: Style) -> SplitFocus<'a> { - SplitFocus(*self, index, items, style) - } pub fn is_down (&self) -> bool { match self { Self::Down => true, _ => false } } @@ -23,27 +17,39 @@ impl Direction { } } -pub struct Split<'a>(Collection<'a>, Direction); +pub struct Split<'a> { + items: Collection<'a>, + direction: Direction, + focus: Option +} impl<'a> Split<'a> { pub fn new (direction: Direction) -> Self { - Self(Collection::new(), direction) + Self { + items: Collection::new(), + direction, + focus: None + } } pub fn down () -> Self { - Self(Collection::new(), Direction::Down) + Self::new(Direction::Down) } pub fn right () -> Self { - Self(Collection::new(), Direction::Right) + Self::new(Direction::Right) + } + pub fn focus (mut self, focus: Option) -> Self { + self.focus = focus; + self } pub fn render_areas (&self, buf: &mut Buffer, area: Rect) -> Usually<(Rect, Vec)> { let Rect { mut x, mut y, mut width, mut height } = area; let mut areas = vec![]; - for item in self.0.0.iter() { + for (index, item) in self.items.0.iter().enumerate() { if width == 0 || height == 0 { break } let result = item.render(buf, Rect { x, y, width, height })?; - match self.1 { + match self.direction { Direction::Down => { y += result.height; height = height.saturating_sub(result.height); @@ -54,7 +60,10 @@ impl<'a> Split<'a> { }, _ => unimplemented!() }; - areas.push(area); + areas.push(result); + if self.focus == Some(index) { + Corners(Style::default().green().not_dim()).draw(buf, result)?; + } } Ok((area, areas)) } @@ -68,91 +77,11 @@ impl<'a> Render for Split<'a> { impl<'a> Collect<'a> for Split<'a> { fn add_box (mut self, item: Box) -> Self { - self.0 = self.0.add_box(item); + self.items = self.items.add_box(item); self } fn add_ref (mut self, item: &'a dyn Render) -> Self { - self.0 = self.0.add_ref(item); + self.items = self.items.add_ref(item); self } } - -//pub struct Split<'a, const N: usize>( - //pub Direction, pub [&'a (dyn Render + Sync);N] -//); - -//impl<'a, const N: usize> Split<'a, N> { - //pub fn down (items: [&'a (dyn Render + Sync);N]) -> Self { - //Self(Direction::Down, items) - //} - //pub fn right (items: [&'a (dyn Render + Sync);N]) -> Self { - //Self(Direction::Right, items) - //} - //pub fn render_areas (&self, buf: &mut Buffer, area: Rect) -> Usually<(Rect, Vec)> { - //let Rect { mut x, mut y, mut width, mut height } = area; - //let mut areas = vec![]; - //for item in self.1 { - //if width == 0 || height == 0 { - //break - //} - //let result = item.render(buf, Rect { x, y, width, height })?; - //match self.0 { - //Direction::Down => { - //y = y + result.height; - //height = height.saturating_sub(result.height); - //}, - //Direction::Right => { - //x = x + result.width; - //width = width.saturating_sub(result.width); - //}, - //_ => unimplemented!() - //}; - //areas.push(area); - //} - //Ok((area, areas)) - //} -//} - -//impl<'a, const N: usize> Render for Split<'a, N> { - //fn render (&self, buf: &mut Buffer, area: Rect) -> Usually { - //Ok(self.render_areas(buf, area)?.0) - //} -//} - -type Renderables<'a> = &'a [&'a (dyn Render + Send + Sync)]; - -pub struct SplitFocus<'a>(pub Direction, pub usize, pub Renderables<'a>, pub Style); - -impl<'a> SplitFocus<'a> { - pub fn render_areas (&self, buf: &mut Buffer, area: Rect) -> Usually<(Rect, Vec)> { - let Rect { mut x, mut y, mut width, mut height } = area; - let mut areas = vec![]; - for item in self.2.iter() { - if width == 0 || height == 0 { - break - } - let result = item.render(buf, Rect { x, y, width, height })?; - areas.push(result); - match self.0 { - Direction::Down => { - y += result.height; - height = height.saturating_sub(result.height); - }, - Direction::Right => { - x += result.width; - width = width.saturating_sub(result.width); - }, - _ => unimplemented!() - } - Lozenge(self.3).draw(buf, result)?; - } - Ok((area, areas)) - } -} - -impl<'a> Render for SplitFocus<'a> { - fn render (&self, buf: &mut Buffer, area: Rect) -> Usually { - Ok(self.render_areas(buf, area)?.0) - } -} - diff --git a/crates/tek_mixer/src/track_view.rs b/crates/tek_mixer/src/track_view.rs index 1b9d01c7..dc944dbe 100644 --- a/crates/tek_mixer/src/track_view.rs +++ b/crates/tek_mixer/src/track_view.rs @@ -37,17 +37,11 @@ impl<'a> Render for TrackView<'a> { _ => { unimplemented!() }, } fill_bg(buf, area, Nord::bg_lo(self.focused, self.entered)); - let devices: Vec<&(dyn Render + Send + Sync)> = chain.devices.as_slice() - .iter() - .map(|d|d as &(dyn Render + Send + Sync)) - .collect(); - let (area, areas) = self.direction - .split_focus(0, devices.as_slice(), if self.focused { - Style::default().green().dim() - } else { - Style::default().dim() - }) - .render_areas(buf, area)?; + let mut split = Split::new(self.direction); + for device in chain.devices.as_slice().iter() { + split = split.add_ref(device); + } + let (area, areas) = split.render_areas(buf, area)?; if self.focused && self.entered && areas.len() > 0 { Corners(Style::default().green().not_dim()).draw(buf, areas[0])?; } diff --git a/crates/tek_sequencer/src/arranger_main.rs b/crates/tek_sequencer/src/arranger_main.rs index 5b29faf0..b6f33838 100644 --- a/crates/tek_sequencer/src/arranger_main.rs +++ b/crates/tek_sequencer/src/arranger_main.rs @@ -15,7 +15,7 @@ struct ArrangerStandalone { /// This allows the sequencer view to be moved or hidden. show_sequencer: Option, /// - focus: usize, + focus: usize, } impl ArrangerStandalone { @@ -23,7 +23,7 @@ impl ArrangerStandalone { self.focus = if self.focus > 0 { 1 } else { self.focus - 1 }; } fn focus_next (&mut self) { - self.focus = if self.focus < 2 { self.focus + 1 } else { 0 }; + self.focus = if self.focus < 1 { self.focus + 1 } else { 0 }; } fn focused (&self) -> &dyn Render { self.focusable()[self.focus] @@ -107,6 +107,7 @@ impl Render for ArrangerStandalone { .add_ref(&self.transport) .add_ref(&self.arranger) .add_ref(&sequencer) + .focus(Some(self.focus)) .render(buf, area)?; if let Some(ref modal) = self.arranger.modal { fill_bg(buf, area, Nord::bg_lo(false, false));