Expand description
eframe - the egui
framework crate
If you are planning to write an app for web or native,
and want to use egui
for everything, then eframe
is for you!
To get started, see the examples.
To learn how to set up eframe
for web and native, go to https://github.com/emilk/eframe_template/ and follow the instructions there!
In short, you implement App
(especially App::update
) and then
call [crate::run_native
] from your main.rs
, and/or call eframe::start_web
from your lib.rs
.
Usage, native:
use eframe::egui;
fn main() {
let native_options = eframe::NativeOptions::default();
eframe::run_native("My egui App", native_options, Box::new(|cc| Box::new(MyEguiApp::new(cc))));
}
#[derive(Default)]
struct MyEguiApp {}
impl MyEguiApp {
fn new(cc: &eframe::CreationContext<'_>) -> Self {
// Customize egui here with cc.egui_ctx.set_fonts and cc.egui_ctx.set_visuals.
// Restore app state using cc.storage (requires the "persistence" feature).
// Use the cc.gl (a glow::Context) to create graphics shaders and buffers that you can use
// for e.g. egui::PaintCallback.
Self::default()
}
}
impl eframe::App for MyEguiApp {
fn update(&mut self, ctx: &egui::Context, frame: &mut eframe::Frame) {
egui::CentralPanel::default().show(ctx, |ui| {
ui.heading("Hello World!");
});
}
}
Usage, web:
#[cfg(target_arch = "wasm32")]
use wasm_bindgen::prelude::*;
/// Call this once from the HTML.
#[cfg(target_arch = "wasm32")]
#[wasm_bindgen]
pub async fn start(canvas_id: &str) -> Result<AppRunnerRef, eframe::wasm_bindgen::JsValue> {
let web_options = eframe::WebOptions::default();
eframe::start_web(canvas_id, web_options, Box::new(|cc| Box::new(MyEguiApp::new(cc)))).await
}
Feature flags
-
accesskit
(enabled by default) — Enable platform accessibility API implementations through AccessKit. -
dark-light
— Detect dark mode system preference usingdark-light
.See also [
NativeOptions::follow_system_theme
] and [NativeOptions::default_theme
]. -
default_fonts
(enabled by default) — If set, egui will useinclude_bytes!
to bundle some fonts. If you plan on specifying your own fonts you may disable this feature. -
glow
(enabled by default) — Useglow
for painting, viaegui_glow
. -
persistence
— Enable saving app state to disk. -
puffin
— Enable profiling with thepuffin
crate.Only enabled on native, because of the low resolution (1ms) of time keeping in browsers.
eframe
will callpuffin::GlobalProfiler::lock().new_frame()
for you -
web_screen_reader
— Enable screen reader support (requiresctx.options_mut(|o| o.screen_reader = true);
) on web.For other platforms, use the “accesskit” feature instead.
-
__screenshot
— If set, eframe will look for the env-varEFRAME_SCREENSHOT_TO
and write a screenshot to that location, and then quit. This is used to generate images for the examples. -
wgpu
— Usewgpu
for painting (viaegui-wgpu
). This overrides theglow
feature.
Optional dependencies
document-features
— Enable this when generating docs.
Re-exports
pub use egui;
pub use egui::emath;
pub use egui::epaint;
pub use egui_glow;
pub use glow;
pub use egui_wgpu;
pub use wgpu;
pub use wasm_bindgen;
pub use web_sys;
Modules
Structs
AppCreator
that can be used to setup and initialize your app.eframe
in a web page.Enums
eframe
.Constants
Traits
eframe
.