✨ image loading works mew
This commit is contained in:
16
Cargo.toml
16
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_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"] }
|
||||
|
||||
110
src/app.rs
110
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,9 +41,6 @@ impl CatnipApp {
|
||||
|
||||
impl eframe::App for CatnipApp {
|
||||
fn update(&mut self, ctx: &egui::Context, _frame: &mut eframe::Frame) {
|
||||
// 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!");
|
||||
@@ -50,52 +48,76 @@ impl eframe::App for CatnipApp {
|
||||
modal.body(ui, "This is a modal.");
|
||||
});
|
||||
modal.buttons(ui, |ui| {
|
||||
if modal.button(ui, "meow").clicked() {
|
||||
};
|
||||
if modal.button(ui, "close").clicked() {
|
||||
println!("Hello world!")
|
||||
};
|
||||
});
|
||||
});
|
||||
|
||||
let is_web = cfg!(target_arch = "wasm32");
|
||||
if !is_web {
|
||||
// top bar
|
||||
egui::TopBottomPanel::top("top_panel").show(ctx, |ui| {
|
||||
egui::menu::bar(ui, |ui| {
|
||||
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() {
|
||||
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() {
|
||||
if !modal.is_open() {
|
||||
if ui.button("Folder").clicked() && !modal.is_open() {
|
||||
modal.open();
|
||||
}
|
||||
ui.close_menu();
|
||||
}
|
||||
});
|
||||
if ui.button("Quit").clicked() {
|
||||
ctx.send_viewport_cmd(egui::ViewportCommand::Close);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
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);
|
||||
});
|
||||
});
|
||||
|
||||
// main content
|
||||
egui::CentralPanel::default().show(ctx, |ui| {
|
||||
ui.vertical_centered(|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 {
|
||||
);
|
||||
});
|
||||
});
|
||||
});
|
||||
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);
|
||||
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.add(egui::Slider::new(&mut self.value, 0.0..=10.0).text("value"));
|
||||
*/
|
||||
ui.ctx().set_theme(theme);
|
||||
});
|
||||
|
||||
// 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 ♡");
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
BIN
src/leaf.png
Normal file
BIN
src/leaf.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 42 KiB |
@@ -1,2 +1,5 @@
|
||||
#![feature(let_chains)]
|
||||
#![feature(unboxed_closures)]
|
||||
|
||||
mod app;
|
||||
pub use app::CatnipApp;
|
||||
|
||||
@@ -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::<CatnipApp>::default())
|
||||
}),
|
||||
)
|
||||
.expect("TODO: panic message");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user