1
0
mirror of https://github.com/emilk/egui.git synced 2026-08-30 13:20:05 -04:00

[eframe] Make persistence, http and time optional features

Saves on compile times.
This commit is contained in:
Emil Ernerfeldt
2021-01-04 01:44:02 +01:00
parent 00269f96c0
commit 69d31a5e47
30 changed files with 412 additions and 303 deletions

View File

@@ -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(),

View File

@@ -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 {}