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 fn start(canvas_id: &str) -> Result<(), eframe::wasm_bindgen::JsValue> {
    eframe::start_web(canvas_id, Box::new(|cc| Box::new(MyApp::new(cc))))
}

Re-exports

pub use egui;
pub use egui::emath;
pub use egui::epaint;
pub use glow;

Structs

Data that is passed to AppCreator that can be used to setup and initialize your app.

Represents the surroundings of your app.

Image data for an application icon.

Information about the integration passed to the use app each frame.

Information about the URL.

Options controlling the behavior of a native window.

Information about the web environment (if applicable).

Constants

Storage key used for app

Traits

Implement this trait to write apps that can be compiled for both web/wasm and desktop/native using eframe.

A place where you can store custom data in a way that persists when you restart the app.

Functions

Get and deserialize the RON stored at the given key.

This is how you start a native (desktop) app.

Serialize the given value as RON and store with the given key.

Type Definitions

This is how your app is created.