2024-09-04 23:16:22 +08:00
|
|
|
use eframe::egui;
|
|
|
|
|
|
|
|
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-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
|
|
|
});
|
|
|
|
})
|
|
|
|
}
|