From 3af5be32999128d3294274bda053e468c6ba2245 Mon Sep 17 00:00:00 2001 From: pjht Date: Wed, 31 Jan 2024 10:42:26 -0600 Subject: [PATCH] Split OptionWindow to separate file --- src/main.rs | 59 +++----------------------------------------- src/option_window.rs | 58 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 61 insertions(+), 56 deletions(-) create mode 100644 src/option_window.rs diff --git a/src/main.rs b/src/main.rs index eb61bed..8f5a187 100644 --- a/src/main.rs +++ b/src/main.rs @@ -5,16 +5,17 @@ mod frontpanel; mod ram; mod window; mod state; +mod option_window; use std::{collections::HashMap, sync::mpsc::Sender}; use audio::{AudioMessage, AudioThread}; use eframe::{ - egui::{self, menu, Button, Slider, Ui}, + egui::{self, menu, Button, Ui}, NativeOptions, }; -use egui_modal::Modal; use frontpanel::Textures; +use option_window::OptionWindow; use rfd::FileDialog; use serde::{Deserialize, Serialize}; 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() - } -} diff --git a/src/option_window.rs b/src/option_window.rs new file mode 100644 index 0000000..b9f0383 --- /dev/null +++ b/src/option_window.rs @@ -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() + } +}