From 70c6f4596a9cbc3d20d55c2e62caba5201d611f0 Mon Sep 17 00:00:00 2001 From: Emil Ernerfeldt Date: Wed, 24 Mar 2021 21:35:29 +0100 Subject: [PATCH] Add checkbox in demo app to turn screen reader on/off --- build_demo_web.sh | 8 +++++--- egui/src/context.rs | 3 +++ egui/src/memory.rs | 10 ++++++++-- egui_demo_app/Cargo.toml | 2 +- egui_demo_lib/src/wrap_app.rs | 10 +++++++++- egui_glium/src/backend.rs | 4 +++- egui_web/src/backend.rs | 4 +++- 7 files changed, 32 insertions(+), 9 deletions(-) diff --git a/build_demo_web.sh b/build_demo_web.sh index 4fab5395..a40772c2 100755 --- a/build_demo_web.sh +++ b/build_demo_web.sh @@ -13,8 +13,7 @@ rm -f docs/${CRATE_NAME}_bg.wasm echo "Building rust…" BUILD=release -FEATURES="http,persistence" # screen_reader is experimental -# FEATURES="http,persistence,screen_reader" # screen_reader is experimental +FEATURES="http,persistence,screen_reader" ( cd egui_demo_app && cargo build \ @@ -30,6 +29,9 @@ TARGET_NAME="${CRATE_NAME}.wasm" wasm-bindgen "target/wasm32-unknown-unknown/$BUILD/$TARGET_NAME" \ --out-dir docs --no-modules --no-typescript -echo "Finished: docs/${CRATE_NAME}.wasm" +# brew install wabt # to get wasm-strip +wasm-strip docs/${CRATE_NAME}_bg.wasm + +echo "Finished: docs/${CRATE_NAME}_bg.wasm" open http://localhost:8888/index.html diff --git a/egui/src/context.rs b/egui/src/context.rs index ae323cbd..2db63db3 100644 --- a/egui/src/context.rs +++ b/egui/src/context.rs @@ -357,6 +357,8 @@ impl Context { self.frame_state.lock().available_rect() } + /// Stores all the egui state. + /// If you want to store/restore egui, serialize this. pub fn memory(&self) -> MutexGuard<'_, Memory> { self.memory.lock() } @@ -365,6 +367,7 @@ impl Context { self.graphics.lock() } + /// What egui outputs each frame. pub fn output(&self) -> MutexGuard<'_, Output> { self.output.lock() } diff --git a/egui/src/memory.rs b/egui/src/memory.rs index 7966a9e8..7c140ecc 100644 --- a/egui/src/memory.rs +++ b/egui/src/memory.rs @@ -18,7 +18,7 @@ use epaint::color::{Color32, Hsva}; #[cfg_attr(feature = "persistence", derive(serde::Deserialize, serde::Serialize))] #[cfg_attr(feature = "persistence", serde(default))] pub struct Memory { - pub(crate) options: Options, + pub options: Options, /// new scale that will be applied at the start of the next frame pub(crate) new_pixels_per_point: Option, @@ -61,10 +61,11 @@ pub struct Memory { // ---------------------------------------------------------------------------- +/// Some global options that you can read and write. #[derive(Clone, Debug, Default)] #[cfg_attr(feature = "persistence", derive(serde::Deserialize, serde::Serialize))] #[cfg_attr(feature = "persistence", serde(default))] -pub(crate) struct Options { +pub struct Options { /// The default style for new `Ui`:s. #[cfg_attr(feature = "persistence", serde(skip))] pub(crate) style: std::sync::Arc