docs.rs failed to build imgui-winit-support-0.11.0
Please check the build logs for more information.
See Builds for ideas on how to fix a failed build, or Metadata for how to configure docs.rs builds.
If you believe this is docs.rs' fault, open an issue.
Please check the build logs for more information.
See Builds for ideas on how to fix a failed build, or Metadata for how to configure docs.rs builds.
If you believe this is docs.rs' fault, open an issue.
Visit the last successful build:
imgui-winit-support-0.8.2
This crate provides a winit-based backend platform for imgui-rs.
A backend platform handles window/input device events and manages their state.
Using the library
There are five things you need to do to use this library correctly:
- Initialize a
WinitPlatform
instance - Attach it to a winit
Window
- Pass events to the platform (every frame)
- Call frame preparation callback (every frame)
- Call render preparation callback (every frame)
Complete example (without a renderer)
use imgui::Context;
use imgui_winit_support::{HiDpiMode, WinitPlatform};
use std::time::Instant;
use winit::event::{Event, WindowEvent};
use winit::event_loop::{ControlFlow, EventLoop};
use winit::window::Window;
let mut event_loop = EventLoop::new();
let mut window = Window::new(&event_loop).unwrap();
let mut imgui = Context::create();
// configure imgui-rs Context if necessary
let mut platform = WinitPlatform::init(&mut imgui); // step 1
platform.attach_window(imgui.io_mut(), &window, HiDpiMode::Default); // step 2
let mut last_frame = Instant::now();
let mut run = true;
event_loop.run(move |event, _, control_flow| {
match event {
Event::NewEvents(_) => {
// other application-specific logic
let now = Instant::now();
imgui.io_mut().update_delta_time(now - last_frame);
last_frame = now;
},
Event::MainEventsCleared => {
// other application-specific logic
platform.prepare_frame(imgui.io_mut(), &window) // step 4
.expect("Failed to prepare frame");
window.request_redraw();
}
Event::RedrawRequested(_) => {
let ui = imgui.frame();
// application-specific rendering *under the UI*
// construct the UI
platform.prepare_render(&ui, &window); // step 5
// render the UI with a renderer
let draw_data = imgui.render();
// renderer.render(..., draw_data).expect("UI rendering failed");
// application-specific rendering *over the UI*
},
Event::WindowEvent { event: WindowEvent::CloseRequested, .. } => {
*control_flow = ControlFlow::Exit;
}
// other application-specific event handling
event => {
platform.handle_event(imgui.io_mut(), &window, &event); // step 3
// other application-specific event handling
}
}
})