Simplify default values for Options

This commit is contained in:
pjht 2024-01-31 10:44:27 -06:00
parent 3af5be3299
commit a7ae967483
Signed by: pjht
GPG Key ID: CA239FC6934E6F3A

View File

@ -34,24 +34,20 @@ fn main() -> Result<(), eframe::Error> {
} }
#[derive(Debug, Copy, Clone, Serialize, Deserialize)] #[derive(Debug, Copy, Clone, Serialize, Deserialize)]
#[serde(default)]
struct Options { struct Options {
#[serde(default = "Options::default_mute")]
mute: bool, mute: bool,
#[serde(default = "Options::default_fan_enabled")]
fan_enabled: bool, fan_enabled: bool,
#[serde(default = "Options::default_volume")]
volume: f32, volume: f32,
} }
impl Options { impl Default for Options {
fn default_mute() -> bool { fn default() -> Self {
false Self {
} mute: false,
fn default_fan_enabled() -> bool { fan_enabled: true,
true volume: 100.0,
} }
fn default_volume() -> f32 {
100.0
} }
} }
@ -65,11 +61,7 @@ struct AltairEmulator {
impl AltairEmulator { impl AltairEmulator {
fn new(cc: &eframe::CreationContext<'_>, audio_tx: Sender<AudioMessage>) -> Self { fn new(cc: &eframe::CreationContext<'_>, audio_tx: Sender<AudioMessage>) -> Self {
let options = if cc.storage.unwrap().get_string("options").is_none() { let options = if cc.storage.unwrap().get_string("options").is_none() {
Options { Options::default()
mute: false,
fan_enabled: true,
volume: 1.0,
}
} else { } else {
eframe::get_value(cc.storage.unwrap(), "options").unwrap() eframe::get_value(cc.storage.unwrap(), "options").unwrap()
}; };