Split OptionWindow to separate file

This commit is contained in:
pjht 2024-01-31 10:42:26 -06:00
parent 3d4c6b038c
commit 3af5be3299
Signed by: pjht
GPG Key ID: CA239FC6934E6F3A
2 changed files with 61 additions and 56 deletions

View File

@ -5,16 +5,17 @@ mod frontpanel;
mod ram; mod ram;
mod window; mod window;
mod state; mod state;
mod option_window;
use std::{collections::HashMap, sync::mpsc::Sender}; use std::{collections::HashMap, sync::mpsc::Sender};
use audio::{AudioMessage, AudioThread}; use audio::{AudioMessage, AudioThread};
use eframe::{ use eframe::{
egui::{self, menu, Button, Slider, Ui}, egui::{self, menu, Button, Ui},
NativeOptions, NativeOptions,
}; };
use egui_modal::Modal;
use frontpanel::Textures; use frontpanel::Textures;
use option_window::OptionWindow;
use rfd::FileDialog; use rfd::FileDialog;
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use state::EmuState; use state::EmuState;
@ -159,57 +160,3 @@ impl eframe::App for AltairEmulator {
} }
} }
} }
struct OptionWindow {
options: Options,
category: OptionsCategory,
}
#[derive(PartialEq, Eq)]
enum OptionsCategory {
General,
Cards,
}
impl OptionWindow {
fn new(ctx: &egui::Context, state: &EmuState) -> Self {
Modal::new(ctx, "options_modal").open();
Self {
options: state.options().clone(),
category: OptionsCategory::General,
}
}
}
impl Window for OptionWindow {
fn draw(&mut self, ctx: &egui::Context, state: &mut EmuState) -> bool {
let modal = Modal::new(ctx, "options_modal");
modal.show(|ui| {
modal.title(ui, "Options");
ui.horizontal(|ui| {
ui.selectable_value(&mut self.category, OptionsCategory::General, "General");
ui.selectable_value(&mut self.category, OptionsCategory::Cards, "Cards");
});
match self.category {
OptionsCategory::General => {
ui.checkbox(&mut self.options.mute, "Mute");
ui.checkbox(&mut self.options.fan_enabled, "Fan enabled");
ui.add(Slider::new(&mut self.options.volume, 0.0..=100.0).text("Volume"));
}
OptionsCategory::Cards => {
ui.heading("TODO");
}
}
modal.buttons(ui, |ui| {
if ui.button("Apply").clicked() {
state.update_options(self.options);
}
if modal.button(ui, "OK").clicked() {
state.update_options(self.options);
}
modal.caution_button(ui, "Cancel");
});
});
!modal.is_open()
}
}

58
src/option_window.rs Normal file
View File

@ -0,0 +1,58 @@
use eframe::egui::{self, Slider};
use egui_modal::Modal;
use crate::{Options, state::EmuState, window::Window};
pub struct OptionWindow {
options: Options,
category: OptionsCategory,
}
#[derive(PartialEq, Eq)]
enum OptionsCategory {
General,
Cards,
}
impl OptionWindow {
pub fn new(ctx: &egui::Context, state: &EmuState) -> Self {
Modal::new(ctx, "options_modal").open();
Self {
options: state.options().clone(),
category: OptionsCategory::General,
}
}
}
impl Window for OptionWindow {
fn draw(&mut self, ctx: &egui::Context, state: &mut EmuState) -> bool {
let modal = Modal::new(ctx, "options_modal");
modal.show(|ui| {
modal.title(ui, "Options");
ui.horizontal(|ui| {
ui.selectable_value(&mut self.category, OptionsCategory::General, "General");
ui.selectable_value(&mut self.category, OptionsCategory::Cards, "Cards");
});
match self.category {
OptionsCategory::General => {
ui.checkbox(&mut self.options.mute, "Mute");
ui.checkbox(&mut self.options.fan_enabled, "Fan enabled");
ui.add(Slider::new(&mut self.options.volume, 0.0..=100.0).text("Volume"));
}
OptionsCategory::Cards => {
ui.heading("TODO");
}
}
modal.buttons(ui, |ui| {
if ui.button("Apply").clicked() {
state.update_options(self.options);
}
if modal.button(ui, "OK").clicked() {
state.update_options(self.options);
}
modal.caution_button(ui, "Cancel");
});
});
!modal.is_open()
}
}