cmdsys: focus enter

This commit is contained in:
🪞👃🪞 2024-11-09 02:22:23 +01:00
parent c551f83d5c
commit 31c1db8a5c
3 changed files with 28 additions and 9 deletions

View file

@ -6,6 +6,8 @@ pub struct Arranger<E: Engine> {
pub jack: Arc<RwLock<JackClient>>,
/// Which view is focused
pub focus_cursor: (usize, usize),
/// Whether the focused view is entered
pub entered: bool,
/// Controls the JACK transport.
pub transport: Option<Arc<RwLock<TransportToolbar<E>>>>,
/// Global timebase
@ -132,6 +134,7 @@ impl<E: Engine> Arranger<E> {
let mut app = Self {
jack: jack.clone(),
focus_cursor: (0, 1),
entered: false,
phrases_split: 20,
arrangement_split: 15,
editor: PhraseEditor::new(),
@ -271,13 +274,21 @@ 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 layout (&self) -> &[&[ArrangerFocus]] { &[
&[ArrangerFocus::Transport],
&[ArrangerFocus::Arrangement, ArrangerFocus::Arrangement],
&[ArrangerFocus::PhrasePool, ArrangerFocus::PhraseEditor],
] }
fn focus_enter (&mut self) { self.entered = true }
fn focus_exit (&mut self) { self.entered = false }
fn entered (&self) -> Option<ArrangerFocus> {
if self.entered { Some(self.focused()) } else { None }
}
fn layout (&self) -> &[&[ArrangerFocus]] {
use ArrangerFocus::*;
&[
&[Transport, Transport],
&[Arrangement, Arrangement],
&[PhrasePool, PhraseEditor],
]
}
fn update_focus (&mut self) {
let focused = *self.focused();
let focused = self.focused();
if let Some(transport) = self.transport.as_ref() {
transport.write().unwrap().focused =
focused == ArrangerFocus::Transport