Update to egui 0.18.0 (#58)
* WIP: Update to egui 0.18.0 (still unreleased) * Update to eframe/egui 0.18.0 * cargo update
This commit is contained in:
parent
341c9b06ff
commit
d44c4f5311
1060
Cargo.lock
generated
1060
Cargo.lock
generated
File diff suppressed because it is too large
Load diff
26
Cargo.toml
26
Cargo.toml
|
@ -15,26 +15,32 @@ path = "src/main.rs"
|
||||||
[lib]
|
[lib]
|
||||||
crate-type = ["cdylib", "rlib"]
|
crate-type = ["cdylib", "rlib"]
|
||||||
|
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
eframe = "0.17.0" # Gives us egui, epi and web+native backends
|
egui = "0.18.0"
|
||||||
|
eframe = { version = "0.18.0", features = ["persistence"] }
|
||||||
|
serde = { version = "1", features = ["derive"] } # You only need this if you want app persistence
|
||||||
|
|
||||||
serde = { version = "1", features = ["derive"], optional = true }
|
# native:
|
||||||
|
[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
|
||||||
|
tracing-subscriber = "0.3"
|
||||||
|
|
||||||
|
# web:
|
||||||
|
[target.'cfg(target_arch = "wasm32")'.dependencies]
|
||||||
|
console_error_panic_hook = "0.1.6"
|
||||||
|
tracing-wasm = "0.2"
|
||||||
|
|
||||||
[features]
|
|
||||||
default = []
|
|
||||||
persistence = ["eframe/persistence", "serde"] # Enable if you want to persist app state on shutdown
|
|
||||||
|
|
||||||
[profile.release]
|
[profile.release]
|
||||||
opt-level = 2 # fast and small wasm
|
opt-level = 2 # fast and small wasm
|
||||||
|
|
||||||
|
|
||||||
[patch.crates-io]
|
[patch.crates-io]
|
||||||
|
|
||||||
# If you want to use the bleeding edge version of `egui`:
|
# If you want to use the bleeding edge version of egui and eframe:
|
||||||
|
# egui = { git = "https://github.com/emilk/egui", branch = "master" }
|
||||||
# eframe = { git = "https://github.com/emilk/egui", branch = "master" }
|
# eframe = { git = "https://github.com/emilk/egui", branch = "master" }
|
||||||
|
|
||||||
# If you fork https://github.com/emilk/egui you can test with:
|
# If you fork https://github.com/emilk/egui you can test with:
|
||||||
|
# egui = { path = "../egui/egui" }
|
||||||
# eframe = { path = "../egui/eframe" }
|
# eframe = { path = "../egui/eframe" }
|
||||||
|
|
||||||
[target.'cfg(target_arch = "wasm32")'.dependencies]
|
|
||||||
console_error_panic_hook = "0.1.6"
|
|
||||||
tracing-wasm = "0.2"
|
|
||||||
|
|
|
@ -20,7 +20,7 @@ Change the name of the crate: Chose a good name for your project, and change the
|
||||||
* Change the `package.default-run` from `eframe_template_bin` to `your_crate_bin` (note the `_bin`!)
|
* Change the `package.default-run` from `eframe_template_bin` to `your_crate_bin` (note the `_bin`!)
|
||||||
* Change the `bin.name` from `eframe_template_bin` to `your_crate_bin` (note the `_bin`!)
|
* Change the `bin.name` from `eframe_template_bin` to `your_crate_bin` (note the `_bin`!)
|
||||||
* `main.rs`
|
* `main.rs`
|
||||||
* Change the `let app =…` line from `eframe_template::TemplateApp` to `your_crate::TemplateApp`
|
* Change `eframe_template::TemplateApp` to `your_crate::TemplateApp`
|
||||||
* `docs/index.html`
|
* `docs/index.html`
|
||||||
* Change the `<title>`
|
* Change the `<title>`
|
||||||
* Change the `<script src=…` line from `eframe_template.js` to `your_crate.js`
|
* Change the `<script src=…` line from `eframe_template.js` to `your_crate.js`
|
||||||
|
|
|
@ -51,8 +51,8 @@ TARGET=$(cargo metadata --format-version=1 | jq --raw-output .target_directory)
|
||||||
|
|
||||||
echo "Generating JS bindings for wasm…"
|
echo "Generating JS bindings for wasm…"
|
||||||
TARGET_NAME="${CRATE_NAME_SNAKE_CASE}.wasm"
|
TARGET_NAME="${CRATE_NAME_SNAKE_CASE}.wasm"
|
||||||
wasm-bindgen "${TARGET}/wasm32-unknown-unknown/${BUILD}/${TARGET_NAME}" \
|
WASM_PATH="${TARGET}/wasm32-unknown-unknown/${BUILD}/${TARGET_NAME}"
|
||||||
--out-dir docs --no-modules --no-typescript
|
wasm-bindgen "${WASM_PATH}" --out-dir docs --no-modules --no-typescript
|
||||||
|
|
||||||
if [[ "${FAST}" == false ]]; then
|
if [[ "${FAST}" == false ]]; then
|
||||||
echo "Optimizing wasm…"
|
echo "Optimizing wasm…"
|
||||||
|
|
File diff suppressed because it is too large
Load diff
Binary file not shown.
43
src/app.rs
43
src/app.rs
|
@ -1,14 +1,12 @@
|
||||||
use eframe::{egui, epi};
|
|
||||||
|
|
||||||
/// We derive Deserialize/Serialize so we can persist app state on shutdown.
|
/// We derive Deserialize/Serialize so we can persist app state on shutdown.
|
||||||
#[cfg_attr(feature = "persistence", derive(serde::Deserialize, serde::Serialize))]
|
#[derive(serde::Deserialize, serde::Serialize)]
|
||||||
#[cfg_attr(feature = "persistence", serde(default))] // if we add new fields, give them default values when deserializing old state
|
#[serde(default)] // if we add new fields, give them default values when deserializing old state
|
||||||
pub struct TemplateApp {
|
pub struct TemplateApp {
|
||||||
// Example stuff:
|
// Example stuff:
|
||||||
label: String,
|
label: String,
|
||||||
|
|
||||||
// this how you opt-out of serialization of a member
|
// this how you opt-out of serialization of a member
|
||||||
#[cfg_attr(feature = "persistence", serde(skip))]
|
#[serde(skip)]
|
||||||
value: f32,
|
value: f32,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -22,36 +20,31 @@ impl Default for TemplateApp {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl epi::App for TemplateApp {
|
impl TemplateApp {
|
||||||
fn name(&self) -> &str {
|
|
||||||
"eframe template"
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Called once before the first frame.
|
/// Called once before the first frame.
|
||||||
fn setup(
|
pub fn new(cc: &eframe::CreationContext<'_>) -> Self {
|
||||||
&mut self,
|
// This is also where you can customized the look at feel of egui using
|
||||||
_ctx: &egui::Context,
|
// `cc.egui_ctx.set_visuals` and `cc.egui_ctx.set_fonts`.
|
||||||
_frame: &epi::Frame,
|
|
||||||
_storage: Option<&dyn epi::Storage>,
|
|
||||||
) {
|
|
||||||
// Load previous app state (if any).
|
// Load previous app state (if any).
|
||||||
// Note that you must enable the `persistence` feature for this to work.
|
// Note that you must enable the `persistence` feature for this to work.
|
||||||
#[cfg(feature = "persistence")]
|
if let Some(storage) = cc.storage {
|
||||||
if let Some(storage) = _storage {
|
return eframe::get_value(storage, eframe::APP_KEY).unwrap_or_default();
|
||||||
*self = epi::get_value(storage, epi::APP_KEY).unwrap_or_default()
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
|
Default::default()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl eframe::App for TemplateApp {
|
||||||
/// Called by the frame work to save state before shutdown.
|
/// Called by the frame work to save state before shutdown.
|
||||||
/// Note that you must enable the `persistence` feature for this to work.
|
fn save(&mut self, storage: &mut dyn eframe::Storage) {
|
||||||
#[cfg(feature = "persistence")]
|
eframe::set_value(storage, eframe::APP_KEY, self);
|
||||||
fn save(&mut self, storage: &mut dyn epi::Storage) {
|
|
||||||
epi::set_value(storage, epi::APP_KEY, self);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Called each time the UI needs repainting, which may be many times per second.
|
/// Called each time the UI needs repainting, which may be many times per second.
|
||||||
/// Put your widgets into a `SidePanel`, `TopPanel`, `CentralPanel`, `Window` or `Area`.
|
/// Put your widgets into a `SidePanel`, `TopPanel`, `CentralPanel`, `Window` or `Area`.
|
||||||
fn update(&mut self, ctx: &egui::Context, frame: &epi::Frame) {
|
fn update(&mut self, ctx: &egui::Context, frame: &mut eframe::Frame) {
|
||||||
let Self { label, value } = self;
|
let Self { label, value } = self;
|
||||||
|
|
||||||
// Examples of how to create different panels and windows.
|
// Examples of how to create different panels and windows.
|
||||||
|
|
|
@ -1,5 +1,3 @@
|
||||||
#![forbid(unsafe_code)]
|
|
||||||
#![cfg_attr(not(debug_assertions), deny(warnings))] // Forbid warnings in release builds
|
|
||||||
#![warn(clippy::all, rust_2018_idioms)]
|
#![warn(clippy::all, rust_2018_idioms)]
|
||||||
|
|
||||||
mod app;
|
mod app;
|
||||||
|
@ -24,6 +22,5 @@ pub fn start(canvas_id: &str) -> Result<(), eframe::wasm_bindgen::JsValue> {
|
||||||
// Redirect tracing to console.log and friends:
|
// Redirect tracing to console.log and friends:
|
||||||
tracing_wasm::set_as_global_default();
|
tracing_wasm::set_as_global_default();
|
||||||
|
|
||||||
let app = TemplateApp::default();
|
eframe::start_web(canvas_id, Box::new(|cc| Box::new(TemplateApp::new(cc))))
|
||||||
eframe::start_web(canvas_id, Box::new(app))
|
|
||||||
}
|
}
|
||||||
|
|
14
src/main.rs
14
src/main.rs
|
@ -1,12 +1,16 @@
|
||||||
#![forbid(unsafe_code)]
|
|
||||||
#![cfg_attr(not(debug_assertions), deny(warnings))] // Forbid warnings in release builds
|
|
||||||
#![warn(clippy::all, rust_2018_idioms)]
|
#![warn(clippy::all, rust_2018_idioms)]
|
||||||
#![cfg_attr(not(debug_assertions), windows_subsystem = "windows")] //Hide console window in release builds on Windows, this blocks stdout.
|
#![cfg_attr(not(debug_assertions), windows_subsystem = "windows")] // hide console window on Windows in release
|
||||||
|
|
||||||
// When compiling natively:
|
// When compiling natively:
|
||||||
#[cfg(not(target_arch = "wasm32"))]
|
#[cfg(not(target_arch = "wasm32"))]
|
||||||
fn main() {
|
fn main() {
|
||||||
let app = eframe_template::TemplateApp::default();
|
// Log to stdout (if you run with `RUST_LOG=debug`).
|
||||||
|
tracing_subscriber::fmt::init();
|
||||||
|
|
||||||
let native_options = eframe::NativeOptions::default();
|
let native_options = eframe::NativeOptions::default();
|
||||||
eframe::run_native(Box::new(app), native_options);
|
eframe::run_native(
|
||||||
|
"eframe template",
|
||||||
|
native_options,
|
||||||
|
Box::new(|cc| Box::new(eframe_template::TemplateApp::new(cc))),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue