imgui-glfw-rs (0.13.2)
Installation
[registries.forgejo]
index = "sparse+ " # Sparse index
# index = " " # Git
[net]
git-fetch-with-cli = truecargo add imgui-glfw-rs@0.13.2 --registry forgejoAbout this package
ImGui input handling for GLFW
imgui-glfw-rs: GLFW Input handling for ImGui
GLFW input handling for imgui
Features
No features are enabled by default. Pick the renderer you need:
opengl— bundles theimgui-opengl-renderer-rscrate so a singleImguiGLFWvalue handles both input and rendering.vulkan— bundles theimgui-vulkan-renderer-rscrate and re-exports it for Vulkan-based rendering.
# OpenGL
imgui-glfw-rs = { version = "0.13.1", features = ["opengl"] }
# Vulkan
imgui-glfw-rs = { version = "0.13.1", features = ["vulkan"] }
Without either feature, ImguiGLFW handles input only — call update_cursors()
and your own renderer each frame instead of draw().
Prerequisites
You need a C compiler and CMake to build GLFW from source (handled automatically by the glfw-sys crate).
Debian / Ubuntu:
sudo apt install build-essential cmake libx11-dev libxrandr-dev libxinerama-dev libxcursor-dev libxi-dev libgl-dev
For the Vulkan example, also install:
sudo apt install libvulkan-dev
Windows:
Install CMake and a C compiler (MSVC via Visual Studio or MinGW). For the Vulkan example, install the Vulkan SDK.
How to use
OpenGL
use imgui_glfw_rs::glfw;
use imgui_glfw_rs::imgui;
use imgui_glfw_rs::ImguiGLFW;
fn main() {
// Initialize glfw with an OpenGL context and load GL functions.
// { ... }
let mut imgui_glfw = ImguiGLFW::new(&mut imgui, &mut window).unwrap();
while !window.should_close() {
let ui = imgui_glfw.frame(&mut window, &mut imgui);
// Draw your ui.
// { ... }
imgui_glfw.draw(&mut imgui, &mut window);
window.swap_buffers();
glfw.poll_events();
for (_, event) in glfw::flush_messages(&events) {
imgui_glfw.handle_event(&mut imgui, &event);
}
}
}
Vulkan
use imgui_glfw_rs::glfw;
use imgui_glfw_rs::imgui;
use imgui_glfw_rs::imgui_vulkan_renderer_rs::{Renderer, RendererCreateInfo};
use imgui_glfw_rs::ImguiGLFW;
fn main() {
// Initialize glfw with ClientApi(NoApi) and set up Vulkan
// (instance, device, swapchain, render pass, etc.).
// { ... }
let mut imgui_glfw = ImguiGLFW::new(&mut imgui, &mut window);
let mut renderer = Renderer::new(&mut imgui, &create_info).unwrap();
while !window.should_close() {
let ui = imgui_glfw.frame(&mut window, &mut imgui);
// Draw your ui.
// { ... }
imgui_glfw.update_cursors(&imgui, &mut window);
let draw_data = imgui.render();
// Record command buffer, begin render pass, then:
renderer.render(draw_data, command_buffer).unwrap();
glfw.poll_events();
for (_, event) in glfw::flush_messages(&events) {
imgui_glfw.handle_event(&mut imgui, &event);
}
}
}
See examples/hello_opengl.rs and examples/hello_vulkan.rs for complete working examples.
Current implemented things
- Mouse button press and release (event-based API)
- Cursor position movement (event-based API)
- Scroll movement (vertical and horizontal)
- Char input
- Key press and release
- Modifier handling
- Cursor icons (with change-detection optimization)
- Clipboard copying/pasting
- HiDPI / framebuffer scale support
- Window focus tracking
- Cursor enter/leave tracking
handle_event()returns whether imgui captured the event
Unimplemented things and known issues
- Gamepad / joystick input
Compiling and running the examples
git clone https://github.com/K4ugummi/imgui-glfw-rs.git
cd imgui-glfw-rs
cargo run --example hello_opengl --features opengl
# Vulkan example (requires Vulkan SDK)
cargo run --example hello_vulkan --features vulkan
Contributing
- Make some changes
- Run rustfmt for code style conformance
cargo fmt - Open a pull request
Thanks to
- The piston developers for maintaining the glfw crate.
- Gekkio for maintaining the imgui bindings for rust.
- You for using this crate and maybe even providing feedback
Dependencies
| ID | Version |
|---|---|
| ash | ^0.38 |
| gl | ^0.14.0 |
| glfw | ^0.62.0 |
| imgui | ^0.12.0 |
| imgui-opengl-renderer-rs | ^0.12.3 |
| imgui-vulkan-renderer-rs | ^0.1.1 |
| ash | ^0.38 |
| gl | ^0.14.0 |
Keywords
imgui
glfw
opengl
input
gui
Details
2026-11-03 13:10:09 +01:00
Assets (1)
Versions (2)
View all
Cargo
2
K4ugummi <stephan.schauerte@gmail.com>
MIT OR Apache-2.0
19 KiB
imgui-glfw-rs-0.13.2.crate
19 KiB