mirror of
https://codeberg.org/unspeaker/tek.git
synced 2025-12-07 04:06:45 +01:00
separate control layer
This commit is contained in:
parent
416acd9f7b
commit
9319315595
29 changed files with 1647 additions and 1641 deletions
|
|
@ -8,67 +8,11 @@ pub enum AppFocus<T: Copy + Debug + PartialEq> {
|
|||
Content(T)
|
||||
}
|
||||
|
||||
/// Which item of the transport toolbar is focused
|
||||
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
|
||||
pub enum TransportFocus {
|
||||
Bpm,
|
||||
Sync,
|
||||
PlayPause,
|
||||
Clock,
|
||||
Quant,
|
||||
}
|
||||
|
||||
/// Sections in the sequencer app that may be focused
|
||||
#[derive(Copy, Clone, PartialEq, Eq, Debug)]
|
||||
pub enum SequencerFocus {
|
||||
/// The transport (toolbar) is focused
|
||||
Transport(TransportFocus),
|
||||
/// The phrase list (pool) is focused
|
||||
Phrases,
|
||||
/// 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 transport (toolbar) is focused
|
||||
Transport(TransportFocus),
|
||||
/// The arrangement (grid) is focused
|
||||
Arranger,
|
||||
/// The phrase list (pool) is focused
|
||||
Phrases,
|
||||
/// The phrase editor (sequencer) is focused
|
||||
PhraseEditor,
|
||||
}
|
||||
|
||||
pub trait FocusWrap<T> {
|
||||
fn wrap <'a, W: Widget<Engine = Tui>> (self, focus: T, content: &'a W)
|
||||
-> impl Widget<Engine = Tui> + 'a;
|
||||
}
|
||||
|
||||
impl FocusWrap<TransportFocus> for TransportFocus {
|
||||
fn wrap <'a, W: Widget<Engine = Tui>> (self, focus: TransportFocus, content: &'a W)
|
||||
-> impl Widget<Engine = Tui> + 'a
|
||||
{
|
||||
let focused = focus == self;
|
||||
let corners = focused.then_some(CORNERS);
|
||||
let highlight = focused.then_some(Background(Color::Rgb(60, 70, 50)));
|
||||
lay!(corners, highlight, *content)
|
||||
}
|
||||
}
|
||||
|
||||
impl FocusWrap<TransportFocus> for Option<TransportFocus> {
|
||||
fn wrap <'a, W: Widget<Engine = Tui>> (self, focus: TransportFocus, content: &'a W)
|
||||
-> impl Widget<Engine = Tui> + 'a
|
||||
{
|
||||
let focused = Some(focus) == self;
|
||||
let corners = focused.then_some(CORNERS);
|
||||
let highlight = focused.then_some(Background(Color::Rgb(60, 70, 50)));
|
||||
lay!(corners, highlight, *content)
|
||||
}
|
||||
}
|
||||
|
||||
macro_rules! impl_focus {
|
||||
($Struct:ident $Focus:ident $Grid:expr) => {
|
||||
impl HasFocus for $Struct {
|
||||
|
|
@ -175,31 +119,3 @@ impl_focus!(ArrangerTui ArrangerFocus [
|
|||
Content(PhraseEditor),
|
||||
],
|
||||
]);
|
||||
|
||||
/// Focused field of `PhraseLength`
|
||||
#[derive(Copy, Clone, Debug)]
|
||||
pub enum PhraseLengthFocus {
|
||||
/// Editing the number of bars
|
||||
Bar,
|
||||
/// Editing the number of beats
|
||||
Beat,
|
||||
/// Editing the number of ticks
|
||||
Tick,
|
||||
}
|
||||
|
||||
impl PhraseLengthFocus {
|
||||
pub fn next (&mut self) {
|
||||
*self = match self {
|
||||
Self::Bar => Self::Beat,
|
||||
Self::Beat => Self::Tick,
|
||||
Self::Tick => Self::Bar,
|
||||
}
|
||||
}
|
||||
pub fn prev (&mut self) {
|
||||
*self = match self {
|
||||
Self::Bar => Self::Tick,
|
||||
Self::Beat => Self::Bar,
|
||||
Self::Tick => Self::Beat,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue