diff --git a/crates/ui/src/lib.rs b/crates/ui/src/lib.rs index 2f513761..8a2c101b 100644 --- a/crates/ui/src/lib.rs +++ b/crates/ui/src/lib.rs @@ -172,12 +172,11 @@ tab_enum! { window_enum! { pub enum Window { About(windows::about::Window), - Appearance(windows::appearance::Window), CommonEvent(windows::common_event_edit::Window), ProjectConfig(windows::config_window::Window), Console(windows::console::Window), EventEdit(windows::event_edit::Window), - GlobalConfig(windows::global_config_window::Window), + Preferences(windows::preferences::Window), Items(windows::items::Window), MapPicker(windows::map_picker::Window), EguiInspection(windows::misc::EguiInspection), @@ -196,7 +195,7 @@ window_enum! { CommonEvent(windows::common_event_edit::Window), ProjectConfig(windows::config_window::Window), EventEdit(windows::event_edit::Window), - GlobalConfig(windows::global_config_window::Window), + GlobalConfig(windows::preferences::Window), Items(windows::items::Window), MapPicker(windows::map_picker::Window), EguiInspection(windows::misc::EguiInspection), diff --git a/crates/ui/src/windows/appearance.rs b/crates/ui/src/windows/appearance.rs deleted file mode 100644 index 788cba5e..00000000 --- a/crates/ui/src/windows/appearance.rs +++ /dev/null @@ -1,103 +0,0 @@ -// Copyright (C) 2023 Lily Lyons -// -// This file is part of Luminol. -// -// Luminol is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. -// -// Luminol is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with Luminol. If not, see . -// -// Additional permission under GNU GPL version 3 section 7 -// -// If you modify this Program, or any covered work, by linking or combining -// it with Steamworks API by Valve Corporation, containing parts covered by -// terms of the Steamworks API by Valve Corporation, the licensors of this -// Program grant you additional permission to convey the resulting work. - -use strum::IntoEnumIterator; - -#[derive(Default)] -pub struct Window { - egui_settings_open: bool, - mode: Mode, -} - -#[derive(Clone, Copy)] -#[derive(Default, PartialEq, Eq)] -#[derive(strum::EnumIter, strum::Display)] -enum Mode { - #[default] - #[strum(to_string = "Egui Appearance")] - EguiAppearance, - #[strum(to_string = "Theme Presets")] - ThemePresets, - #[strum(to_string = "Code Theme")] - CodeTheme, -} - -const CODE_SAMPLE: &str = include_str!("../../assets/code_sample.rb"); - -impl luminol_core::Window for Window { - fn id(&self) -> egui::Id { - egui::Id::new("luminol_appearance_window") - } - - fn name(&self) -> String { - "Luminol Appearance".to_string() - } - - fn show( - &mut self, - ctx: &egui::Context, - open: &mut bool, - update_state: &mut luminol_core::UpdateState<'_>, - ) { - egui::Window::new(self.name()).open(open).show(ctx, |ui| { - ui.horizontal(|ui| { - for mode in Mode::iter() { - ui.selectable_value(&mut self.mode, mode, mode.to_string()); - ui.separator(); - } - }); - ui.separator(); - - match self.mode { - Mode::EguiAppearance => { - ctx.style_ui(ui); - } - Mode::ThemePresets => {} - Mode::CodeTheme => { - ui.horizontal(|ui| { - ui.vertical(|ui| { - for t in luminol_config::SyntectTheme::iter() { - ui.radio_value( - &mut update_state.global_config.theme.syntect_theme, - t, - t.to_string(), - ); - } - }); - - ui.vertical(|ui| { - ui.label("Code sample"); - ui.label(luminol_components::syntax_highlighting::highlight( - ui.ctx(), - update_state.global_config.theme, - CODE_SAMPLE, - "rb", - )); - }); - }); - } - } - }); - } -} diff --git a/crates/ui/src/windows/mod.rs b/crates/ui/src/windows/mod.rs index d6991ad1..dd3943dc 100644 --- a/crates/ui/src/windows/mod.rs +++ b/crates/ui/src/windows/mod.rs @@ -24,7 +24,6 @@ /// The about window. pub mod about; -pub mod appearance; /// The common event editor. pub mod common_event_edit; /// Config window @@ -34,7 +33,6 @@ pub mod config_window; pub mod console; /// The event editor. pub mod event_edit; -pub mod global_config_window; /// The item editor. pub mod items; /// The map picker. @@ -43,6 +41,7 @@ pub mod map_picker; pub mod misc; /// New project window pub mod new_project; +pub mod preferences; /// The script editor pub mod script_edit; /// The sound test. diff --git a/crates/ui/src/windows/global_config_window.rs b/crates/ui/src/windows/preferences.rs similarity index 62% rename from crates/ui/src/windows/global_config_window.rs rename to crates/ui/src/windows/preferences.rs index b33fb998..b4e4ec2f 100644 --- a/crates/ui/src/windows/global_config_window.rs +++ b/crates/ui/src/windows/preferences.rs @@ -21,15 +21,32 @@ // it with Steamworks API by Valve Corporation, containing parts covered by // terms of the Steamworks API by Valve Corporation, the licensors of this // Program grant you additional permission to convey the resulting work. - use std::ops::Not; +use strum::IntoEnumIterator; #[derive(Default)] pub struct Window { edit_rtp_path_name: String, edit_rtp_path_path: String, + + appearance_mode: AppearanceMode, +} + +#[derive(Clone, Copy)] +#[derive(Default, PartialEq, Eq)] +#[derive(strum::EnumIter, strum::Display)] +enum AppearanceMode { + #[default] + #[strum(to_string = "Egui Style")] + EguiStyle, + #[strum(to_string = "Style Presets")] + StylePresets, + #[strum(to_string = "Code Theme")] + CodeTheme, } +const CODE_SAMPLE: &str = include_str!("../../assets/code_sample.rb"); + impl luminol_core::Window for Window { fn name(&self) -> String { "Luminol Preferences".to_string() @@ -85,6 +102,46 @@ impl luminol_core::Window for Window { update_state.global_config.rtp_paths = new_rtp_paths; }); + + ui.separator(); + + ui.horizontal(|ui| { + for mode in AppearanceMode::iter() { + ui.selectable_value(&mut self.appearance_mode, mode, mode.to_string()); + ui.separator(); + } + }); + ui.separator(); + + match self.appearance_mode { + AppearanceMode::EguiStyle => { + ctx.style_ui(ui); + } + AppearanceMode::StylePresets => {} + AppearanceMode::CodeTheme => { + ui.horizontal(|ui| { + ui.vertical(|ui| { + for t in luminol_config::SyntectTheme::iter() { + ui.radio_value( + &mut update_state.global_config.theme.syntect_theme, + t, + t.to_string(), + ); + } + }); + + ui.vertical(|ui| { + ui.label("Code sample"); + ui.label(luminol_components::syntax_highlighting::highlight( + ui.ctx(), + update_state.global_config.theme, + CODE_SAMPLE, + "rb", + )); + }); + }); + } + } }); } } diff --git a/src/app/top_bar.rs b/src/app/top_bar.rs index 116218b7..6da1e3fd 100644 --- a/src/app/top_bar.rs +++ b/src/app/top_bar.rs @@ -130,13 +130,7 @@ impl TopBar { if ui.button("Preferences").clicked() { update_state .edit_windows - .add_window(luminol_ui::windows::global_config_window::Window::default()) - } - - if ui.button("Appearance").clicked() { - update_state - .edit_windows - .add_window(luminol_ui::windows::appearance::Window::default()) + .add_window(luminol_ui::windows::preferences::Window::default()) } });