added code editor
This commit is contained in:
parent
d0f933cd76
commit
166183aa9a
46
src/main.rs
46
src/main.rs
|
@ -2,7 +2,7 @@
|
||||||
mod tools;
|
mod tools;
|
||||||
|
|
||||||
use eframe::egui;
|
use eframe::egui;
|
||||||
use tools::Demo;
|
//use tools::Demo;
|
||||||
|
|
||||||
|
|
||||||
fn main() -> Result<(), eframe::Error> {
|
fn main() -> Result<(), eframe::Error> {
|
||||||
|
@ -24,16 +24,21 @@ fn main() -> Result<(), eframe::Error> {
|
||||||
//#[derive(Default)]
|
//#[derive(Default)]
|
||||||
struct MyApp {
|
struct MyApp {
|
||||||
picked_path: Option<String>,
|
picked_path: Option<String>,
|
||||||
code_editor: tools::code_editor::CodeEditor,
|
language: String,
|
||||||
code_open: bool,
|
code: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for MyApp {
|
impl Default for MyApp {
|
||||||
fn default() -> Self {
|
fn default() -> Self {
|
||||||
Self {
|
Self {
|
||||||
picked_path: None,
|
picked_path: None,
|
||||||
code_editor: tools::code_editor::CodeEditor::default(), // Initialize CodeEditor
|
language: "rs".into(),
|
||||||
code_open: true,
|
code: "// A very simple example\n\
|
||||||
|
fn main() {\n\
|
||||||
|
\tprintln!(\"Hello world!\");\n\
|
||||||
|
}\n\
|
||||||
|
"
|
||||||
|
.into(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -51,8 +56,6 @@ impl eframe::App for MyApp {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ui.label("Code");
|
|
||||||
|
|
||||||
if let Some(picked_path) = &self.picked_path {
|
if let Some(picked_path) = &self.picked_path {
|
||||||
ui.horizontal(|ui| {
|
ui.horizontal(|ui| {
|
||||||
ui.label("Picked file:");
|
ui.label("Picked file:");
|
||||||
|
@ -60,12 +63,29 @@ impl eframe::App for MyApp {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
//~ let mut code_editor = CodeEditor::default();
|
//self.code_editor.show(ctx, &mut self.code_open);
|
||||||
//~ code_editor.code = self.code.clone(); // Initialize code editor with MyApp's code
|
|
||||||
//~ code_editor.language = self.language.clone();
|
let Self { language, code, .. } = self;
|
||||||
//~ code_editor.show(ctx, ui);
|
|
||||||
//~
|
let theme = egui_extras::syntax_highlighting::CodeTheme::from_memory(ui.ctx());
|
||||||
self.code_editor.show(ctx, &mut self.code_open);
|
let mut layouter = |ui: &egui::Ui, string: &str, wrap_width: f32| {
|
||||||
|
let mut layout_job =
|
||||||
|
egui_extras::syntax_highlighting::highlight(ui.ctx(), &theme, string, language);
|
||||||
|
layout_job.wrap.max_width = wrap_width;
|
||||||
|
ui.fonts(|f| f.layout_job(layout_job))
|
||||||
|
};
|
||||||
|
|
||||||
|
egui::ScrollArea::vertical().show(ui, |ui| {
|
||||||
|
ui.add(
|
||||||
|
egui::TextEdit::multiline(code)
|
||||||
|
.font(egui::FontId::monospace(60.0)) // for cursor height
|
||||||
|
.code_editor()
|
||||||
|
.desired_rows(20)
|
||||||
|
.lock_focus(true)
|
||||||
|
.desired_width(f32::INFINITY)
|
||||||
|
.layouter(&mut layouter),
|
||||||
|
);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
egui::TopBottomPanel::bottom("terminal").show(ctx, |ui| {
|
egui::TopBottomPanel::bottom("terminal").show(ctx, |ui| {
|
||||||
ui.label("Terminal ?");
|
ui.label("Terminal ?");
|
||||||
|
|
Loading…
Reference in a new issue