Browse Source

Add new crate `eframe` which wraps egui, epi, egui_web and egui_glium

pull/92/head
Emil Ernerfeldt 4 years ago
parent
commit
84414e62a3
  1. 20
      Cargo.lock
  2. 27
      eframe/Cargo.toml
  3. 7
      eframe/README.md
  4. 54
      eframe/src/lib.rs
  5. 15
      egui_demo/Cargo.toml
  6. 5
      egui_demo/src/lib.rs
  7. 2
      egui_demo/src/main.rs
  8. 2
      egui_web/src/backend.rs
  9. 3
      egui_web/src/lib.rs
  10. 2
      epi/Cargo.toml
  11. 2
      epi/src/lib.rs
  12. 3
      example_web/Cargo.toml
  13. 1
      example_web/src/example_app.rs
  14. 7
      example_web/src/lib.rs

20
Cargo.lock

@ -620,6 +620,16 @@ version = "1.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9ea835d29036a4087793836fa931b08837ad5e957da9e23886b29586fb9b6650"
[[package]]
name = "eframe"
version = "0.6.0"
dependencies = [
"egui",
"egui_glium",
"egui_web",
"epi",
]
[[package]]
name = "egui"
version = "0.6.0"
@ -635,14 +645,9 @@ dependencies = [
name = "egui_demo"
version = "0.1.0"
dependencies = [
"egui",
"eframe",
"egui_demo_lib",
"egui_glium",
"egui_web",
"epi",
"js-sys",
"serde",
"wasm-bindgen",
]
[[package]]
@ -702,9 +707,8 @@ dependencies = [
name = "example_web"
version = "0.1.0"
dependencies = [
"egui",
"eframe",
"egui_web",
"epi",
"image",
"js-sys",
"serde",

27
eframe/Cargo.toml

@ -0,0 +1,27 @@
[package]
name = "eframe"
version = "0.6.0"
authors = ["Emil Ernerfeldt <emil.ernerfeldt@gmail.com>"]
description = "Egui Framework - write GUI apps that compiles to web and/or natively"
edition = "2018"
homepage = "https://github.com/emilk/egui"
license = "MIT OR Apache-2.0"
readme = "README.md"
repository = "https://github.com/emilk/egui"
categories = ["gui", "graphics"]
keywords = ["egui", "gui", "gamedev"]
include = [ "**/*.rs", "Cargo.toml"]
[lib]
[dependencies]
egui = { version = "0.6.0", path = "../egui", features = ["serde"] }
epi = { version = "0.6.0", path = "../epi", features = ["serde", "serde_json"] }
# For compiling natively:
[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
egui_glium = { path = "../egui_glium" }
# For compiling to web:
[target.'cfg(target_arch = "wasm32")'.dependencies]
egui_web = { path = "../egui_web" }

7
eframe/README.md

@ -0,0 +1,7 @@
# Egui Framework
This aims to be the entry-level crate if you want to write an Egui App.
`eframe` calls into your code (it is a framework) and supports web apps (via `egui_web`) and native apps (via `egui_glium`).
`eframe` is a very thin crate that re-exports `egui`, `epi` and thin wrappers over the backends.

54
eframe/src/lib.rs

@ -0,0 +1,54 @@
//! Backend-agnostic interface for writing apps using Egui.
//!
//! Egui is a GUI library, which can be plugged in to e.g. a game engine.
//!
//! This crate provides a common interface for programming an app, using Egui,
//! so you can then easily plug it in to a backend such as `egui_web` or `egui_glium`.
//!
//! This crate is primarily used by the `egui_web` and `egui_glium` crates.
#![forbid(unsafe_code)]
#![cfg_attr(not(debug_assertions), deny(warnings))] // Forbid warnings in release builds
#![warn(clippy::all)]
pub use {egui, epi};
// ----------------------------------------------------------------------------
// When compiling for web
#[cfg(target_arch = "wasm32")]
pub use egui_web::wasm_bindgen;
/// Install event listeners to register different input events
/// and start running the given app.
///
/// Usage:
/// ``` ignore
/// #[cfg(target_arch = "wasm32")]
/// use wasm_bindgen::prelude::*;
///
/// /// This is the entry-point for all the web-assembly.
/// /// This is called once from the HTML.
/// /// It loads the app, installs some callbacks, then returns.
/// /// You can add more callbacks like this if you want to call in to your code.
/// #[cfg(target_arch = "wasm32")]
/// #[wasm_bindgen]
/// pub fn start(canvas_id: &str) -> Result<(), eframe::wasm_bindgen::JsValue> {
/// let app = MyEguiApp::default();
/// eframe::start_web(canvas_id, Box::new(app))
/// }
/// ```
#[cfg(target_arch = "wasm32")]
pub fn start_web(canvas_id: &str, app: Box<dyn epi::App>) -> Result<(), wasm_bindgen::JsValue> {
egui_web::start(canvas_id, app)?;
Ok(())
}
// ----------------------------------------------------------------------------
// When compiling natively
/// Call from main as `eframe::run_native(Box::new(MyEguiApp::default()))`
#[cfg(not(target_arch = "wasm32"))]
pub fn run_native(app: Box<dyn epi::App>) {
egui_glium::run(app)
}

15
egui_demo/Cargo.toml

@ -9,17 +9,6 @@ edition = "2018"
crate-type = ["cdylib", "rlib"]
[dependencies]
egui = { version = "0.6.0", path = "../egui", features = ["serde"] }
egui_demo_lib = { path = "../egui_demo_lib" }
epi = { version = "0.6.0", path = "../epi", features = ["serde", "serde_json"] }
eframe = { version = "0.6.0", path = "../eframe"}
egui_demo_lib = { version = "0.6.0", path = "../egui_demo_lib"}
serde = { version = "1", features = ["derive"] }
# For compiling natively:
[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
egui_glium = { path = "../egui_glium" }
# For compiling to web:
[target.'cfg(target_arch = "wasm32")'.dependencies]
egui_web = { path = "../egui_web" }
js-sys = "0.3"
wasm-bindgen = "0.2"

5
egui_demo/src/lib.rs

@ -3,7 +3,7 @@
#![warn(clippy::all)]
#[cfg(target_arch = "wasm32")]
use wasm_bindgen::prelude::*;
use eframe::wasm_bindgen::{self, prelude::*};
/// This is the entry-point for all the web-assembly.
/// This is called once from the HTML.
@ -13,6 +13,5 @@ use wasm_bindgen::prelude::*;
#[wasm_bindgen]
pub fn start(canvas_id: &str) -> Result<(), wasm_bindgen::JsValue> {
let app = egui_demo_lib::DemoApp::default();
egui_web::start(canvas_id, Box::new(app))?;
Ok(())
eframe::start_web(canvas_id, Box::new(app))
}

2
egui_demo/src/main.rs

@ -5,5 +5,5 @@
// When compiling natively:
fn main() {
let app = egui_demo_lib::DemoApp::default();
egui_glium::run(Box::new(app));
eframe::run_native(Box::new(app));
}

2
egui_web/src/backend.rs

@ -219,7 +219,7 @@ impl AppRunner {
}
/// Install event listeners to register different input events
/// and starts running the given app.
/// and start running the given app.
pub fn start(canvas_id: &str, app: Box<dyn epi::App>) -> Result<AppRunnerRef, JsValue> {
let backend = WebBackend::new(canvas_id)?;
let runner = AppRunner::new(backend, app)?;

3
egui_web/src/lib.rs

@ -8,6 +8,9 @@ pub mod webgl;
pub use backend::*;
pub use wasm_bindgen;
pub use web_sys;
use egui::mutex::Mutex;
use std::sync::Arc;
use wasm_bindgen::prelude::*;

2
epi/Cargo.toml

@ -9,7 +9,7 @@ license = "MIT OR Apache-2.0"
readme = "README.md"
repository = "https://github.com/emilk/egui"
categories = ["gui", "graphics"]
keywords = ["glium", "egui", "gui", "gamedev"]
keywords = ["egui", "gui", "gamedev"]
include = [ "**/*.rs", "Cargo.toml"]
[lib]

2
epi/src/lib.rs

@ -50,6 +50,8 @@
unused_doc_comments,
)]
pub use egui; // Re-export for user convenience
// ----------------------------------------------------------------------------
/// Implement this trait to write apps that can be compiled both natively using the [`egui_glium`](https://crates.io/crates/egui_glium) crate,

3
example_web/Cargo.toml

@ -9,9 +9,8 @@ edition = "2018"
crate-type = ["cdylib", "rlib"]
[dependencies]
egui = { path = "../egui", features = ["serde"] }
eframe = { path = "../eframe" }
egui_web = { path = "../egui_web" }
epi = { version = "0.6.0", path = "../epi", features = ["serde", "serde_json"] }
image = { version = "0.23", default_features = false, features = ["jpeg", "png"] }
js-sys = "0.3"
serde = { version = "1", features = ["derive"] }

1
example_web/src/example_app.rs

@ -1,3 +1,4 @@
use eframe::{egui, epi};
use egui_web::fetch::Response;
use std::sync::mpsc::Receiver;

7
example_web/src/lib.rs

@ -4,15 +4,16 @@
mod example_app;
use wasm_bindgen::prelude::*;
#[cfg(target_arch = "wasm32")]
use eframe::wasm_bindgen::{self, prelude::*};
/// This is the entry-point for all the web-assembly.
/// This is called once from the HTML.
/// It loads the app, installs some callbacks, then returns.
/// You can add more callbacks like this if you want to call in to your code.
#[cfg(target_arch = "wasm32")]
#[wasm_bindgen]
pub fn start(canvas_id: &str) -> Result<(), wasm_bindgen::JsValue> {
let app = example_app::ExampleApp::default();
egui_web::start(canvas_id, Box::new(app))?;
Ok(())
eframe::start_web(canvas_id, Box::new(app))
}

Loading…
Cancel
Save