oxide_engine/ui/
egui_manager.rs1use egui_winit::State;
8use wgpu::{Device, TextureFormat};
9use winit::window::Window;
10
11pub struct EguiManager {
13 pub context: egui::Context,
15 pub winit_state: State,
17}
18
19impl EguiManager {
20 pub fn new(
22 _device: &Device,
23 _output_format: TextureFormat,
24 window: &Window,
25 scale_factor: f32,
26 ) -> Self {
27 let context = egui::Context::default();
28 let viewport_id = context.viewport_id();
29
30 let winit_state = State::new(
31 context.clone(),
32 viewport_id,
33 window,
34 Some(scale_factor),
35 None,
36 None,
37 );
38
39 Self {
40 context,
41 winit_state,
42 }
43 }
44
45 pub fn wants_pointer_input(&self) -> bool {
47 self.context.wants_pointer_input()
48 }
49
50 pub fn wants_keyboard_input(&self) -> bool {
52 self.context.wants_keyboard_input()
53 }
54
55 pub fn begin_frame(&mut self, window: &Window) {
57 let raw_input = self.winit_state.take_egui_input(window);
58 self.context.begin_pass(raw_input);
59 }
60
61 pub fn end_frame(&mut self) -> egui::FullOutput {
63 self.context.end_pass()
64 }
65}