mirror of
https://codeberg.org/unspeaker/tek.git
synced 2025-12-06 19:56:42 +01:00
cmdsys: handle entered areas
This commit is contained in:
parent
31c1db8a5c
commit
1085826849
4 changed files with 65 additions and 24 deletions
|
|
@ -6,12 +6,15 @@ pub trait FocusGrid {
|
|||
fn cursor (&self) -> (usize, usize);
|
||||
fn cursor_mut (&mut self) -> &mut (usize, usize);
|
||||
fn update_focus (&mut self) {}
|
||||
fn focused (&self) -> &Self::Item {
|
||||
fn focus_enter (&mut self) {}
|
||||
fn focus_exit (&mut self) {}
|
||||
fn entered (&self) -> Option<Self::Item>;
|
||||
fn focused (&self) -> Self::Item {
|
||||
let (x, y) = self.cursor();
|
||||
&self.layout()[y][x]
|
||||
self.layout()[y][x]
|
||||
}
|
||||
fn focus (&mut self, target: Self::Item) {
|
||||
while self.focused() != &target {
|
||||
while self.focused() != target {
|
||||
self.focus_next()
|
||||
}
|
||||
}
|
||||
|
|
@ -50,7 +53,7 @@ pub trait FocusGrid {
|
|||
self.update_focus();
|
||||
}
|
||||
fn focus_next (&mut self) {
|
||||
let current = *self.focused();
|
||||
let current = self.focused();
|
||||
let (x, y) = self.cursor();
|
||||
if x < self.layout()[y].len().saturating_sub(1) {
|
||||
self.focus_right();
|
||||
|
|
@ -58,13 +61,13 @@ pub trait FocusGrid {
|
|||
self.focus_down();
|
||||
self.cursor_mut().0 = 0;
|
||||
}
|
||||
if *self.focused() == current { // FIXME: prevent infinite loop
|
||||
if self.focused() == current { // FIXME: prevent infinite loop
|
||||
self.focus_next()
|
||||
}
|
||||
self.update_focus();
|
||||
}
|
||||
fn focus_prev (&mut self) {
|
||||
let current = *self.focused();
|
||||
let current = self.focused();
|
||||
let (x, _) = self.cursor();
|
||||
if x > 0 {
|
||||
self.focus_left();
|
||||
|
|
@ -74,13 +77,11 @@ pub trait FocusGrid {
|
|||
let next_x = self.layout()[y].len().saturating_sub(1);
|
||||
self.cursor_mut().0 = next_x;
|
||||
}
|
||||
if *self.focused() == current { // FIXME: prevent infinite loop
|
||||
if self.focused() == current { // FIXME: prevent infinite loop
|
||||
self.focus_prev()
|
||||
}
|
||||
self.update_focus();
|
||||
}
|
||||
fn focus_enter (&mut self) {}
|
||||
fn focus_exit (&mut self) {}
|
||||
}
|
||||
|
||||
#[derive(Clone, PartialEq)]
|
||||
|
|
|
|||
|
|
@ -274,10 +274,32 @@ impl<E: Engine> FocusGrid for Arranger<E> {
|
|||
type Item = ArrangerFocus;
|
||||
fn cursor (&self) -> (usize, usize) { self.focus_cursor }
|
||||
fn cursor_mut (&mut self) -> &mut (usize, usize) { &mut self.focus_cursor }
|
||||
fn focus_enter (&mut self) { self.entered = true }
|
||||
fn focus_exit (&mut self) { self.entered = false }
|
||||
fn focus_enter (&mut self) {
|
||||
let focused = self.focused();
|
||||
if !self.entered {
|
||||
self.entered = true;
|
||||
use ArrangerFocus::*;
|
||||
if let Some(transport) = self.transport.as_ref() {
|
||||
//transport.write().unwrap().entered = focused == Transport
|
||||
}
|
||||
self.arrangement.entered = focused == Arrangement;
|
||||
//self.phrases.write().unwrap().entered = focused == PhrasePool;
|
||||
self.editor.entered = focused == PhraseEditor;
|
||||
}
|
||||
}
|
||||
fn focus_exit (&mut self) {
|
||||
if self.entered {
|
||||
self.entered = false;
|
||||
self.arrangement.entered = false;
|
||||
self.editor.entered = false;
|
||||
}
|
||||
}
|
||||
fn entered (&self) -> Option<ArrangerFocus> {
|
||||
if self.entered { Some(self.focused()) } else { None }
|
||||
if self.entered {
|
||||
Some(self.focused())
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
fn layout (&self) -> &[&[ArrangerFocus]] {
|
||||
use ArrangerFocus::*;
|
||||
|
|
@ -288,17 +310,14 @@ impl<E: Engine> FocusGrid for Arranger<E> {
|
|||
]
|
||||
}
|
||||
fn update_focus (&mut self) {
|
||||
use ArrangerFocus::*;
|
||||
let focused = self.focused();
|
||||
if let Some(transport) = self.transport.as_ref() {
|
||||
transport.write().unwrap().focused =
|
||||
focused == ArrangerFocus::Transport
|
||||
transport.write().unwrap().focused = focused == Transport
|
||||
}
|
||||
self.arrangement.focused =
|
||||
focused == ArrangerFocus::Arrangement;
|
||||
self.phrases.write().unwrap().focused =
|
||||
focused == ArrangerFocus::PhrasePool;
|
||||
self.editor.focused =
|
||||
focused == ArrangerFocus::PhraseEditor;
|
||||
self.arrangement.focused = focused == Arrangement;
|
||||
self.phrases.write().unwrap().focused = focused == PhrasePool;
|
||||
self.editor.focused = focused == PhraseEditor;
|
||||
self.update_status();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -526,8 +526,19 @@ impl<'a> Content for HorizontalArranger<'a, Tui> {
|
|||
}
|
||||
/// Handle top-level events in standalone arranger.
|
||||
impl Handle<Tui> for Arranger<Tui> {
|
||||
fn handle (&mut self, from: &TuiInput) -> Perhaps<bool> {
|
||||
Ok(if let Some(command) = ArrangerCommand::match_input(self, from) {
|
||||
fn handle (&mut self, i: &TuiInput) -> Perhaps<bool> {
|
||||
if let Some(entered) = self.entered() {
|
||||
use ArrangerFocus::*;
|
||||
if let Some(true) = match entered {
|
||||
Transport => self.transport.as_mut().map(|t|t.handle(i)).transpose()?.flatten(),
|
||||
Arrangement => self.arrangement.handle(i)?,
|
||||
PhrasePool => self.phrases.write().unwrap().handle(i)?,
|
||||
PhraseEditor => self.editor.handle(i)?,
|
||||
} {
|
||||
return Ok(Some(true))
|
||||
}
|
||||
}
|
||||
Ok(if let Some(command) = ArrangerCommand::match_input(self, i) {
|
||||
let _undo = command.execute(self)?;
|
||||
Some(true)
|
||||
} else {
|
||||
|
|
|
|||
|
|
@ -11,8 +11,18 @@ impl Content for Sequencer<Tui> {
|
|||
}
|
||||
}
|
||||
impl Handle<Tui> for Sequencer<Tui> {
|
||||
fn handle (&mut self, from: &TuiInput) -> Perhaps<bool> {
|
||||
if let Some(command) = SequencerCommand::match_input(self, from) {
|
||||
fn handle (&mut self, i: &TuiInput) -> Perhaps<bool> {
|
||||
if let Some(entered) = self.entered() {
|
||||
use SequencerFocus::*;
|
||||
if let Some(true) = match entered {
|
||||
Transport => self.transport.as_mut().map(|t|t.handle(i)).transpose()?.flatten(),
|
||||
PhrasePool => self.phrases.write().unwrap().handle(i)?,
|
||||
PhraseEditor => self.editor.handle(i)?,
|
||||
} {
|
||||
return Ok(Some(true))
|
||||
}
|
||||
}
|
||||
if let Some(command) = SequencerCommand::match_input(self, i) {
|
||||
let _undo = command.execute(self)?;
|
||||
return Ok(Some(true))
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue