101 lines
2.3 KiB
Rust
101 lines
2.3 KiB
Rust
use super::CyclicEnum;
|
|
|
|
#[derive(Clone, Copy, PartialEq, Eq, Default)]
|
|
pub enum OptionsFocus {
|
|
#[default]
|
|
ColorScheme,
|
|
HueRotation,
|
|
RefreshRate,
|
|
RuntimeHighlight,
|
|
ShowScope,
|
|
ShowSpectrum,
|
|
ShowCompletion,
|
|
LinkEnabled,
|
|
StartStopSync,
|
|
Quantum,
|
|
MidiOutput0,
|
|
MidiOutput1,
|
|
MidiOutput2,
|
|
MidiOutput3,
|
|
MidiInput0,
|
|
MidiInput1,
|
|
MidiInput2,
|
|
MidiInput3,
|
|
}
|
|
|
|
impl CyclicEnum for OptionsFocus {
|
|
const VARIANTS: &'static [Self] = &[
|
|
Self::ColorScheme,
|
|
Self::HueRotation,
|
|
Self::RefreshRate,
|
|
Self::RuntimeHighlight,
|
|
Self::ShowScope,
|
|
Self::ShowSpectrum,
|
|
Self::ShowCompletion,
|
|
Self::LinkEnabled,
|
|
Self::StartStopSync,
|
|
Self::Quantum,
|
|
Self::MidiOutput0,
|
|
Self::MidiOutput1,
|
|
Self::MidiOutput2,
|
|
Self::MidiOutput3,
|
|
Self::MidiInput0,
|
|
Self::MidiInput1,
|
|
Self::MidiInput2,
|
|
Self::MidiInput3,
|
|
];
|
|
}
|
|
|
|
const FOCUS_LINES: &[(OptionsFocus, usize)] = &[
|
|
(OptionsFocus::ColorScheme, 2),
|
|
(OptionsFocus::HueRotation, 3),
|
|
(OptionsFocus::RefreshRate, 4),
|
|
(OptionsFocus::RuntimeHighlight, 5),
|
|
(OptionsFocus::ShowScope, 6),
|
|
(OptionsFocus::ShowSpectrum, 7),
|
|
(OptionsFocus::ShowCompletion, 8),
|
|
(OptionsFocus::LinkEnabled, 12),
|
|
(OptionsFocus::StartStopSync, 13),
|
|
(OptionsFocus::Quantum, 14),
|
|
(OptionsFocus::MidiOutput0, 24),
|
|
(OptionsFocus::MidiOutput1, 25),
|
|
(OptionsFocus::MidiOutput2, 26),
|
|
(OptionsFocus::MidiOutput3, 27),
|
|
(OptionsFocus::MidiInput0, 31),
|
|
(OptionsFocus::MidiInput1, 32),
|
|
(OptionsFocus::MidiInput2, 33),
|
|
(OptionsFocus::MidiInput3, 34),
|
|
];
|
|
|
|
impl OptionsFocus {
|
|
pub fn line_index(self) -> usize {
|
|
FOCUS_LINES
|
|
.iter()
|
|
.find(|(f, _)| *f == self)
|
|
.map(|(_, l)| *l)
|
|
.unwrap_or(0)
|
|
}
|
|
|
|
pub fn at_line(line: usize) -> Option<OptionsFocus> {
|
|
FOCUS_LINES
|
|
.iter()
|
|
.find(|(_, l)| *l == line)
|
|
.map(|(f, _)| *f)
|
|
}
|
|
}
|
|
|
|
#[derive(Default)]
|
|
pub struct OptionsState {
|
|
pub focus: OptionsFocus,
|
|
}
|
|
|
|
impl OptionsState {
|
|
pub fn next_focus(&mut self) {
|
|
self.focus = self.focus.next();
|
|
}
|
|
|
|
pub fn prev_focus(&mut self) {
|
|
self.focus = self.focus.prev();
|
|
}
|
|
}
|