mirror of
https://github.com/emilk/egui.git
synced 2026-09-03 07:10:04 -04:00
Add syntax highlighing feature to egui_extras (#3333)
* Add syntax highlighing feature to egui_extras Enable "syntect" feature for great syntax highlighting of any language. If not a simple fallback is used that works fine for C++, Rust, Python * Check --no-default-features of egui_extras on CI * spelling * Fix building egui_extras without additional features
This commit is contained in:
@@ -45,7 +45,6 @@ impl super::View for About {
|
||||
}
|
||||
|
||||
fn about_immediate_mode(ui: &mut egui::Ui) {
|
||||
use crate::syntax_highlighting::code_view_ui;
|
||||
ui.style_mut().spacing.interact_size.y = 0.0; // hack to make `horizontal_wrapped` work better with text.
|
||||
|
||||
ui.horizontal_wrapped(|ui| {
|
||||
@@ -56,7 +55,7 @@ fn about_immediate_mode(ui: &mut egui::Ui) {
|
||||
});
|
||||
|
||||
ui.add_space(8.0);
|
||||
code_view_ui(
|
||||
crate::rust_view_ui(
|
||||
ui,
|
||||
r#"
|
||||
if ui.button("Save").clicked() {
|
||||
|
||||
@@ -67,7 +67,7 @@ impl super::View for CodeEditor {
|
||||
});
|
||||
}
|
||||
|
||||
let mut theme = crate::syntax_highlighting::CodeTheme::from_memory(ui.ctx());
|
||||
let mut theme = egui_extras::syntax_highlighting::CodeTheme::from_memory(ui.ctx());
|
||||
ui.collapsing("Theme", |ui| {
|
||||
ui.group(|ui| {
|
||||
theme.ui(ui);
|
||||
@@ -77,7 +77,7 @@ impl super::View for CodeEditor {
|
||||
|
||||
let mut layouter = |ui: &egui::Ui, string: &str, wrap_width: f32| {
|
||||
let mut layout_job =
|
||||
crate::syntax_highlighting::highlight(ui.ctx(), &theme, string, language);
|
||||
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))
|
||||
};
|
||||
|
||||
@@ -81,13 +81,11 @@ impl super::Demo for CodeExample {
|
||||
|
||||
impl super::View for CodeExample {
|
||||
fn ui(&mut self, ui: &mut egui::Ui) {
|
||||
use crate::syntax_highlighting::code_view_ui;
|
||||
|
||||
ui.vertical_centered(|ui| {
|
||||
ui.add(crate::egui_github_link_file!());
|
||||
});
|
||||
|
||||
code_view_ui(
|
||||
crate::rust_view_ui(
|
||||
ui,
|
||||
r"
|
||||
pub struct CodeExample {
|
||||
@@ -117,15 +115,15 @@ impl CodeExample {
|
||||
});
|
||||
});
|
||||
|
||||
code_view_ui(ui, " }\n}");
|
||||
crate::rust_view_ui(ui, " }\n}");
|
||||
|
||||
ui.separator();
|
||||
|
||||
code_view_ui(ui, &format!("{self:#?}"));
|
||||
crate::rust_view_ui(ui, &format!("{self:#?}"));
|
||||
|
||||
ui.separator();
|
||||
|
||||
let mut theme = crate::syntax_highlighting::CodeTheme::from_memory(ui.ctx());
|
||||
let mut theme = egui_extras::syntax_highlighting::CodeTheme::from_memory(ui.ctx());
|
||||
ui.collapsing("Theme", |ui| {
|
||||
theme.ui(ui);
|
||||
theme.store_in_memory(ui.ctx());
|
||||
@@ -135,7 +133,7 @@ impl CodeExample {
|
||||
|
||||
fn show_code(ui: &mut egui::Ui, code: &str) {
|
||||
let code = remove_leading_indentation(code.trim_start_matches('\n'));
|
||||
crate::syntax_highlighting::code_view_ui(ui, &code);
|
||||
crate::rust_view_ui(ui, &code);
|
||||
}
|
||||
|
||||
fn remove_leading_indentation(code: &str) -> String {
|
||||
|
||||
Reference in New Issue
Block a user