arranger: theme trait

This commit is contained in:
🪞👃🪞 2024-11-09 17:43:08 +01:00
parent 89cb8d7bbe
commit 0b1193722d
6 changed files with 149 additions and 87 deletions

View file

@ -22,15 +22,15 @@ impl Handle<Tui> for Sequencer<Tui> {
return Ok(Some(true))
}
}
if let Some(command) = SequencerCommand::match_input(self, i) {
if let Some(command) = SequencerCommand::input_to_command(self, i) {
let _undo = command.execute(self)?;
return Ok(Some(true))
}
Ok(None)
}
}
impl MatchInput<Tui, Sequencer<Tui>> for SequencerCommand {
fn match_input (state: &Sequencer<Tui>, input: &TuiInput) -> Option<Self> {
impl InputToCommand<Tui, Sequencer<Tui>> for SequencerCommand {
fn input_to_command (state: &Sequencer<Tui>, input: &TuiInput) -> Option<Self> {
use SequencerCommand::*;
use FocusCommand::*;
match input.event() {
@ -45,15 +45,15 @@ impl MatchInput<Tui, Sequencer<Tui>> for SequencerCommand {
key!(KeyCode::Char(' ')) => Some(Transport(TransportCommand::PlayToggle)),
_ => match state.focused() {
SequencerFocus::Transport => if let Some(t) = state.transport.as_ref() {
TransportCommand::match_input(&*t.read().unwrap(), input).map(Transport)
TransportCommand::input_to_command(&*t.read().unwrap(), input).map(Transport)
} else {
None
},
SequencerFocus::PhrasePool =>
PhrasePoolCommand::match_input(&*state.phrases.read().unwrap(), input)
PhrasePoolCommand::input_to_command(&*state.phrases.read().unwrap(), input)
.map(Phrases),
SequencerFocus::PhraseEditor =>
PhraseEditorCommand::match_input(&state.editor, input)
PhraseEditorCommand::input_to_command(&state.editor, input)
.map(Editor),
}
}
@ -100,15 +100,15 @@ impl Content for PhrasePool<Tui> {
}
impl Handle<Tui> for PhrasePool<Tui> {
fn handle (&mut self, from: &TuiInput) -> Perhaps<bool> {
if let Some(command) = PhrasePoolCommand::match_input(self, from) {
if let Some(command) = PhrasePoolCommand::input_to_command(self, from) {
let _undo = command.execute(self)?;
return Ok(Some(true))
}
Ok(None)
}
}
impl MatchInput<Tui, PhrasePool<Tui>> for PhrasePoolCommand {
fn match_input (state: &PhrasePool<Tui>, input: &TuiInput) -> Option<Self> {
impl InputToCommand<Tui, PhrasePool<Tui>> for PhrasePoolCommand {
fn input_to_command (state: &PhrasePool<Tui>, input: &TuiInput) -> Option<Self> {
match input.event() {
key!(KeyCode::Up) => Some(Self::Prev),
key!(KeyCode::Down) => Some(Self::Next),
@ -122,17 +122,17 @@ impl MatchInput<Tui, PhrasePool<Tui>> for PhrasePoolCommand {
key!(KeyCode::Char('n')) => Some(Self::Rename(PhraseRenameCommand::Begin)),
key!(KeyCode::Char('t')) => Some(Self::Length(PhraseLengthCommand::Begin)),
_ => match state.mode {
Some(PhrasePoolMode::Rename(..)) => PhraseRenameCommand::match_input(state, input)
Some(PhrasePoolMode::Rename(..)) => PhraseRenameCommand::input_to_command(state, input)
.map(Self::Rename),
Some(PhrasePoolMode::Length(..)) => PhraseLengthCommand::match_input(state, input)
Some(PhrasePoolMode::Length(..)) => PhraseLengthCommand::input_to_command(state, input)
.map(Self::Length),
_ => None
}
}
}
}
impl MatchInput<Tui, PhrasePool<Tui>> for PhraseRenameCommand {
fn match_input (_: &PhrasePool<Tui>, from: &TuiInput) -> Option<Self> {
impl InputToCommand<Tui, PhrasePool<Tui>> for PhraseRenameCommand {
fn input_to_command (_: &PhrasePool<Tui>, from: &TuiInput) -> Option<Self> {
match from.event() {
key!(KeyCode::Backspace) => Some(Self::Backspace),
key!(KeyCode::Enter) => Some(Self::Confirm),
@ -142,8 +142,8 @@ impl MatchInput<Tui, PhrasePool<Tui>> for PhraseRenameCommand {
}
}
}
impl MatchInput<Tui, PhrasePool<Tui>> for PhraseLengthCommand {
fn match_input (_: &PhrasePool<Tui>, from: &TuiInput) -> Option<Self> {
impl InputToCommand<Tui, PhrasePool<Tui>> for PhraseLengthCommand {
fn input_to_command (_: &PhrasePool<Tui>, from: &TuiInput) -> Option<Self> {
match from.event() {
key!(KeyCode::Up) => Some(Self::Inc),
key!(KeyCode::Down) => Some(Self::Dec),
@ -307,10 +307,15 @@ impl Content for PhraseEditor<Tui> {
//note_clamp.unwrap_or(0),
//);
}
let upper_right = if let Some(phrase) = phrase {
format!("┤Length: {}", phrase.read().unwrap().length)
} else {
String::new()
};
lay!(
content,
TuiStyle::fg(upper_left.to_string(), title_color).push_x(1).align_nw().fill_xy(),
//TuiStyle::fg(upper_right.to_string(), title_color).pull_x(1).align_ne().fill_xy(),
TuiStyle::fg(upper_right.to_string(), title_color).pull_x(1).align_ne().fill_xy(),
TuiStyle::fg(lower_right.to_string(), title_color).pull_x(1).align_se().fill_xy(),
)
}
@ -456,15 +461,15 @@ pub(crate) fn keys_vert () -> Buffer {
}
impl Handle<Tui> for PhraseEditor<Tui> {
fn handle (&mut self, from: &TuiInput) -> Perhaps<bool> {
if let Some(command) = PhraseEditorCommand::match_input(self, from) {
if let Some(command) = PhraseEditorCommand::input_to_command(self, from) {
let _undo = command.execute(self)?;
return Ok(Some(true))
}
Ok(None)
}
}
impl MatchInput<Tui, PhraseEditor<Tui>> for PhraseEditorCommand {
fn match_input (_: &PhraseEditor<Tui>, from: &TuiInput) -> Option<Self> {
impl InputToCommand<Tui, PhraseEditor<Tui>> for PhraseEditorCommand {
fn input_to_command (_: &PhraseEditor<Tui>, from: &TuiInput) -> Option<Self> {
match from.event() {
key!(KeyCode::Char('`')) => Some(Self::ToggleDirection),
key!(KeyCode::Enter) => Some(Self::EnterEditMode),