1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
//! What the rule list remembers between frames.
use super::intent::SlotNumbering;
/// Which rules the list shows.
#[derive(Debug, Clone, Copy, Default, PartialEq, Eq)]
pub(crate) enum ModeFilter {
/// Every rule, in a section per mode.
#[default]
All,
/// The rules that work in all modes.
Everywhere,
/// The rules of one mode.
Mode(u8),
}
/// Learning a control, asked for by a click in the list.
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub(crate) enum LearnRequest {
/// Each control moved next gets a rule (in the shown mode).
NewControls,
/// The control's messages change to those of the control moved next.
Control(usize),
/// The button pressed next switches to this mode.
ModeSwitch(u8),
}
/// The copy dialog of a rule: the controls to copy to and how its numbers
/// count there.
#[derive(Debug, Clone, Default)]
pub(crate) struct CopyState {
pub(crate) chosen: Vec<usize>,
/// How many controls sending the next messages to copy to as well,
/// learned or not.
pub(crate) next: u8,
pub(crate) numbering: SlotNumbering,
pub(crate) prepared: bool,
}
#[derive(Debug, Default)]
pub(crate) struct ListState {
pub(crate) find: String,
pub(crate) filter: ModeFilter,
/// The group member whose own rule is open: the group's first control
/// and mode, and the member's control.
pub(crate) open_member: Option<(usize, Option<u8>, usize)>,
/// Rules with their MIDI details open, by control and mode.
pub(crate) midi_open: Vec<(usize, Option<u8>)>,
/// The rule whose copy dialog is open.
pub(crate) copying: Option<(usize, Option<u8>)>,
pub(crate) copy: CopyState,
/// The rule whose action palette opens now, after learning its control.
pub(crate) open_palette: Option<(usize, Option<u8>)>,
/// The control moved on the hardware last, and when (seconds).
pub(crate) highlight: Option<(usize, f64)>,
pub(crate) scroll_to: Option<usize>,
pub(crate) renaming: Option<(usize, String)>,
pub(crate) learn_request: Option<LearnRequest>,
/// The search field takes the focus.
pub(crate) focus_find: bool,
}
impl ListState {
/// Forgets what belongs to another controller.
pub(crate) fn reset(&mut self) {
*self = Self {
find: std::mem::take(&mut self.find),
..Self::default()
};
}
}