Compare commits
3 commits
master
...
update-to-
Author | SHA1 | Date | |
---|---|---|---|
1f5d99c050 | |||
3bc57f1bf5 | |||
edeb665e57 |
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]
|
||||
crate-type = ["cdylib", "rlib"]
|
||||
|
||||
|
||||
[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]
|
||||
opt-level = 2 # fast and small wasm
|
||||
|
||||
|
||||
[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" }
|
||||
|
||||
# If you fork https://github.com/emilk/egui you can test with:
|
||||
# egui = { path = "../egui/egui" }
|
||||
# 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 `bin.name` from `eframe_template_bin` to `your_crate_bin` (note the `_bin`!)
|
||||
* `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`
|
||||
* Change the `<title>`
|
||||
* 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…"
|
||||
TARGET_NAME="${CRATE_NAME_SNAKE_CASE}.wasm"
|
||||
wasm-bindgen "${TARGET}/wasm32-unknown-unknown/${BUILD}/${TARGET_NAME}" \
|
||||
--out-dir docs --no-modules --no-typescript
|
||||
WASM_PATH="${TARGET}/wasm32-unknown-unknown/${BUILD}/${TARGET_NAME}"
|
||||
wasm-bindgen "${WASM_PATH}" --out-dir docs --no-modules --no-typescript
|
||||
|
||||
if [[ "${FAST}" == false ]]; then
|
||||
echo "Optimizing wasm…"
|
||||
|
|
File diff suppressed because it is too large
Load diff
Binary file not shown.
41
src/app.rs
41
src/app.rs
|
@ -1,14 +1,12 @@
|
|||
use eframe::{egui, epi};
|
||||
|
||||
/// We derive Deserialize/Serialize so we can persist app state on shutdown.
|
||||
#[cfg_attr(feature = "persistence", derive(serde::Deserialize, serde::Serialize))]
|
||||
#[cfg_attr(feature = "persistence", serde(default))] // if we add new fields, give them default values when deserializing old state
|
||||
#[derive(serde::Deserialize, serde::Serialize)]
|
||||
#[serde(default)] // if we add new fields, give them default values when deserializing old state
|
||||
pub struct TemplateApp {
|
||||
// Example stuff:
|
||||
label: String,
|
||||
|
||||
// this how you opt-out of serialization of a member
|
||||
#[cfg_attr(feature = "persistence", serde(skip))]
|
||||
#[serde(skip)]
|
||||
value: f32,
|
||||
}
|
||||
|
||||
|
@ -22,36 +20,31 @@ impl Default for TemplateApp {
|
|||
}
|
||||
}
|
||||
|
||||
impl epi::App for TemplateApp {
|
||||
fn name(&self) -> &str {
|
||||
"eframe template"
|
||||
}
|
||||
|
||||
impl TemplateApp {
|
||||
/// Called once before the first frame.
|
||||
fn setup(
|
||||
&mut self,
|
||||
_ctx: &egui::Context,
|
||||
_frame: &epi::Frame,
|
||||
_storage: Option<&dyn epi::Storage>,
|
||||
) {
|
||||
pub fn new(cc: &eframe::CreationContext<'_>) -> Self {
|
||||
// This is also where you can customized the look at feel of egui using
|
||||
// `cc.egui_ctx.set_visuals` and `cc.egui_ctx.set_fonts`.
|
||||
|
||||
// Load previous app state (if any).
|
||||
// Note that you must enable the `persistence` feature for this to work.
|
||||
#[cfg(feature = "persistence")]
|
||||
if let Some(storage) = _storage {
|
||||
*self = epi::get_value(storage, epi::APP_KEY).unwrap_or_default()
|
||||
if let Some(storage) = cc.storage {
|
||||
return eframe::get_value(storage, eframe::APP_KEY).unwrap_or_default();
|
||||
}
|
||||
|
||||
Default::default()
|
||||
}
|
||||
}
|
||||
|
||||
impl eframe::App for TemplateApp {
|
||||
/// Called by the frame work to save state before shutdown.
|
||||
/// Note that you must enable the `persistence` feature for this to work.
|
||||
#[cfg(feature = "persistence")]
|
||||
fn save(&mut self, storage: &mut dyn epi::Storage) {
|
||||
epi::set_value(storage, epi::APP_KEY, self);
|
||||
fn save(&mut self, storage: &mut dyn eframe::Storage) {
|
||||
eframe::set_value(storage, eframe::APP_KEY, self);
|
||||
}
|
||||
|
||||
/// 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`.
|
||||
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;
|
||||
|
||||
// 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)]
|
||||
|
||||
mod app;
|
||||
|
@ -24,6 +22,5 @@ pub fn start(canvas_id: &str) -> Result<(), eframe::wasm_bindgen::JsValue> {
|
|||
// Redirect tracing to console.log and friends:
|
||||
tracing_wasm::set_as_global_default();
|
||||
|
||||
let app = TemplateApp::default();
|
||||
eframe::start_web(canvas_id, Box::new(app))
|
||||
eframe::start_web(canvas_id, Box::new(|cc| Box::new(TemplateApp::new(cc))))
|
||||
}
|
||||
|
|
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)]
|
||||
#![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:
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
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();
|
||||
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