diff --git a/src/control.rs b/src/control.rs index 42c41e00..3e107813 100644 --- a/src/control.rs +++ b/src/control.rs @@ -1,10 +1,7 @@ -pub mod focus; pub mod mixer; pub mod plugin; pub mod sampler; -pub use self::focus::*; - use crate::{core::*, handle, App, AppSection}; handle!(App |self, e| { diff --git a/src/control/focus.rs b/src/control/focus.rs deleted file mode 100644 index 82a7d935..00000000 --- a/src/control/focus.rs +++ /dev/null @@ -1,189 +0,0 @@ -use crate::{core::*, view::*}; - -pub trait Focus { - fn unfocus (&mut self); - fn focused (&self) -> Option<&Box>; - fn focused_mut (&mut self) -> Option<&mut Box>; - fn handle_focus (&mut self, event: &FocusEvent) -> Usually; -} - -pub enum FocusEvent { Forward, Backward, Inward, Outward, } - -pub fn handle_focus ( - state: &mut T, - event: &AppEvent, - keymap: &[KeyBinding] -) -> Usually { - let handled = if let Some(focused) = state.focused_mut() { - focused.handle(event) - } else { - Ok(false) - }; - return Ok(handled? || handle_keymap( - state, event, keymap - )?) -} - -pub struct FocusColumn(pub Option, pub Column); - -impl Handle for FocusColumn { - fn handle (&mut self, event: &AppEvent) -> Usually { - handle_focus(self, event, KEYMAP_FOCUS_COLUMN) - } -} - -impl Render for FocusColumn { - fn render (&self, buf: &mut Buffer, area: Rect) -> Usually { - let (rect, _rects) = Column::draw(buf, area, self.1.0.as_ref(), 0)?; - //if i == self.focus { - //if self.focused { - //draw_box_styled(buf, result, Some(Style::default().white().not_dim())) - //} else { - //draw_box_styled_dotted(buf, result, Some(Style::default().white().dim())) - //}; - //}; - Ok(rect) - } -} - -const KEYMAP_FOCUS_COLUMN: &'static [KeyBinding] = keymap!(FocusColumn { - [Up, NONE, "focus_up", "focus row above", - |s: &mut FocusColumn|s.handle_focus(&FocusEvent::Backward)], - [Down, NONE, "focus_down", "focus row below", - |s: &mut FocusColumn|s.handle_focus(&FocusEvent::Forward)], - [Enter, NONE, "focus_down", "focus row below", - |s: &mut FocusColumn|s.handle_focus(&FocusEvent::Inward)], - [Esc, NONE, "focus_down", "focus row below", - |s: &mut FocusColumn|s.handle_focus(&FocusEvent::Outward)] -}); - -impl Focus for FocusColumn { - fn unfocus (&mut self) { - self.0 = None - } - fn focused (&self) -> Option<&Box> { - self.0.map(|index|self.1.0.get(index))? - } - fn focused_mut (&mut self) -> Option<&mut Box> { - self.0.map(|index|self.1.0.get_mut(index))? - } - fn handle_focus (&mut self, event: &FocusEvent) -> Usually { - Ok(match event { - FocusEvent::Backward => match self.0 { - Some(i) => { - self.0 = Some(if i == 0 { - self.1.0.len() - 1 - } else { - i - 1 - }); - true - }, - _ => false - }, - FocusEvent::Forward => match self.0 { - Some(i) => { - self.0 = Some(if i >= self.1.0.len() { - 0 - } else { - i + 1 - }); - true - }, - _ => false - }, - FocusEvent::Inward => match self.0 { - None => { - self.0 = Some(0); - true - }, - _ => false - }, - FocusEvent::Outward => match self.0 { - Some(_i) => { - self.0 = None; - true - }, - _ => false - }, - }) - } -} - -pub struct FocusRow(pub Option, pub Row); - -impl Handle for FocusRow { - fn handle (&mut self, event: &AppEvent) -> Usually { - handle_focus(self, event, KEYMAP_FOCUS_ROW) - } -} - -impl Render for FocusRow { - fn render (&self, buf: &mut Buffer, area: Rect) -> Usually { - let (rect, _rects) = Row::draw(buf, area, &self.1.0, 0)?; - Ok(rect) - } -} - -const KEYMAP_FOCUS_ROW: &'static [KeyBinding] = keymap!(FocusRow { - [Left, NONE, "focus_up", "focus row above", - |s: &mut FocusRow|s.handle_focus(&FocusEvent::Backward)], - [Right, NONE, "focus_down", "focus row below", - |s: &mut FocusRow|s.handle_focus(&FocusEvent::Forward)], - [Enter, NONE, "focus_down", "focus row below", - |s: &mut FocusRow|s.handle_focus(&FocusEvent::Inward)], - [Esc, NONE, "focus_down", "focus row below", - |s: &mut FocusRow|s.handle_focus(&FocusEvent::Outward)] -}); - -impl Focus for FocusRow { - fn unfocus (&mut self) { - self.0 = None - } - fn focused (&self) -> Option<&Box> { - self.0.map(|index|self.1.0.get(index))? - } - fn focused_mut (&mut self) -> Option<&mut Box> { - self.0.map(|index|self.1.0.get_mut(index))? - } - fn handle_focus (&mut self, event: &FocusEvent) -> Usually { - Ok(match event { - FocusEvent::Backward => match self.0 { - Some(i) => { - self.0 = Some(if i == 0 { - self.1.0.len() - 1 - } else { - i - 1 - }); - true - }, - _ => false - }, - FocusEvent::Forward => match self.0 { - Some(i) => { - self.0 = Some(if i >= self.1.0.len() { - 0 - } else { - i + 1 - }); - true - }, - _ => false - }, - FocusEvent::Inward => match self.0 { - None => { - self.0 = Some(0); - true - }, - _ => false - }, - FocusEvent::Outward => match self.0 { - Some(_i) => { - self.0 = None; - true - }, - _ => false - }, - }) - } -} - diff --git a/src/view.rs b/src/view.rs index 1457f0c6..9df999d4 100644 --- a/src/view.rs +++ b/src/view.rs @@ -19,14 +19,15 @@ pub use self::sequencer::SequencerView; use crate::{render, App, AppSection, core::*}; render!(App |self, buf, area| { + let track = self.track_cursor; Split::down([ &TransportView::new(self), &Split::down([ &ArrangerView::new(&self, !self.arranger_mode), - &Split::down([ + &If(track > 0, &Split::right([ + &ChainView::vertical(&self), &SequencerView::new(&self), - &ChainView::new(&self, false) - ]) + ])) ]) ]).render(buf, area)?; if let Some(ref modal) = self.modal { diff --git a/src/view/border.rs b/src/view/border.rs index 3e0e6c33..25c1a973 100644 --- a/src/view/border.rs +++ b/src/view/border.rs @@ -128,3 +128,36 @@ pub fn lozenge_right (buf: &mut Buffer, x: u16, y1: u16, h: u16, style: Option Rect { + draw_box_styled(buffer, area, Some(Style::default().gray().dim())) +} + +pub fn draw_box_styled (buffer: &mut Buffer, area: Rect, style: Option