gled-ui 2.32.1

gled's egui interface, shared by the desktop app and the browser
Documentation
//! The interface's own settings, which stay on the device showing it: how
//! big the effect thumbnails are, with which palette they are drawn, and
//! whether the browser may use MIDI. eframe stores them, in a file on the
//! desktop and in the browser's local storage.

use gled_model::{asset::palette::Palette, asset_id::AssetId};
use serde::{Deserialize, Serialize};

/// The key eframe stores the settings under.
pub const STORAGE_KEY: &str = "gled_client_settings";

#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
#[serde(default)]
pub struct ClientSettings {
    effects_size: f32,
    preview_palette: Option<AssetId<Palette>>,
    /// The user connected the browser's MIDI devices once, so the page asks
    /// for them again when it opens.
    midi_access_wanted: bool,
}

impl Default for ClientSettings {
    fn default() -> Self {
        Self {
            effects_size: 100.0,
            preview_palette: None,
            midi_access_wanted: false,
        }
    }
}

impl ClientSettings {
    pub fn new(effects_size: f32, preview_palette: Option<AssetId<Palette>>) -> Self {
        Self {
            effects_size,
            preview_palette,
            ..Self::default()
        }
    }

    pub(crate) fn effects_size(&self) -> f32 {
        self.effects_size
    }

    pub(crate) fn effects_size_mut(&mut self) -> &mut f32 {
        &mut self.effects_size
    }

    pub(crate) fn preview_palette(&self) -> Option<AssetId<Palette>> {
        self.preview_palette
    }

    pub(crate) fn preview_palette_mut(&mut self) -> &mut Option<AssetId<Palette>> {
        &mut self.preview_palette
    }

    pub(crate) fn midi_access_wanted(&self) -> bool {
        self.midi_access_wanted
    }

    pub(crate) fn want_midi_access(&mut self) {
        self.midi_access_wanted = true;
    }
}