mirror of
https://codeberg.org/unspeaker/tek.git
synced 2025-12-07 04:06:45 +01:00
what is up with the Focus trait again
This commit is contained in:
parent
e7f2284e5e
commit
deaa66d6e2
1 changed files with 50 additions and 34 deletions
|
|
@ -7,9 +7,9 @@ pub fn main () -> Usually<()> {
|
|||
Ok(())
|
||||
}
|
||||
|
||||
struct ArrangerStandalone {
|
||||
struct ArrangerStandalone<E: Engine> {
|
||||
/// Contains all the sequencers.
|
||||
arranger: Arranger,
|
||||
arranger: Arranger<E>,
|
||||
/// Controls the JACK transport.
|
||||
transport: Option<TransportToolbar>,
|
||||
/// This allows the sequencer view to be moved or hidden.
|
||||
|
|
@ -18,8 +18,6 @@ struct ArrangerStandalone {
|
|||
focus: usize,
|
||||
}
|
||||
|
||||
focus!(ArrangerStandalone (focus) : 2 => [ transport, arranger ]);
|
||||
|
||||
#[derive(Debug, Parser)]
|
||||
#[command(version, about, long_about = None)]
|
||||
pub struct ArrangerCli {
|
||||
|
|
@ -40,7 +38,7 @@ pub struct ArrangerCli {
|
|||
scenes: usize,
|
||||
}
|
||||
|
||||
impl ArrangerStandalone {
|
||||
impl<E: Engine> ArrangerStandalone<E> {
|
||||
pub fn from_args () -> Usually<Self> {
|
||||
let args = ArrangerCli::parse();
|
||||
let mut arranger = Arranger::new("");
|
||||
|
|
@ -75,7 +73,7 @@ impl ArrangerStandalone {
|
|||
}
|
||||
}
|
||||
|
||||
impl Render<Tui> for ArrangerStandalone {
|
||||
impl Render<Tui> for ArrangerStandalone<Tui> {
|
||||
fn render (&self, to: &mut Tui) -> Perhaps<Rect> {
|
||||
let area = to.area();
|
||||
let sequencer = self.arranger.sequencer();
|
||||
|
|
@ -94,55 +92,73 @@ impl Render<Tui> for ArrangerStandalone {
|
|||
}
|
||||
}
|
||||
|
||||
impl Handle<Tui> for ArrangerStandalone {
|
||||
fn handle (&mut self, e: &AppEvent) -> Usually<bool> {
|
||||
match e {
|
||||
AppEvent::Input(Event::Key(KeyEvent { code: KeyCode::Char(' '), .. })) => {
|
||||
impl Handle<Tui> for ArrangerStandalone<Tui> {
|
||||
fn handle (&mut self, from: &Tui) -> Perhaps<bool> {
|
||||
match from.event() {
|
||||
key!(KeyCode::Char(' ')) => {
|
||||
if let Some(ref mut transport) = self.transport {
|
||||
transport.toggle_play()?;
|
||||
Ok(true)
|
||||
Ok(Some(true))
|
||||
} else {
|
||||
Ok(false)
|
||||
Ok(None)
|
||||
}
|
||||
},
|
||||
AppEvent::Input(Event::Key(KeyEvent { code: KeyCode::Tab, .. })) => {
|
||||
self.focus_next();
|
||||
Ok(true)
|
||||
key!(KeyCode::Tab) => {
|
||||
self.arranger.focus_next();
|
||||
Ok(Some(true))
|
||||
},
|
||||
AppEvent::Input(Event::Key(KeyEvent { code: KeyCode::BackTab, .. })) => {
|
||||
self.focus_prev();
|
||||
Ok(true)
|
||||
key!(KeyCode::BackTab) => {
|
||||
self.arranger.focus_prev();
|
||||
Ok(Some(true))
|
||||
},
|
||||
AppEvent::Input(Event::Key(KeyEvent { code: KeyCode::Down, .. })) => {
|
||||
key!(KeyCode::Down) => {
|
||||
if self.focus == 0 || (
|
||||
self.focus == 1 && self.arranger.is_last_row()
|
||||
) {
|
||||
self.focus_next();
|
||||
Ok(true)
|
||||
self.arranger.focus_next();
|
||||
Ok(Some(true))
|
||||
} else {
|
||||
self.focused_mut().handle(e)
|
||||
self.arranger.focused_mut().handle(from)
|
||||
}
|
||||
},
|
||||
AppEvent::Input(Event::Key(KeyEvent { code: KeyCode::Up, .. })) => {
|
||||
key!(KeyCode::Up) => {
|
||||
if self.focus == 1 && self.arranger.is_first_row() {
|
||||
self.focus_prev();
|
||||
Ok(true)
|
||||
self.arranger.focus_prev();
|
||||
Ok(Some(true))
|
||||
} else {
|
||||
self.focused_mut().handle(e)
|
||||
self.arranger.focused_mut().handle(from)
|
||||
}
|
||||
},
|
||||
_ => self.focused_mut().handle(e)
|
||||
_ => self.arranger.focused_mut().handle(from)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
struct SequencerProxy(Arc<RwLock<Arranger>>);
|
||||
struct SequencerProxy<E: Engine>(Arc<RwLock<Arranger<E>>>);
|
||||
|
||||
impl Handle for SequencerProxy {
|
||||
fn handle (&mut self, e: &AppEvent) -> Usually<bool> {
|
||||
match self.0.write().unwrap().sequencer_mut() {
|
||||
Some(sequencer) => sequencer.handle(e),
|
||||
None => Ok(false)
|
||||
}
|
||||
impl Handle<Tui> for SequencerProxy<Tui> {
|
||||
fn handle (&mut self, from: &Tui) -> Perhaps<bool> {
|
||||
self.0.write().unwrap().handle(from)
|
||||
}
|
||||
}
|
||||
|
||||
impl Focus<2, E: Engine> for ArrangerStandalone<E> {
|
||||
fn focus (&self) -> usize {
|
||||
self.focus
|
||||
}
|
||||
fn focus_mut (&mut self) -> &mut usize {
|
||||
&mut self.focus
|
||||
}
|
||||
fn focusable (&self) -> [&dyn Focusable<E>;2] {
|
||||
[
|
||||
&self.transport as &dyn Focusable<E>,
|
||||
&self.arranger as &dyn Focusable<E>,
|
||||
]
|
||||
}
|
||||
fn focusable_mut (&mut self) -> [&mut dyn Focusable<E>;2] {
|
||||
[
|
||||
&mut self.transport as &mut dyn Focusable<E>,
|
||||
&mut self.arranger as &mut dyn Focusable<E>,
|
||||
]
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue