mirror of
https://codeberg.org/unspeaker/tek.git
synced 2025-12-07 04:06:45 +01:00
wip: p.51, e=7, collecting tui by layer
This commit is contained in:
parent
b3ac9e60e3
commit
7b3c013aa7
26 changed files with 786 additions and 799 deletions
215
crates/tek_tui/src/tui_focus.rs
Normal file
215
crates/tek_tui/src/tui_focus.rs
Normal file
|
|
@ -0,0 +1,215 @@
|
|||
use crate::*;
|
||||
|
||||
/// Which item of the transport toolbar is focused
|
||||
#[derive(Clone, Copy, Debug, PartialEq)]
|
||||
pub enum TransportFocus {
|
||||
Menu,
|
||||
Bpm,
|
||||
Sync,
|
||||
PlayPause,
|
||||
Clock,
|
||||
Quant,
|
||||
}
|
||||
/// Sections in the sequencer app that may be focused
|
||||
#[derive(Copy, Clone, PartialEq, Eq, Debug)]
|
||||
pub enum SequencerFocus {
|
||||
/// The menu bar is focused
|
||||
Menu,
|
||||
/// The transport (toolbar) is focused
|
||||
Transport,
|
||||
/// The phrase list (pool) is focused
|
||||
PhrasePool,
|
||||
/// The phrase editor (sequencer) is focused
|
||||
PhraseEditor,
|
||||
}
|
||||
/// Sections in the arranger app that may be focused
|
||||
#[derive(Copy, Clone, PartialEq, Eq, Debug)]
|
||||
pub enum ArrangerFocus {
|
||||
/// The menu bar is focused
|
||||
Menu,
|
||||
/// The transport (toolbar) is focused
|
||||
Transport,
|
||||
/// The arrangement (grid) is focused
|
||||
Arranger,
|
||||
/// The phrase list (pool) is focused
|
||||
PhrasePool,
|
||||
/// The phrase editor (sequencer) is focused
|
||||
PhraseEditor,
|
||||
}
|
||||
|
||||
impl TransportFocus {
|
||||
pub fn next (&mut self) {
|
||||
*self = match self {
|
||||
Self::PlayPause => Self::Bpm,
|
||||
Self::Bpm => Self::Quant,
|
||||
Self::Quant => Self::Sync,
|
||||
Self::Sync => Self::Clock,
|
||||
Self::Clock => Self::PlayPause,
|
||||
}
|
||||
}
|
||||
pub fn prev (&mut self) {
|
||||
*self = match self {
|
||||
Self::PlayPause => Self::Clock,
|
||||
Self::Bpm => Self::PlayPause,
|
||||
Self::Quant => Self::Bpm,
|
||||
Self::Sync => Self::Quant,
|
||||
Self::Clock => Self::Sync,
|
||||
}
|
||||
}
|
||||
pub fn wrap <'a, W: Widget<Engine = Tui>> (
|
||||
self, parent_focus: bool, focus: Self, widget: &'a W
|
||||
) -> impl Widget<Engine = Tui> + 'a {
|
||||
let focused = parent_focus && focus == self;
|
||||
let corners = focused.then_some(CORNERS);
|
||||
let highlight = focused.then_some(Background(Color::Rgb(60, 70, 50)));
|
||||
lay!(corners, highlight, *widget)
|
||||
}
|
||||
}
|
||||
|
||||
impl HasFocus for TransportTui {
|
||||
type Item = TransportFocus;
|
||||
}
|
||||
|
||||
impl FocusEnter for TransportTui {
|
||||
type Item = TransportFocus;
|
||||
fn focus_enter (&mut self) {
|
||||
self.entered = true;
|
||||
}
|
||||
fn focus_exit (&mut self) {
|
||||
self.entered = false;
|
||||
}
|
||||
fn focus_entered (&self) -> Option<Self::Item> {
|
||||
if self.entered {
|
||||
Some(self.focused())
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl FocusGrid for TransportTui {
|
||||
type Item = TransportFocus;
|
||||
fn focus_cursor (&self) -> (usize, usize) {
|
||||
self.cursor
|
||||
}
|
||||
fn focus_cursor_mut (&mut self) -> &mut (usize, usize) {
|
||||
&mut self.cursor
|
||||
}
|
||||
fn focus_layout (&self) -> &[&[Self::Item]] {
|
||||
use TransportFocus::*;
|
||||
&[
|
||||
&[Menu],
|
||||
&[Bpm, Sync, PlayPause, Clock, Quant],
|
||||
]
|
||||
}
|
||||
fn focus_update (&mut self) {
|
||||
// TODO
|
||||
}
|
||||
}
|
||||
|
||||
impl HasFocus for SequencerTui {
|
||||
type Item = SequencerFocus;
|
||||
}
|
||||
|
||||
impl FocusEnter for SequencerTui {
|
||||
type Item = SequencerFocus;
|
||||
fn focus_enter (&mut self) {
|
||||
let focused = self.focused();
|
||||
if !self.entered {
|
||||
self.entered = true;
|
||||
// TODO
|
||||
}
|
||||
}
|
||||
fn focus_exit (&mut self) {
|
||||
if self.entered {
|
||||
self.entered = false;
|
||||
// TODO
|
||||
}
|
||||
}
|
||||
fn focus_entered (&self) -> Option<Self::Item> {
|
||||
if self.entered {
|
||||
Some(self.focused())
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl FocusGrid for SequencerTui {
|
||||
type Item = SequencerFocus;
|
||||
fn focus_cursor (&self) -> (usize, usize) {
|
||||
self.cursor
|
||||
}
|
||||
fn focus_cursor_mut (&mut self) -> &mut (usize, usize) {
|
||||
&mut self.cursor
|
||||
}
|
||||
fn focus_layout (&self) -> &[&[Self::Item]] {
|
||||
use SequencerFocus::*;
|
||||
&[
|
||||
&[Menu, Menu ],
|
||||
&[Transport, Transport ],
|
||||
&[PhrasePool, PhraseEditor],
|
||||
]
|
||||
}
|
||||
fn focus_update (&mut self) {
|
||||
// TODO
|
||||
}
|
||||
}
|
||||
|
||||
impl FocusEnter for ArrangerTui {
|
||||
type Item = ArrangerFocus;
|
||||
fn focus_enter (&mut self) {
|
||||
use ArrangerFocus::*;
|
||||
let focused = self.focused();
|
||||
if !self.entered {
|
||||
self.entered = focused == Arranger;
|
||||
self.app.editor.entered = focused == PhraseEditor;
|
||||
self.app.phrases.entered = focused == PhrasePool;
|
||||
}
|
||||
}
|
||||
fn focus_exit (&mut self) {
|
||||
if self.entered {
|
||||
self.entered = false;
|
||||
self.app.editor.entered = false;
|
||||
self.app.phrases.entered = false;
|
||||
}
|
||||
}
|
||||
fn focus_entered (&self) -> Option<Self::Item> {
|
||||
if self.entered {
|
||||
Some(self.focused())
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Focus layout of arranger app
|
||||
impl FocusGrid for ArrangerTui {
|
||||
type Item = ArrangerFocus;
|
||||
fn focus_cursor (&self) -> (usize, usize) {
|
||||
self.cursor
|
||||
}
|
||||
fn focus_cursor_mut (&mut self) -> &mut (usize, usize) {
|
||||
&mut self.cursor
|
||||
}
|
||||
fn focus_layout (&self) -> &[&[Self::Item]] {
|
||||
use ArrangerFocus::*;
|
||||
&[
|
||||
&[Menu, Menu ],
|
||||
&[Transport, Transport ],
|
||||
&[Arranger, Arranger ],
|
||||
&[PhrasePool, PhraseEditor],
|
||||
]
|
||||
}
|
||||
fn focus_update (&mut self) {
|
||||
use ArrangerFocus::*;
|
||||
let focused = self.focused();
|
||||
if let Some(mut status_bar) = self.status_bar {
|
||||
status_bar.update(&(
|
||||
self.focused(),
|
||||
self.app.selected,
|
||||
focused == PhraseEditor && self.entered
|
||||
))
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue