1pub mod platform;
2pub mod renderer;
3pub mod utils;
4
5use platform::Platform;
6use renderer::Renderer;
7
8pub struct ImGuiSdl3 {
9 imgui_context: imgui::Context,
10 platform: Platform,
11 renderer: Renderer,
12}
13
14impl ImGuiSdl3 {
15 pub fn new<T>(device: &sdl3::gpu::Device, window: &sdl3::video::Window, ctx_configure: T) -> Self
16 where
17 T: Fn(&mut imgui::Context),
18 {
19 let mut imgui_context = imgui::Context::create();
20 ctx_configure(&mut imgui_context);
21
22 let platform = Platform::new(&mut imgui_context);
23 let renderer = Renderer::new(device, window, &mut imgui_context).unwrap();
24
25 Self {
26 imgui_context,
27 platform,
28 renderer,
29 }
30 }
31
32 pub fn handle_event(&mut self, event: &sdl3::event::Event) {
33 self.platform.handle_event(&mut self.imgui_context, event);
34 }
35
36 pub fn render<T>(
37 &mut self,
38 sdl_context: &mut sdl3::Sdl,
39 device: &sdl3::gpu::Device,
40 window: &sdl3::video::Window,
41 event_pump: &sdl3::EventPump,
42 draw_callback: T,
43 ) where
44 T: Fn(&mut imgui::Ui),
45 {
46 self.platform
47 .prepare_frame(sdl_context, &mut self.imgui_context, window, event_pump);
48
49 let ui = self.imgui_context.new_frame();
50 draw_callback(ui);
51
52 self.renderer.render(device, window, &mut self.imgui_context).unwrap();
53 }
54}