Raylib integration for egui. The primary use case for this crate is a drop-in GUI library for 2D games made in Raylib.
- Add this crate as a dependency.
- Get coding!
use raylib::prelude::*;
use egui_raylib::RlEgui;
fn main() {
let (mut rl, thread) = raylib::init()
.size(640, 480)
.title("Hello, World")
.build();
// Use default input options.
let mut gui = RlEgui::default();
while !rl.window_should_close() {
// Create all UI components and prepare them for drawing.
gui.prepare(&mut rl, &thread, |ctx| {
// UI goes here...
egui::CentralPanel::default().show(&ctx, |ui| {
ui.label("Hello world!");
if ui.button("Click me").clicked() {
eprintln("You clicked me!");
}
});
});
let mut d = rl.begin_drawing(&thread);
d.clear_background(Color::WHITE);
d.draw_text("Hello, world!", 12, 12, 20, Color::BLACK);
// Draw the gui
gui.draw(&mut d);
}
}
The screenshot of another example, showcasing various widgets.
- raylib-rs: Rust-bindings for Raylib.
- egui
The following features will not be supported in this integration:
- Rendering arbitrary meshes.
- Paint callbacks.
The primary reason behind this is that this integration does not rely on egui to tessellate its entire UI-mesh, but rather traverses the output shape tree and calls corresponding raylib functions on a draw handle. If necessary, these features can be obtained by using egui's built-in tessellation functionality to generate primitives that can be rendered directly. This approach was not chosen to allow the ui to be rendered on any draw handle that supports clipping.