mirror of
https://github.com/emilk/egui.git
synced 2026-08-30 21:30:03 -04:00
[eframe] Make persistence, http and time optional features
Saves on compile times.
This commit is contained in:
@@ -16,47 +16,54 @@ include = [ "**/*.rs", "Cargo.toml"]
|
||||
crate-type = ["cdylib", "rlib"]
|
||||
|
||||
[dependencies]
|
||||
egui = { version = "0.6.0", path = "../egui", features = ["serde"] }
|
||||
epi = { version = "0.6.0", path = "../epi", features = ["serde", "serde_json"] }
|
||||
egui = { version = "0.6.0", path = "../egui" }
|
||||
epi = { version = "0.6.0", path = "../epi" }
|
||||
js-sys = "0.3"
|
||||
serde = "1"
|
||||
serde_json = "1"
|
||||
serde = { version = "1", optional = true }
|
||||
serde_json = { version = "1", optional = true }
|
||||
wasm-bindgen = "0.2"
|
||||
wasm-bindgen-futures = "0.4"
|
||||
|
||||
[features]
|
||||
default = []
|
||||
http = [
|
||||
"epi/http",
|
||||
"web-sys/Headers",
|
||||
"web-sys/Request",
|
||||
"web-sys/RequestInit",
|
||||
"web-sys/RequestMode",
|
||||
"web-sys/Response",
|
||||
]
|
||||
persistence = ["serde", "serde_json"]
|
||||
|
||||
[dependencies.web-sys]
|
||||
version = "0.3"
|
||||
features = [
|
||||
'Clipboard',
|
||||
'ClipboardEvent',
|
||||
'console',
|
||||
'CssStyleDeclaration',
|
||||
'DataTransfer',
|
||||
'Document',
|
||||
'DomRect',
|
||||
'Element',
|
||||
'Headers',
|
||||
'HtmlCanvasElement',
|
||||
'HtmlElement',
|
||||
'KeyboardEvent',
|
||||
'Location',
|
||||
'MouseEvent',
|
||||
'Navigator',
|
||||
'Performance',
|
||||
'Request',
|
||||
'RequestInit',
|
||||
'RequestMode',
|
||||
'Response',
|
||||
'Storage',
|
||||
'Touch',
|
||||
'TouchEvent',
|
||||
'TouchList',
|
||||
'WebGlBuffer',
|
||||
'WebGlProgram',
|
||||
'WebGlRenderingContext',
|
||||
'WebGlShader',
|
||||
'WebGlTexture',
|
||||
'WebGlUniformLocation',
|
||||
'WheelEvent',
|
||||
'Window',
|
||||
"Clipboard",
|
||||
"ClipboardEvent",
|
||||
"console",
|
||||
"CssStyleDeclaration",
|
||||
"DataTransfer",
|
||||
"Document",
|
||||
"DomRect",
|
||||
"Element",
|
||||
"HtmlCanvasElement",
|
||||
"HtmlElement",
|
||||
"KeyboardEvent",
|
||||
"Location",
|
||||
"MouseEvent",
|
||||
"Navigator",
|
||||
"Performance",
|
||||
"Storage",
|
||||
"Touch",
|
||||
"TouchEvent",
|
||||
"TouchList",
|
||||
"WebGlBuffer",
|
||||
"WebGlProgram",
|
||||
"WebGlRenderingContext",
|
||||
"WebGlShader",
|
||||
"WebGlTexture",
|
||||
"WebGlUniformLocation",
|
||||
"WheelEvent",
|
||||
"Window",
|
||||
]
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
use crate::*;
|
||||
|
||||
pub use egui::{pos2, Color32};
|
||||
use http::WebHttp;
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
@@ -144,7 +143,8 @@ pub struct AppRunner {
|
||||
pub(crate) needs_repaint: std::sync::Arc<NeedRepaint>,
|
||||
storage: LocalStorage,
|
||||
last_save_time: f64,
|
||||
http: Arc<WebHttp>,
|
||||
#[cfg(feature = "http")]
|
||||
http: Arc<http::WebHttp>,
|
||||
}
|
||||
|
||||
impl AppRunner {
|
||||
@@ -160,7 +160,8 @@ impl AppRunner {
|
||||
needs_repaint: Default::default(),
|
||||
storage,
|
||||
last_save_time: now_sec(),
|
||||
http: Arc::new(WebHttp {}),
|
||||
#[cfg(feature = "http")]
|
||||
http: Arc::new(http::WebHttp {}),
|
||||
})
|
||||
}
|
||||
|
||||
@@ -210,6 +211,7 @@ impl AppRunner {
|
||||
native_pixels_per_point: Some(native_pixels_per_point()),
|
||||
},
|
||||
tex_allocator: Some(&mut self.web_backend.painter),
|
||||
#[cfg(feature = "http")]
|
||||
http: self.http.clone(),
|
||||
output: &mut app_output,
|
||||
repaint_signal: self.needs_repaint.clone(),
|
||||
|
||||
@@ -9,6 +9,7 @@
|
||||
#![warn(clippy::all, rust_2018_idioms)]
|
||||
|
||||
pub mod backend;
|
||||
#[cfg(feature = "http")]
|
||||
pub mod http;
|
||||
pub mod webgl;
|
||||
|
||||
@@ -154,6 +155,7 @@ pub fn local_storage_remove(key: &str) {
|
||||
local_storage().map(|storage| storage.remove_item(key));
|
||||
}
|
||||
|
||||
#[cfg(feature = "persistence")]
|
||||
pub fn load_memory(ctx: &egui::Context) {
|
||||
if let Some(memory_string) = local_storage_get("egui_memory_json") {
|
||||
match serde_json::from_str(&memory_string) {
|
||||
@@ -167,6 +169,10 @@ pub fn load_memory(ctx: &egui::Context) {
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(not(feature = "persistence"))]
|
||||
pub fn load_memory(_: &egui::Context) {}
|
||||
|
||||
#[cfg(feature = "persistence")]
|
||||
pub fn save_memory(ctx: &egui::Context) {
|
||||
match serde_json::to_string(&*ctx.memory()) {
|
||||
Ok(json) => {
|
||||
@@ -178,6 +184,9 @@ pub fn save_memory(ctx: &egui::Context) {
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(not(feature = "persistence"))]
|
||||
pub fn save_memory(_: &egui::Context) {}
|
||||
|
||||
#[derive(Default)]
|
||||
pub struct LocalStorage {}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user