1
0
mirror of https://github.com/emilk/egui.git synced 2026-08-29 04:40:03 -04:00

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

This commit is contained in:
Emil Ernerfeldt
2020-12-29 15:57:13 +01:00
parent d7459bc13d
commit 84414e62a3
14 changed files with 118 additions and 32 deletions

27
eframe/Cargo.toml Normal file
View File

@@ -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 Normal file
View File

@@ -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 Normal file
View File

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