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)]
#[serde(default)]
struct Options {
#[serde(default = "Options::default_mute")]
mute: bool,
#[serde(default = "Options::default_fan_enabled")]
fan_enabled: bool,
#[serde(default = "Options::default_volume")]
volume: f32,
}
impl Options {
fn default_mute() -> bool {
false
impl Default for Options {
fn default() -> Self {
Self {
mute: false,
fan_enabled: true,
volume: 100.0,
}
fn default_fan_enabled() -> bool {
true
}
fn default_volume() -> f32 {
100.0
}
}
@ -65,11 +61,7 @@ struct AltairEmulator {
impl AltairEmulator {
fn new(cc: &eframe::CreationContext<'_>, audio_tx: Sender<AudioMessage>) -> Self {
let options = if cc.storage.unwrap().get_string("options").is_none() {
Options {
mute: false,
fan_enabled: true,
volume: 1.0,
}
Options::default()
} else {
eframe::get_value(cc.storage.unwrap(), "options").unwrap()
};