Usage
Create an instance of [EguiMq
] and call its event-handler from
your miniquad::EventHandler
implementation.
In your miniquad::EventHandler::draw
method do this:
use miniquad as mq;
struct MyMiniquadApp {
egui_mq: egui_miniquad::EguiMq,
}
impl MyMiniquadApp {
fn new(ctx: &mut mq::Context) -> Self {
Self {
egui_mq: egui_miniquad::EguiMq::new(ctx),
}
}
fn ui(&mut self) {
egui::Window::new("Egui Window").show(self.egui_mq.egui_ctx(), |ui| {
ui.heading("Hello World!");
});
}
}
impl mq::EventHandler for MyMiniquadApp {
fn update(&mut self, _: &mut mq::Context) {}
fn draw(&mut self, ctx: &mut mq::Context) {
ctx.clear(Some((1., 1., 1., 1.)), None, None);
ctx.begin_default_pass(mq::PassAction::clear_color(0.0, 0.0, 0.0, 1.0));
ctx.end_render_pass();
self.egui_mq.begin_frame(ctx);
self.ui();
self.egui_mq.end_frame(ctx);
// Draw things behind egui here
self.egui_mq.draw(ctx);
// Draw things in front of egui here
ctx.commit_frame();
}
fn mouse_motion_event(&mut self, ctx: &mut mq::Context, x: f32, y: f32) {
self.egui_mq.mouse_motion_event(ctx, x, y);
}
fn mouse_wheel_event(&mut self, ctx: &mut mq::Context, dx: f32, dy: f32) {
self.egui_mq.mouse_wheel_event(ctx, dx, dy);
}
fn mouse_button_down_event(
&mut self,
ctx: &mut mq::Context,
mb: mq::MouseButton,
x: f32,
y: f32,
) {
self.egui_mq.mouse_button_down_event(ctx, mb, x, y);
}
fn mouse_button_up_event(
&mut self,
ctx: &mut mq::Context,
mb: mq::MouseButton,
x: f32,
y: f32,
) {
self.egui_mq.mouse_button_up_event(ctx, mb, x, y);
}
fn char_event(
&mut self,
_ctx: &mut mq::Context,
character: char,
_keymods: mq::KeyMods,
_repeat: bool,
) {
self.egui_mq.char_event(character);
}
fn key_down_event(
&mut self,
ctx: &mut mq::Context,
keycode: mq::KeyCode,
keymods: mq::KeyMods,
_repeat: bool,
) {
self.egui_mq.key_down_event(ctx, keycode, keymods);
}
fn key_up_event(&mut self, _ctx: &mut mq::Context, keycode: mq::KeyCode, keymods: mq::KeyMods) {
self.egui_mq.key_up_event(keycode, keymods);
}
}