Skip to content
Snippets Groups Projects
Commit 4fc9b16b authored by Finn Bear's avatar Finn Bear
Browse files

Add syntax hylighting to code display.

parent b9d503dc
No related branches found
No related tags found
No related merge requests found
......@@ -265,6 +265,21 @@ dependencies = [
"libc",
]
[[package]]
name = "chrono"
version = "0.4.19"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "670ad68c9088c2a963aaa298cb369688cf3f9465ce5e2d4ca10e6e0098a1ce73"
dependencies = [
"js-sys",
"libc",
"num-integer",
"num-traits",
"time",
"wasm-bindgen",
"winapi",
]
[[package]]
name = "clipboard-win"
version = "3.1.1"
......@@ -623,6 +638,19 @@ dependencies = [
"winit",
]
[[package]]
name = "egui_demo_lib"
version = "0.17.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "43ed5e8c26d1d7f9f56e51f32469b13e9880fceda61199bd0a7cae79b88d5dd5"
dependencies = [
"chrono",
"egui",
"enum-map",
"epi",
"unicode_names2",
]
[[package]]
name = "egui_glow"
version = "0.17.0"
......@@ -668,6 +696,27 @@ dependencies = [
"bytemuck",
]
[[package]]
name = "enum-map"
version = "2.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0348b2a57c82f98b9dbd8098b1abb2416f221823d3e50cbe24eaebdd16896826"
dependencies = [
"enum-map-derive",
"serde",
]
[[package]]
name = "enum-map-derive"
version = "0.8.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a63b7a0ddec6f38dcec5e36257750b7a8fcaf4227e12ceb306e341d63634da05"
dependencies = [
"proc-macro2",
"quote",
"syn",
]
[[package]]
name = "enumflags2"
version = "0.7.5"
......@@ -817,6 +866,7 @@ name = "generative_art_cartoon"
version = "0.1.0"
dependencies = [
"eframe",
"egui_demo_lib",
"image",
"rand",
]
......@@ -1810,6 +1860,16 @@ dependencies = [
"syn",
]
[[package]]
name = "time"
version = "0.1.43"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ca8a50ef2360fbd1eeb0ecd46795a87a19024eb4b53c5dc916ca1fd95fe62438"
dependencies = [
"libc",
"winapi",
]
[[package]]
name = "tinyvec"
version = "1.6.0"
......@@ -1893,6 +1953,12 @@ version = "0.2.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8ccb82d61f80a663efe1f787a51b16b5a51e3314d6ac365b08639f52387b33f3"
[[package]]
name = "unicode_names2"
version = "0.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "eec8e807a365e5c972debc47b8f06d361b37b94cfd18d48f7adc715fb86404dd"
[[package]]
name = "url"
version = "2.2.2"
......
......@@ -5,5 +5,6 @@ edition = "2021"
[dependencies]
eframe = "0.17"
egui_demo_lib = "0.17"
image = {version = "0.24", default-features = false, features=["png"]}
rand = {version = "0.8"}
\ No newline at end of file
use eframe::egui::{Align2, Color32, Context, Vec2, Window};
use eframe::egui;
use eframe::egui::{Align2, Color32, Context, Vec2, Widget, Window};
#[derive(Clone)]
pub struct Code {
......@@ -42,7 +43,28 @@ impl Code {
.fixed_size(Vec2::splat(self.size_pixels))
.show(ctx, |ui| {
//let (_id, _rect) = ui.allocate_space(Vec2::splat(self.size_pixels));
ui.code_editor(&mut self.code.as_str());
let theme = egui_demo_lib::syntax_highlighting::CodeTheme::from_memory(ui.ctx());
let mut layouter = |ui: &egui::Ui, string: &str, wrap_width: f32| {
let mut layout_job = egui_demo_lib::syntax_highlighting::highlight(
ui.ctx(),
&theme,
string,
"rs",
);
layout_job.wrap_width = wrap_width;
ui.fonts().layout_job(layout_job)
};
egui::TextEdit::multiline(&mut self.code.as_str())
.font(egui::TextStyle::Monospace) // for cursor height
.code_editor()
//.desired_rows(10)
.lock_focus(true)
.desired_width(f32::INFINITY)
.layouter(&mut layouter)
.ui(ui);
});
}
}
......@@ -91,6 +91,10 @@ impl epi::App for Cartoon {
let small_style = style.text_styles.get_mut(&TextStyle::Small).unwrap();
small_style.size = 22.0;
}
{
let monospaced_style = style.text_styles.get_mut(&TextStyle::Monospace).unwrap();
monospaced_style.size = 22.0;
}
ctx.set_style(style);
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment