diff --git a/crates/ui/assets/code_sample.rb b/crates/ui/assets/code_sample.rb new file mode 100644 index 00000000..86c6554f --- /dev/null +++ b/crates/ui/assets/code_sample.rb @@ -0,0 +1,19 @@ + +class Foo < Array + include Enumerable +end + +def bar(baz) + @baz = baz + $foo = Foo.new(1, 2, 3, 4) +end + +baz = ->() {} +{ + "string" => bar(baz), + hash_symbol: baz +} + +print 1, 2.0 + +puts [0x3F, :symbol, '5'] diff --git a/crates/ui/src/windows/appearance.rs b/crates/ui/src/windows/appearance.rs index 4b78e927..788cba5e 100644 --- a/crates/ui/src/windows/appearance.rs +++ b/crates/ui/src/windows/appearance.rs @@ -27,8 +27,24 @@ 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") @@ -45,59 +61,42 @@ impl luminol_core::Window for Window { update_state: &mut luminol_core::UpdateState<'_>, ) { egui::Window::new(self.name()).open(open).show(ctx, |ui| { - // Or these together so if one OR the other is true the window shows. - self.egui_settings_open = - ui.button("Egui Settings").clicked() || self.egui_settings_open; - - ui.menu_button("Catppuccin theme", |ui| { - if ui.button("Frappe").clicked() { - catppuccin_egui::set_theme(ui.ctx(), catppuccin_egui::FRAPPE); - } - if ui.button("Latte").clicked() { - catppuccin_egui::set_theme(ui.ctx(), catppuccin_egui::LATTE); - } - if ui.button("Macchiato").clicked() { - catppuccin_egui::set_theme(ui.ctx(), catppuccin_egui::MACCHIATO); - } - if ui.button("Mocha").clicked() { - catppuccin_egui::set_theme(ui.ctx(), catppuccin_egui::MOCHA); + ui.horizontal(|ui| { + for mode in Mode::iter() { + ui.selectable_value(&mut self.mode, mode, mode.to_string()); + ui.separator(); } }); + ui.separator(); - ui.menu_button("Code Theme", |ui| { - for t in luminol_config::SyntectTheme::iter() { - ui.radio_value( - &mut update_state.global_config.theme.syntect_theme, - t, - t.to_string(), - ); + 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.label("Code sample"); - ui.label(luminol_components::syntax_highlighting::highlight( - ui.ctx(), - update_state.global_config.theme, - r#" - class Foo < Array - end - def bar(baz) - end - print 1, 2.0 - puts [0x3, :4, '5'] - "#, - "rb", - )); - }); - - if ui - .button("Clear Loaded Textures") - .on_hover_text( - "You may need to reopen maps/windows for any changes to take effect.", - ) - .clicked() - { - update_state.graphics.image_cache.clear(); - update_state.graphics.atlas_cache.clear(); + ui.vertical(|ui| { + ui.label("Code sample"); + ui.label(luminol_components::syntax_highlighting::highlight( + ui.ctx(), + update_state.global_config.theme, + CODE_SAMPLE, + "rb", + )); + }); + }); + } } }); }