gled-ui 2.34.0

gled's egui interface, shared by the desktop app and the browser
Documentation
//! 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()
        };
    }
}