diff --git a/Cargo.toml b/Cargo.toml index 3eb54fd..ad54c6b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,7 +1,14 @@ [package] name = "application_catnip" version = "0.0.0-develop" +authors = ["lunarydess"] +license = "Apache-2.0" edition = "2024" +rust-version = "1.85" +publish = false + +[package.metadata.cargo-machete] +ignored = ["image"] [dependencies] egui = "0.31" @@ -11,7 +18,12 @@ eframe = { version = "0.31", default-features = false, features = [ "wayland", "wgpu" ] } rfd = "0.15" -env_logger = "0.11" +env_logger = { version = "0.11", default-features = false, features = [ + "auto-color", + "humantime", +] } serde = { version = "1", features = ["derive"] } -egui_code_editor = { git = "https://github.com/lunarydess/Application-Catnip-Editor.git", version = "0.3.0-develop" } -egui-modal = { git = "https://github.com/mkrueger/egui-modal.git", branch = "mkrueger/egui0.31"} +egui_code_editor = { git = "https://github.com/lunarydess/Application-Catnip-Editor.git", version = "0.3.0-develop", rev = "0754452" } +egui-modal = { git = "https://github.com/mkrueger/egui-modal.git", branch = "mkrueger/egui0.31" } +egui_extras = {version = "0.31", default-features = false, features = ["default", "all_loaders"]} +image = { version = "0.25", default-features = false, features = ["jpeg", "png"] } diff --git a/src/app.rs b/src/app.rs index 57b6926..07acaee 100644 --- a/src/app.rs +++ b/src/app.rs @@ -1,3 +1,4 @@ +use eframe::emath::Align; use eframe::epaint::text::TextWrapMode; use egui::ThemePreference; use egui_code_editor::{CodeEditor, ColorTheme, Syntax, DEFAULT_THEMES}; @@ -20,7 +21,7 @@ pub struct CatnipApp { impl Default for CatnipApp { fn default() -> Self { Self { - label: "Hello World!".to_owned(), + label: "println!(\"meow\");".to_owned(), editor_theme: ColorTheme::default(), editor_syntax: Syntax::default(), editor_text: "".to_owned(), @@ -40,62 +41,83 @@ impl CatnipApp { impl eframe::App for CatnipApp { fn update(&mut self, ctx: &egui::Context, _frame: &mut eframe::Frame) { + let modal = Modal::new(ctx, "open folder modal :3"); + modal.show(|ui| { + modal.title(ui, "Hello world!"); + modal.frame(ui, |ui| { + modal.body(ui, "This is a modal."); + }); + modal.buttons(ui, |ui| { + if modal.button(ui, "meow").clicked() { + }; + if modal.button(ui, "close").clicked() { + }; + }); + }); + // top bar egui::TopBottomPanel::top("top_panel").show(ctx, |ui| { egui::menu::bar(ui, |ui| { - let modal = Modal::new(ctx, "open folder modal :3"); - modal.show(|ui| { - modal.title(ui, "Hello world!"); - modal.frame(ui, |ui| { - modal.body(ui, "This is a modal."); - }); - modal.buttons(ui, |ui| { - if modal.button(ui, "close").clicked() { - println!("Hello world!") - }; - }); - }); - - let is_web = cfg!(target_arch = "wasm32"); - if !is_web { - ui.menu_button("File", |ui| { - ui.menu_button("New …", |_| {}); - ui.menu_button("Open …", |ui| { - if ui.button("File").clicked() { - if let Some(path) = rfd::FileDialog::new().pick_file() { - self.editor_text = - fs::read_to_string(path.display().to_string()).unwrap(); - } - } - if ui.button("Folder").clicked() { - if !modal.is_open() { - modal.open(); - } - } - }); - if ui.button("Quit").clicked() { - ctx.send_viewport_cmd(egui::ViewportCommand::Close); + ui.menu_button("File", |ui| { + ui.menu_button("New …", |_| {}); + ui.menu_button("Open …", |ui| { + if ui.button("File").clicked() + && let Some(path) = rfd::FileDialog::new().pick_file() + { + self.editor_text = + fs::read_to_string(path.display().to_string()).unwrap(); + ui.close_menu(); + } + if ui.button("Folder").clicked() && !modal.is_open() { + modal.open(); + ui.close_menu(); } }); - } - - let mut theme = ui.ctx().options(|opt| opt.theme_preference); - egui::ComboBox::from_label("") - .wrap_mode(TextWrapMode::Wrap) - .selected_text(format!("{:?}", theme)) - .show_ui(ui, |ui| { - ui.selectable_value(&mut theme, ThemePreference::System, "💻 System"); - ui.selectable_value(&mut theme, ThemePreference::Light, "☀ Light"); - ui.selectable_value(&mut theme, ThemePreference::Dark, "🌙 Dark"); - }); - ui.ctx().set_theme(theme); + if ui.button("Quit").clicked() { + ctx.send_viewport_cmd(egui::ViewportCommand::Close); + } + }); }); }); // main content egui::CentralPanel::default().show(ctx, |ui| { - ui.vertical_centered(|ui| { - ui.horizontal(|ui| { + ui.image(egui::include_image!("leaf.png")) + .on_hover_text_at_pointer("test meow"); + ui.with_layout(egui::Layout::left_to_right(Align::Max), |ui| { + CodeEditor::default() + .id_source("cat editor :3") + .with_fontsize(12.0) + .with_theme(self.editor_theme) + .with_syntax(self.editor_syntax.clone()) + .with_numlines(true) + .vscroll(true) + .stick_to_bottom(true) + .show(ui, &mut self.editor_text); + }); + + // header example: + // ui.heading("eframe template"); + + /* config examples with serde: + ui.horizontal(|ui| { + ui.label("Write something: "); + ui.te xt_edit_singleline(&mut self.label); + }); + + ui.add(egui::Slider::new(&mut self.value, 0.0..=10.0).text("value")); + */ + }); + + // bottom bar + egui::TopBottomPanel::bottom("bottom_panel").show(ctx, |ui| { + ui.horizontal(|ui| { + ui.spacing_mut().item_spacing.x = 0.0; + ui.label("made by "); + ui.hyperlink_to("lunarydess", "https://github.com/lunarydess"); + ui.label(" with ♡"); + + ui.with_layout(egui::Layout::right_to_left(Align::Center), |ui| { // editor theme selector egui::ComboBox::from_label("Theme") .wrap_mode(TextWrapMode::Wrap) @@ -129,36 +151,18 @@ impl eframe::App for CatnipApp { ); }); }); + + let mut theme = ui.ctx().options(|opt| opt.theme_preference); + egui::ComboBox::from_label("") + .wrap_mode(TextWrapMode::Wrap) + .selected_text(format!("{:?}", theme)) + .show_ui(ui, |ui| { + ui.selectable_value(&mut theme, ThemePreference::System, "💻 System"); + ui.selectable_value(&mut theme, ThemePreference::Light, "☀ Light"); + ui.selectable_value(&mut theme, ThemePreference::Dark, "🌙 Dark"); + }); + ui.ctx().set_theme(theme); }); - CodeEditor::default() - .id_source("cat editor :3") - .with_fontsize(12.0) - .with_theme(self.editor_theme) - .with_syntax(self.editor_syntax.clone()) - .with_numlines(true) - .show(ui, &mut self.editor_text); - }); - - // header example: - // ui.heading("eframe template"); - - /* config examples with serde: - ui.horizontal(|ui| { - ui.label("Write something: "); - ui.te xt_edit_singleline(&mut self.label); - }); - - ui.add(egui::Slider::new(&mut self.value, 0.0..=10.0).text("value")); - */ - }); - - // bottom bar - egui::TopBottomPanel::bottom("bottom_panel").show(ctx, |ui| { - ui.horizontal(|ui| { - ui.spacing_mut().item_spacing.x = 0.0; - ui.label("made by "); - ui.hyperlink_to("lunarydess", "https://github.com/lunarydess"); - ui.label(" with ♡"); }); }); } diff --git a/src/leaf.png b/src/leaf.png new file mode 100644 index 0000000..d524786 Binary files /dev/null and b/src/leaf.png differ diff --git a/src/lib.rs b/src/lib.rs index 77288a9..1146721 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,2 +1,5 @@ +#![feature(let_chains)] +#![feature(unboxed_closures)] + mod app; pub use app::CatnipApp; diff --git a/src/main.rs b/src/main.rs index 6970314..4d93e53 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,5 +1,5 @@ -use eframe::Renderer; use application_catnip::CatnipApp; +use eframe::Renderer; fn main() { env_logger::init(); @@ -13,7 +13,10 @@ fn main() { .with_min_inner_size([300.0, 220.0]), ..Default::default() }, - Box::new(|context| Ok(Box::new(CatnipApp::new(context)))), + Box::new(|context| { + egui_extras::install_image_loaders(&context.egui_ctx); + Ok(Box::::default()) + }), ) .expect("TODO: panic message"); }