This crate provides support functions to simplify integrating imgui-rs with winit.
Using the library
In your initialization code call configure_keys
:
use imgui::ImGui;
# fn main() {
let mut imgui = ImGui::init();
imgui_winit_support::configure_keys(&mut imgui);
# }
In your main loop you should already be retrieving events from winit and handling them. All
you need to do is pass each event to imgui_winit_support
as well:
# use imgui::ImGui;
# use winit::EventsLoop;
# fn main() {
# let mut events_loop = EventsLoop::new();
# let mut imgui = ImGui::init();
# let window_hidpi_factor = 1.0;
# let app_hidpi_factor = 1.0;
events_loop.poll_events(|event| {
imgui_winit_support::handle_event(
&mut imgui,
&event,
window_hidpi_factor,
app_hidpi_factor
);
});
# }
Advanced use cases
In more advanced use cases you might want to handle and filter events yourself and call some of
the various smaller helper functions exported by the library.
For example, you might want to customize mouse wheel line scrolling amount:
# use imgui::ImGui;
# use winit::{EventsLoop, Event, WindowEvent, MouseScrollDelta, TouchPhase};
# fn main() {
# let mut events_loop = EventsLoop::new();
# let mut imgui = ImGui::init();
# let window_hidpi_factor = 1.0;
# let app_hidpi_factor = 1.0;
events_loop.poll_events(|event| {
imgui_winit_support::handle_event(
&mut imgui,
&event,
window_hidpi_factor,
app_hidpi_factor
);
if let Event::WindowEvent { event, .. } = event {
match event {
WindowEvent::MouseWheel {
delta: MouseScrollDelta::LineDelta(_, lines),
phase: TouchPhase::Moved,
..
} => {
imgui.set_mouse_wheel(lines * 10.0);
}
_ => ()
}
}
});
# }