[go: up one dir, main page]

egui 0.9.0

Simple, portable immediate mode GUI library for Rust
Documentation

egui core library

To quickly get started with egui, you can take a look at egui_template which uses eframe.

To create a GUI using egui you first need a [CtxRef] (by convention referred to by ctx). Then you add a [Window] or a [SidePanel] to get a [Ui], which is what you'll be using to add all the buttons and labels that you need.

Integrating with egui

To write your own integration for egui you need to do this:

# fn handle_output(_: egui::Output) {}
# fn paint(_: Vec<egui::ClippedMesh>) {}
# fn gather_input() -> egui::RawInput { egui::RawInput::default() }
let mut ctx = egui::CtxRef::default();

// Game loop:
loop {
let raw_input: egui::RawInput = gather_input();
ctx.begin_frame(raw_input);

egui::CentralPanel::default().show(&ctx, |ui| {
ui.label("Hello world!");
if ui.button("Click me").clicked() {
/* take some action here */
}
});

let (output, shapes) = ctx.end_frame();
let clipped_meshes = ctx.tessellate(shapes); // create triangles to paint
handle_output(output);
paint(clipped_meshes);
}

Using egui

To see what is possible to build we egui you can check out the online demo at https://emilk.github.io/egui/#demo.

Use one of [SidePanel], [TopPanel], [CentralPanel], [Window] or [Area] to get access to an [Ui] where you can put widgets. For example:

# let mut ctx = egui::CtxRef::default();
# ctx.begin_frame(Default::default());
egui::CentralPanel::default().show(&ctx, |ui| {
ui.add(egui::Label::new("Hello World!"));
ui.label("A shorter and more convenient way to add a label.");
if ui.button("Click me").clicked() {
/* take some action here */
}
});