mirror of
https://codeberg.org/unspeaker/tek.git
synced 2025-12-08 12:46:42 +01:00
add focus proxy for sequencers
This commit is contained in:
parent
47cdf5869b
commit
4be2df1347
2 changed files with 71 additions and 17 deletions
|
|
@ -48,7 +48,8 @@ impl ArrangerCli {
|
||||||
transport,
|
transport,
|
||||||
show_sequencer: Some(tek_core::Direction::Down),
|
show_sequencer: Some(tek_core::Direction::Down),
|
||||||
arranger,
|
arranger,
|
||||||
focus: 0
|
focus: 0,
|
||||||
|
sequencer_proxy: SequencerProxy(Default::default(), false)
|
||||||
})))?;
|
})))?;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
@ -61,8 +62,26 @@ struct ArrangerStandalone<E: Engine> {
|
||||||
arranger: Arranger<E>,
|
arranger: Arranger<E>,
|
||||||
/// This allows the sequencer view to be moved or hidden.
|
/// This allows the sequencer view to be moved or hidden.
|
||||||
show_sequencer: Option<tek_core::Direction>,
|
show_sequencer: Option<tek_core::Direction>,
|
||||||
///
|
/// Index of currently focused component
|
||||||
focus: usize,
|
focus: usize,
|
||||||
|
/// Focus target that passes events down to sequencer
|
||||||
|
sequencer_proxy: SequencerProxy<E>,
|
||||||
|
}
|
||||||
|
impl<E: Engine> ArrangerStandalone<E> {
|
||||||
|
fn sequencer (&self) -> Option<&Sequencer<E>> {
|
||||||
|
if self.show_sequencer.is_some() {
|
||||||
|
self.arranger.sequencer()
|
||||||
|
} else {
|
||||||
|
None
|
||||||
|
}
|
||||||
|
}
|
||||||
|
fn sequencer_mut (&mut self) -> Option<&mut Sequencer<E>> {
|
||||||
|
if self.show_sequencer.is_some() {
|
||||||
|
self.arranger.sequencer_mut()
|
||||||
|
} else {
|
||||||
|
None
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
/// The standalone arranger consists of transport, clip grid, and sequencer.
|
/// The standalone arranger consists of transport, clip grid, and sequencer.
|
||||||
impl Content for ArrangerStandalone<Tui> {
|
impl Content for ArrangerStandalone<Tui> {
|
||||||
|
|
@ -94,6 +113,16 @@ impl Content for ArrangerStandalone<Tui> {
|
||||||
/// Handle top-level events in standalone arranger.
|
/// Handle top-level events in standalone arranger.
|
||||||
impl Handle<Tui> for ArrangerStandalone<Tui> {
|
impl Handle<Tui> for ArrangerStandalone<Tui> {
|
||||||
fn handle (&mut self, from: &TuiInput) -> Perhaps<bool> {
|
fn handle (&mut self, from: &TuiInput) -> Perhaps<bool> {
|
||||||
|
let focus = self.focus;
|
||||||
|
let is_first_row = self.arranger.is_first_row();
|
||||||
|
let is_last_row = self.arranger.is_last_row();
|
||||||
|
let mut focused_handle = || {
|
||||||
|
if focus == 2 {
|
||||||
|
self.arranger.sequencer_mut().handle(from)
|
||||||
|
} else {
|
||||||
|
self.focused_mut().handle(from)
|
||||||
|
}
|
||||||
|
};
|
||||||
match from.event() {
|
match from.event() {
|
||||||
key!(KeyCode::Char(' ')) => {
|
key!(KeyCode::Char(' ')) => {
|
||||||
if let Some(ref mut transport) = self.transport {
|
if let Some(ref mut transport) = self.transport {
|
||||||
|
|
@ -109,38 +138,55 @@ impl Handle<Tui> for ArrangerStandalone<Tui> {
|
||||||
self.focus_prev();
|
self.focus_prev();
|
||||||
},
|
},
|
||||||
key!(KeyCode::Down) => {
|
key!(KeyCode::Down) => {
|
||||||
if self.focus == 0 {
|
if focus == 0 {
|
||||||
self.focus_next();
|
self.focus_next();
|
||||||
} else if self.focus == 1 && self.arranger.is_last_row() {
|
} else if focus == 1 && is_last_row {
|
||||||
self.focus_next();
|
self.focus_next();
|
||||||
} else {
|
} else {
|
||||||
return self.focused_mut().handle(from)
|
return focused_handle()
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
key!(KeyCode::Up) => {
|
key!(KeyCode::Up) => {
|
||||||
if self.focus == 1 && self.arranger.is_first_row() {
|
if focus == 1 && is_first_row {
|
||||||
self.focus_prev();
|
self.focus_prev();
|
||||||
} else {
|
} else {
|
||||||
return self.focused_mut().handle(from)
|
return focused_handle()
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
_ => return self.focused_mut().handle(from)
|
_ => return focused_handle()
|
||||||
}
|
}
|
||||||
Ok(Some(true))
|
Ok(Some(true))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/// Focusable items in standalone arranger.
|
/// Focusable items in standalone arranger.
|
||||||
impl Focus<2, Tui> for ArrangerStandalone<Tui> {
|
impl Focus<3, Tui> for ArrangerStandalone<Tui> {
|
||||||
fn focus (&self) -> usize {
|
fn focus (&self) -> usize {
|
||||||
self.focus
|
self.focus
|
||||||
}
|
}
|
||||||
fn focus_mut (&mut self) -> &mut usize {
|
fn focus_mut (&mut self) -> &mut usize {
|
||||||
&mut self.focus
|
&mut self.focus
|
||||||
}
|
}
|
||||||
fn focusable (&self) -> [&dyn Focusable<Tui>;2] {
|
fn focusable (&self) -> [&dyn Focusable<Tui>;3] {
|
||||||
focusables!(self.transport, self.arranger)
|
focusables!(self.transport, self.arranger, self.sequencer_proxy)
|
||||||
}
|
}
|
||||||
fn focusable_mut (&mut self) -> [&mut dyn Focusable<Tui>;2] {
|
fn focusable_mut (&mut self) -> [&mut dyn Focusable<Tui>;3] {
|
||||||
focusables_mut!(self.transport, self.arranger)
|
focusables_mut!(self.transport, self.arranger, self.sequencer_proxy)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#[derive(Default)]
|
||||||
|
struct SequencerProxy<E: Engine>(PhantomData<E>, bool);
|
||||||
|
impl Handle<Tui> for SequencerProxy<Tui> {
|
||||||
|
fn handle (&mut self, _: &TuiInput) -> Perhaps<bool> { unreachable!() }
|
||||||
|
}
|
||||||
|
impl Content for SequencerProxy<Tui> {
|
||||||
|
type Engine = Tui;
|
||||||
|
fn content (&self) -> impl Widget<Engine = Tui> { "" }
|
||||||
|
}
|
||||||
|
impl Focusable<Tui> for SequencerProxy<Tui> {
|
||||||
|
fn is_focused (&self) -> bool {
|
||||||
|
self.1
|
||||||
|
}
|
||||||
|
fn set_focused (&mut self, focus: bool) {
|
||||||
|
self.1 = focus
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -885,6 +885,14 @@ impl Content for Sequencer<Tui> {
|
||||||
.fg(Color::Rgb(70, 80, 50))))
|
.fg(Color::Rgb(70, 80, 50))))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
impl Focusable<Tui> for Sequencer<Tui> {
|
||||||
|
fn is_focused (&self) -> bool {
|
||||||
|
self.focused
|
||||||
|
}
|
||||||
|
fn set_focused (&mut self, focused: bool) {
|
||||||
|
self.focused = focused
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// Colors of piano keys
|
/// Colors of piano keys
|
||||||
const KEY_COLORS: [(Color, Color);6] = [
|
const KEY_COLORS: [(Color, Color);6] = [
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue