Skip to content

Commit

Permalink
Sorta setup appearance window
Browse files Browse the repository at this point in the history
  • Loading branch information
melody-rs committed Nov 24, 2023
1 parent d46ac12 commit 23ee401
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 48 deletions.
19 changes: 19 additions & 0 deletions crates/ui/assets/code_sample.rb
Original file line number Diff line number Diff line change
@@ -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']
95 changes: 47 additions & 48 deletions crates/ui/src/windows/appearance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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",
));
});
});
}
}
});
}
Expand Down

0 comments on commit 23ee401

Please sign in to comment.