2024-09-04 23:16:22 +08:00
|
|
|
use eframe::egui;
|
2024-09-05 19:07:44 +08:00
|
|
|
use nac3parser::parser;
|
|
|
|
|
2024-09-04 23:16:22 +08:00
|
|
|
|
|
|
|
fn main() -> eframe::Result {
|
|
|
|
let options = eframe::NativeOptions {
|
2024-09-05 18:10:28 +08:00
|
|
|
viewport: egui::ViewportBuilder::default().with_inner_size([1024.0, 768.0]),
|
2024-09-04 23:16:22 +08:00
|
|
|
..Default::default()
|
|
|
|
};
|
|
|
|
|
2024-09-05 18:10:28 +08:00
|
|
|
let mut code = String::new();
|
2024-09-04 23:16:22 +08:00
|
|
|
|
2024-09-05 18:10:28 +08:00
|
|
|
eframe::run_simple_native("Cells", options, move |ctx, _frame| {
|
2024-09-05 19:07:44 +08:00
|
|
|
let submit_key = egui::KeyboardShortcut::new(egui::Modifiers::CTRL, egui::Key::Enter);
|
|
|
|
if ctx.input_mut(|i| i.consume_shortcut(&submit_key)) {
|
|
|
|
match parser::parse_program(code.as_str(), String::from("cell1").into()) {
|
|
|
|
Ok(parser_result) => println!("{:?}", parser_result),
|
|
|
|
Err(err) => println!("parse error: {}", err),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-09-04 23:16:22 +08:00
|
|
|
egui::CentralPanel::default().show(ctx, |ui| {
|
2024-09-05 18:10:28 +08:00
|
|
|
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, "Python");
|
|
|
|
layout_job.wrap.max_width = wrap_width;
|
|
|
|
layout_job.sections = layout_job
|
|
|
|
.sections
|
|
|
|
.iter()
|
|
|
|
.map(|layout_section| {
|
|
|
|
let mut section = layout_section.clone();
|
|
|
|
section.format.font_id = egui::FontId::monospace(16.0);
|
|
|
|
section
|
|
|
|
})
|
|
|
|
.collect();
|
|
|
|
ui.fonts(|f| f.layout_job(layout_job))
|
|
|
|
};
|
|
|
|
ui.add(
|
|
|
|
egui::TextEdit::multiline(&mut code)
|
|
|
|
.code_editor()
|
|
|
|
.desired_rows(4)
|
|
|
|
.lock_focus(true)
|
|
|
|
.desired_width(f32::INFINITY)
|
|
|
|
.layouter(&mut layouter)
|
|
|
|
.font(egui::FontId::monospace(16.0)),
|
|
|
|
);
|
2024-09-04 23:16:22 +08:00
|
|
|
});
|
|
|
|
})
|
|
|
|
}
|