Simplify default values for Options
This commit is contained in:
parent
3af5be3299
commit
a7ae967483
24
src/main.rs
24
src/main.rs
@ -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,
|
||||||
|
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 {
|
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()
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user