Crate imgui_glutin_support

Source
Expand description

This crate provides support functions to simplify integrating imgui-rs with glutin.

§Using the library

In your initialization code call configure_keys:

use imgui::ImGui;

let mut imgui = ImGui::init();
imgui_glutin_support::configure_keys(&mut imgui);

In your main loop you should already be retrieving events from glutin and handling them. All you need to do is pass each event to imgui_glutin_support as well:

events_loop.poll_events(|event| {
    // do application-specific stuff with event

    imgui_glutin_support::handle_event(&mut imgui, &event);
});

§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:

events_loop.poll_events(|event| {
    // do application-specific stuff with event

    // default handling for events
    imgui_glutin_support::handle_event(&mut imgui, &event);

    // Scroll 10 times the pixels per line by handling LineDelta events again and
    // overriding the mouse wheel value
    if let Event::WindowEvent { event, .. } = event {
        match event {
            WindowEvent::MouseWheel {
                delta: MouseScrollDelta::LineDelta(_, lines),
                phase: TouchPhase::Moved,
                ..
            } => {
                imgui.set_mouse_wheel(lines * 10.0);
            }
            _ => ()
        }
    }
});

Functions§

configure_keys
Configure imgui key map with glutin VirtualKeyCode values
get_frame_size
Get the current frame size for imgui frame rendering.
handle_event
Update imgui state from glutin event
handle_keyboard_input
Update imgui keyboard state
handle_modifiers
Update imgui keyboard modifier state
handle_mouse_button_state
Update imgui mouse button state
handle_mouse_scroll_delta
Update imgui mouse wheel position
handle_window_event
Update imgui state from glutin window event
update_mouse_cursor
Update glutin window mouse cursor state