implement sequencer focus; auto update_focus

This commit is contained in:
🪞👃🪞 2024-10-09 22:50:23 +03:00
parent 9f15f8fff9
commit 3bf475d15e
8 changed files with 119 additions and 160 deletions

View file

@ -2,6 +2,8 @@ use crate::*;
/// Root level object for standalone `tek_arranger`
pub struct Arranger<E: Engine> {
/// Which view is focused
pub focus_cursor: (usize, usize),
/// Controls the JACK transport.
pub transport: Option<Arc<RwLock<TransportToolbar<E>>>>,
/// Contains all the sequencers.
@ -14,24 +16,10 @@ pub struct Arranger<E: Engine> {
pub show_sequencer: Option<tek_core::Direction>,
/// Slot for modal dialog displayed on top of app.
pub modal: Option<Box<dyn ContentComponent<E>>>,
/// Focus cursor
pub focus_cursor: (usize, usize)
}
/// Sections in the arranger that may be focused
/// Sections in the arranger app that may be focused
#[derive(Copy, Clone, PartialEq, Eq)]
pub enum ArrangerFocus { Transport, Arrangement, PhrasePool, PhraseEditor }
/// Focus layout of arranger.
impl<E: Engine> FocusGrid<ArrangerFocus> for Arranger<E> {
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],
]
}
}
/// Represents the tracks and scenes of the composition.
pub struct Arrangement<E: Engine> {
/// Name of arranger
@ -104,6 +92,29 @@ pub struct ArrangerRenameModal<E: Engine> {
pub result: Arc<RwLock<String>>,
pub cursor: usize
}
/// Focus layout of arranger app
impl<E: Engine> FocusGrid<ArrangerFocus> for Arranger<E> {
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 update_focus (&mut self) {
let focused = *self.focused();
if let Some(transport) = self.transport.as_ref() {
transport.write().unwrap().focused =
focused == ArrangerFocus::Transport
}
self.arrangement.focused =
focused == ArrangerFocus::Arrangement;
self.phrases.write().unwrap().focused =
focused == ArrangerFocus::PhrasePool;
self.editor.focused =
focused == ArrangerFocus::PhraseEditor;
}
}
/// General methods for arrangement
impl<E: Engine> Arrangement<E> {
pub fn new (name: &str, phrases: &Arc<RwLock<PhrasePool<E>>>) -> Self {
@ -182,7 +193,7 @@ impl<E: Engine> Arrangement<E> {
for track_index in 0..self.tracks.len() {
if let Some(phrase) = scene.clip(track_index) {
let len = phrase.read().unwrap().name.read().unwrap().len();
lens[track_index] = lens[track_index].max(len + 16);
lens[track_index] = lens[track_index].max(len);
}
}
}