2021-01-17 13:48:59 +00:00
//! eframe - the egui framework crate
2020-12-29 14:57:13 +00:00
//!
2021-01-17 09:52:01 +00:00
//! If you are planning to write an app for web or native,
2021-01-17 13:48:59 +00:00
//! and are happy with just using egui for all visuals,
2021-01-17 09:52:01 +00:00
//! Then `eframe` is for you!
2020-12-29 14:57:13 +00:00
//!
2021-10-18 18:19:43 +00:00
//! To get started, look at <https://github.com/emilk/eframe_template>.
2020-12-29 14:57:13 +00:00
//!
2021-01-17 09:52:01 +00:00
//! You write your application code for [`epi`] (implementing [`epi::App`]) and then
//! call from [`crate::run_native`] your `main.rs`, and/or call `eframe::start_web` from your `lib.rs`.
//!
2021-10-19 13:32:23 +00:00
//! `eframe` is implemented using [`egui_web`](https://github.com/emilk/egui/tree/master/egui_web) for web and
//! [`egui_glium`](https://github.com/emilk/egui/tree/master/egui_glium) or [`egui_glow`](https://github.com/emilk/egui/tree/master/egui_glow) for native.
2021-10-23 03:58:10 +00:00
//!
//! ## Usage, native:
//! ``` no_run
//! use eframe::{epi, egui};
//!
//! #[derive(Default)]
//! struct MyEguiApp {}
//!
//! impl epi::App for MyEguiApp {
//! fn name(&self) -> &str {
//! "My egui App"
//! }
//!
//! fn update(&mut self, ctx: &egui::CtxRef, frame: &mut epi::Frame<'_>) {
//! egui::CentralPanel::default().show(ctx, |ui| {
//! ui.heading("Hello World!");
//! });
//! }
//!}
//!
//! fn main() {
//! let app = MyEguiApp::default();
//! let native_options = eframe::NativeOptions::default();
//! eframe::run_native(Box::new(app), native_options);
//! }
//! ```
//!
//! ## Usage, web:
//! ``` no_run
//! #[cfg(target_arch = "wasm32")]
//! use wasm_bindgen::prelude::*;
//!
//! /// Call this once from the HTML.
//! #[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))
//! }
//! ```
2020-12-29 14:57:13 +00:00
2021-06-23 07:16:39 +00:00
// Forbid warnings in release builds:
#![ cfg_attr(not(debug_assertions), deny(warnings)) ]
2021-04-15 08:35:15 +00:00
#![ forbid(unsafe_code) ]
2021-09-08 22:16:06 +00:00
#![ warn(clippy::all, missing_crate_level_docs, missing_docs, rust_2018_idioms) ]
2021-10-23 03:58:10 +00:00
#![ allow(clippy::needless_doctest_main) ]
2020-12-29 14:57:13 +00:00
pub use { egui , epi } ;
2021-05-08 08:14:56 +00:00
#[ cfg(not(target_arch = " wasm32 " )) ]
pub use epi ::NativeOptions ;
2020-12-29 14:57:13 +00:00
// ----------------------------------------------------------------------------
// 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.
///
2021-06-03 16:56:26 +00:00
/// For performance reasons (on some browsers) the egui canvas does not, by default,
/// fill the whole width of the browser.
/// This can be changed by overriding [`epi::Frame::max_size_points`].
///
2021-10-23 03:58:10 +00:00
/// ### Usage, native:
/// ``` no_run
/// fn main() {
/// let app = MyEguiApp::default();
/// let native_options = eframe::NativeOptions::default();
/// eframe::run_native(Box::new(app), native_options);
/// }
/// ```
///
/// ### Web
2021-01-17 09:52:01 +00:00
/// ``` no_run
2020-12-29 14:57:13 +00:00
/// #[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
2021-10-23 03:58:10 +00:00
/// Call from `fn main` like this: `
/// ``` no_run
/// use eframe::{epi, egui};
///
/// #[derive(Default)]
/// struct MyEguiApp {}
///
/// impl epi::App for MyEguiApp {
/// fn name(&self) -> &str {
/// "My egui App"
/// }
///
/// fn update(&mut self, ctx: &egui::CtxRef, frame: &mut epi::Frame<'_>) {
/// egui::CentralPanel::default().show(ctx, |ui| {
/// ui.heading("Hello World!");
/// });
/// }
///}
///
/// fn main() {
/// let app = MyEguiApp::default();
/// let native_options = eframe::NativeOptions::default();
/// eframe::run_native(Box::new(app), native_options);
/// }
/// ```
2020-12-29 14:57:13 +00:00
#[ cfg(not(target_arch = " wasm32 " )) ]
2021-10-19 13:32:23 +00:00
#[ cfg(feature = " egui_glium " ) ]
2021-09-30 16:53:41 +00:00
pub fn run_native ( app : Box < dyn epi ::App > , native_options : epi ::NativeOptions ) -> ! {
2021-09-28 15:33:28 +00:00
egui_glium ::run ( app , & native_options )
2020-12-29 14:57:13 +00:00
}
2021-10-19 13:32:23 +00:00
2021-10-23 03:58:10 +00:00
/// Call from `fn main` like this: `
/// ``` no_run
/// fn main() {
/// let app = MyEguiApp::default();
/// let native_options = eframe::NativeOptions::default();
/// eframe::run_native(Box::new(app), native_options);
/// }
/// ```
2021-10-19 13:32:23 +00:00
#[ cfg(not(target_arch = " wasm32 " )) ]
#[ cfg(not(feature = " egui_glium " )) ] // make sure we still compile with `--all-features`
#[ cfg(feature = " egui_glow " ) ]
pub fn run_native ( app : Box < dyn epi ::App > , native_options : epi ::NativeOptions ) -> ! {
egui_glow ::run ( app , & native_options )
}
// disabled since we want to be able to compile with `--all-features`
// #[cfg(all(feature = "egui_glium", feature = "egui_glow"))]
// compile_error!("Enable either egui_glium or egui_glow, not both");
2021-10-19 19:40:55 +00:00
#[ cfg(not(any(feature = " egui_glium " , feature = " egui_glow " ))) ]
2021-10-19 13:32:23 +00:00
compile_error! ( " Enable either egui_glium or egui_glow " ) ;