Browse Source

[demo] Make syntect an optional dependency

Adds a whopping 1.4 MB to the WASM
pull/151/head
Emil Ernerfeldt 4 years ago
parent
commit
e529bd3ea4
  1. 2
      egui_demo_lib/Cargo.toml
  2. 14
      egui_demo_lib/src/apps/http_app.rs

2
egui_demo_lib/Cargo.toml

@ -30,7 +30,7 @@ criterion = { version = "0.3", default-features = false }
[features]
default = []
http = ["image", "syntect", "epi/http"]
http = ["image", "epi/http"]
persistence = ["epi/persistence", "serde"]
[[bench]]

14
egui_demo_lib/src/apps/http_app.rs

@ -196,6 +196,7 @@ fn ui_resouce(
// ----------------------------------------------------------------------------
// Syntax highlighting:
#[cfg(feature = "syntect")]
fn syntax_highlighting(response: &Response) -> Option<ColoredText> {
let text = response.text.as_ref()?;
let extension_and_rest: Vec<&str> = response.url.rsplitn(2, '.').collect();
@ -204,8 +205,10 @@ fn syntax_highlighting(response: &Response) -> Option<ColoredText> {
}
/// Lines of text fragments
#[cfg(feature = "syntect")]
struct ColoredText(Vec<Vec<(syntect::highlighting::Style, String)>>);
#[cfg(feature = "syntect")]
impl ColoredText {
/// e.g. `text_with_extension("fn foo() {}", "rs")`
pub fn text_with_extension(text: &str, extension: &str) -> Option<ColoredText> {
@ -247,6 +250,17 @@ impl ColoredText {
}
}
#[cfg(not(feature = "syntect"))]
fn syntax_highlighting(_: &Response) -> Option<ColoredText> {
None
}
#[cfg(not(feature = "syntect"))]
struct ColoredText();
#[cfg(not(feature = "syntect"))]
impl ColoredText {
pub fn ui(&self, _ui: &mut egui::Ui) {}
}
// ----------------------------------------------------------------------------
// Texture/image handling is very manual at the moment.

Loading…
Cancel
Save