Trying to clena the mess opened by plugins

This commit is contained in:
2026-02-21 01:03:55 +01:00
parent 5ef988382b
commit e9bca2548c
67 changed files with 1246 additions and 69 deletions

View File

@@ -11,6 +11,9 @@ pub enum OptionsFocus {
ShowSpectrum,
ShowCompletion,
ShowPreview,
Font,
ZoomFactor,
WindowSize,
LinkEnabled,
StartStopSync,
Quantum,
@@ -35,6 +38,9 @@ impl CyclicEnum for OptionsFocus {
Self::ShowSpectrum,
Self::ShowCompletion,
Self::ShowPreview,
Self::Font,
Self::ZoomFactor,
Self::WindowSize,
Self::LinkEnabled,
Self::StartStopSync,
Self::Quantum,
@@ -50,6 +56,8 @@ impl CyclicEnum for OptionsFocus {
];
}
// Line indices when Font/ZoomFactor are shown (plugin mode).
// In terminal mode, Font/ZoomFactor are absent; all lines after ShowPreview shift up by 2.
const FOCUS_LINES: &[(OptionsFocus, usize)] = &[
(OptionsFocus::ColorScheme, 2),
(OptionsFocus::HueRotation, 3),
@@ -59,34 +67,51 @@ const FOCUS_LINES: &[(OptionsFocus, usize)] = &[
(OptionsFocus::ShowSpectrum, 7),
(OptionsFocus::ShowCompletion, 8),
(OptionsFocus::ShowPreview, 9),
(OptionsFocus::LinkEnabled, 13),
(OptionsFocus::StartStopSync, 14),
(OptionsFocus::Quantum, 15),
(OptionsFocus::MidiOutput0, 25),
(OptionsFocus::MidiOutput1, 26),
(OptionsFocus::MidiOutput2, 27),
(OptionsFocus::MidiOutput3, 28),
(OptionsFocus::MidiInput0, 32),
(OptionsFocus::MidiInput1, 33),
(OptionsFocus::MidiInput2, 34),
(OptionsFocus::MidiInput3, 35),
(OptionsFocus::ResetOnboarding, 39),
(OptionsFocus::Font, 10),
(OptionsFocus::ZoomFactor, 11),
(OptionsFocus::WindowSize, 12),
(OptionsFocus::LinkEnabled, 16),
(OptionsFocus::StartStopSync, 17),
(OptionsFocus::Quantum, 18),
(OptionsFocus::MidiOutput0, 28),
(OptionsFocus::MidiOutput1, 29),
(OptionsFocus::MidiOutput2, 30),
(OptionsFocus::MidiOutput3, 31),
(OptionsFocus::MidiInput0, 35),
(OptionsFocus::MidiInput1, 36),
(OptionsFocus::MidiInput2, 37),
(OptionsFocus::MidiInput3, 38),
(OptionsFocus::ResetOnboarding, 42),
];
const PLUGIN_ONLY: &[OptionsFocus] = &[OptionsFocus::Font, OptionsFocus::ZoomFactor, OptionsFocus::WindowSize];
impl OptionsFocus {
pub fn line_index(self) -> usize {
FOCUS_LINES
fn is_plugin_only(self) -> bool {
PLUGIN_ONLY.contains(&self)
}
pub fn line_index(self, plugin_mode: bool) -> usize {
let base = FOCUS_LINES
.iter()
.find(|(f, _)| *f == self)
.map(|(_, l)| *l)
.unwrap_or(0)
.unwrap_or(0);
if plugin_mode || base <= 9 {
base
} else {
base - 3
}
}
pub fn at_line(line: usize) -> Option<OptionsFocus> {
FOCUS_LINES
.iter()
.find(|(_, l)| *l == line)
.map(|(f, _)| *f)
pub fn at_line(line: usize, plugin_mode: bool) -> Option<OptionsFocus> {
FOCUS_LINES.iter().find_map(|(f, l)| {
if f.is_plugin_only() && !plugin_mode {
return None;
}
let effective = if plugin_mode || *l <= 9 { *l } else { *l - 3 };
if effective == line { Some(*f) } else { None }
})
}
}
@@ -96,11 +121,25 @@ pub struct OptionsState {
}
impl OptionsState {
pub fn next_focus(&mut self) {
self.focus = self.focus.next();
pub fn next_focus(&mut self, plugin_mode: bool) {
let mut f = self.focus;
loop {
f = f.next();
if !f.is_plugin_only() || plugin_mode {
break;
}
}
self.focus = f;
}
pub fn prev_focus(&mut self) {
self.focus = self.focus.prev();
pub fn prev_focus(&mut self, plugin_mode: bool) {
let mut f = self.focus;
loop {
f = f.prev();
if !f.is_plugin_only() || plugin_mode {
break;
}
}
self.focus = f;
}
}