✨ image loading works mew
This commit is contained in:
18
Cargo.toml
18
Cargo.toml
@@ -1,7 +1,14 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "application_catnip"
|
name = "application_catnip"
|
||||||
version = "0.0.0-develop"
|
version = "0.0.0-develop"
|
||||||
|
authors = ["lunarydess"]
|
||||||
|
license = "Apache-2.0"
|
||||||
edition = "2024"
|
edition = "2024"
|
||||||
|
rust-version = "1.85"
|
||||||
|
publish = false
|
||||||
|
|
||||||
|
[package.metadata.cargo-machete]
|
||||||
|
ignored = ["image"]
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
egui = "0.31"
|
egui = "0.31"
|
||||||
@@ -11,7 +18,12 @@ eframe = { version = "0.31", default-features = false, features = [
|
|||||||
"wayland", "wgpu"
|
"wayland", "wgpu"
|
||||||
] }
|
] }
|
||||||
rfd = "0.15"
|
rfd = "0.15"
|
||||||
env_logger = "0.11"
|
env_logger = { version = "0.11", default-features = false, features = [
|
||||||
|
"auto-color",
|
||||||
|
"humantime",
|
||||||
|
] }
|
||||||
serde = { version = "1", features = ["derive"] }
|
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-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"] }
|
||||||
|
|||||||
156
src/app.rs
156
src/app.rs
@@ -1,3 +1,4 @@
|
|||||||
|
use eframe::emath::Align;
|
||||||
use eframe::epaint::text::TextWrapMode;
|
use eframe::epaint::text::TextWrapMode;
|
||||||
use egui::ThemePreference;
|
use egui::ThemePreference;
|
||||||
use egui_code_editor::{CodeEditor, ColorTheme, Syntax, DEFAULT_THEMES};
|
use egui_code_editor::{CodeEditor, ColorTheme, Syntax, DEFAULT_THEMES};
|
||||||
@@ -20,7 +21,7 @@ pub struct CatnipApp {
|
|||||||
impl Default for CatnipApp {
|
impl Default for CatnipApp {
|
||||||
fn default() -> Self {
|
fn default() -> Self {
|
||||||
Self {
|
Self {
|
||||||
label: "Hello World!".to_owned(),
|
label: "println!(\"meow\");".to_owned(),
|
||||||
editor_theme: ColorTheme::default(),
|
editor_theme: ColorTheme::default(),
|
||||||
editor_syntax: Syntax::default(),
|
editor_syntax: Syntax::default(),
|
||||||
editor_text: "".to_owned(),
|
editor_text: "".to_owned(),
|
||||||
@@ -40,62 +41,83 @@ impl CatnipApp {
|
|||||||
|
|
||||||
impl eframe::App for CatnipApp {
|
impl eframe::App for CatnipApp {
|
||||||
fn update(&mut self, ctx: &egui::Context, _frame: &mut eframe::Frame) {
|
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
|
// top bar
|
||||||
egui::TopBottomPanel::top("top_panel").show(ctx, |ui| {
|
egui::TopBottomPanel::top("top_panel").show(ctx, |ui| {
|
||||||
egui::menu::bar(ui, |ui| {
|
egui::menu::bar(ui, |ui| {
|
||||||
let modal = Modal::new(ctx, "open folder modal :3");
|
ui.menu_button("File", |ui| {
|
||||||
modal.show(|ui| {
|
ui.menu_button("New …", |_| {});
|
||||||
modal.title(ui, "Hello world!");
|
ui.menu_button("Open …", |ui| {
|
||||||
modal.frame(ui, |ui| {
|
if ui.button("File").clicked()
|
||||||
modal.body(ui, "This is a modal.");
|
&& let Some(path) = rfd::FileDialog::new().pick_file()
|
||||||
});
|
{
|
||||||
modal.buttons(ui, |ui| {
|
self.editor_text =
|
||||||
if modal.button(ui, "close").clicked() {
|
fs::read_to_string(path.display().to_string()).unwrap();
|
||||||
println!("Hello world!")
|
ui.close_menu();
|
||||||
};
|
}
|
||||||
});
|
if ui.button("Folder").clicked() && !modal.is_open() {
|
||||||
});
|
modal.open();
|
||||||
|
ui.close_menu();
|
||||||
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);
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
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
|
// main content
|
||||||
egui::CentralPanel::default().show(ctx, |ui| {
|
egui::CentralPanel::default().show(ctx, |ui| {
|
||||||
ui.vertical_centered(|ui| {
|
ui.image(egui::include_image!("leaf.png"))
|
||||||
ui.horizontal(|ui| {
|
.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
|
// editor theme selector
|
||||||
egui::ComboBox::from_label("Theme")
|
egui::ComboBox::from_label("Theme")
|
||||||
.wrap_mode(TextWrapMode::Wrap)
|
.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 ♡");
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
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;
|
mod app;
|
||||||
pub use app::CatnipApp;
|
pub use app::CatnipApp;
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
use eframe::Renderer;
|
|
||||||
use application_catnip::CatnipApp;
|
use application_catnip::CatnipApp;
|
||||||
|
use eframe::Renderer;
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
env_logger::init();
|
env_logger::init();
|
||||||
@@ -13,7 +13,10 @@ fn main() {
|
|||||||
.with_min_inner_size([300.0, 220.0]),
|
.with_min_inner_size([300.0, 220.0]),
|
||||||
..Default::default()
|
..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");
|
.expect("TODO: panic message");
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user