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;
|
||||
|
||||
use eframe::egui;
|
||||
use tools::Demo;
|
||||
//use tools::Demo;
|
||||
|
||||
|
||||
fn main() -> Result<(), eframe::Error> {
|
||||
|
@ -24,16 +24,21 @@ fn main() -> Result<(), eframe::Error> {
|
|||
//#[derive(Default)]
|
||||
struct MyApp {
|
||||
picked_path: Option<String>,
|
||||
code_editor: tools::code_editor::CodeEditor,
|
||||
code_open: bool,
|
||||
language: String,
|
||||
code: String,
|
||||
}
|
||||
|
||||
impl Default for MyApp {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
picked_path: None,
|
||||
code_editor: tools::code_editor::CodeEditor::default(), // Initialize CodeEditor
|
||||
code_open: true,
|
||||
language: "rs".into(),
|
||||
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 {
|
||||
ui.horizontal(|ui| {
|
||||
ui.label("Picked file:");
|
||||
|
@ -60,12 +63,29 @@ impl eframe::App for MyApp {
|
|||
});
|
||||
}
|
||||
|
||||
//~ let mut code_editor = CodeEditor::default();
|
||||
//~ code_editor.code = self.code.clone(); // Initialize code editor with MyApp's code
|
||||
//~ code_editor.language = self.language.clone();
|
||||
//~ code_editor.show(ctx, ui);
|
||||
//~
|
||||
self.code_editor.show(ctx, &mut self.code_open);
|
||||
//self.code_editor.show(ctx, &mut self.code_open);
|
||||
|
||||
let Self { language, code, .. } = self;
|
||||
|
||||
let theme = egui_extras::syntax_highlighting::CodeTheme::from_memory(ui.ctx());
|
||||
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| {
|
||||
ui.label("Terminal ?");
|
||||
|
|
Loading…
Reference in a new issue