Split OptionWindow to separate file
This commit is contained in:
parent
3d4c6b038c
commit
3af5be3299
59
src/main.rs
59
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()
|
||||
}
|
||||
}
|
||||
|
58
src/option_window.rs
Normal file
58
src/option_window.rs
Normal 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()
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user