altair_emu/src/option_window.rs

59 lines
1.8 KiB
Rust
Raw Normal View History

2024-01-31 10:42:26 -06:00
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()
}
}