1#![allow(
19 clippy::cast_possible_truncation,
20 clippy::cast_sign_loss,
21 clippy::as_conversions
22)]
23use bitflags::bitflags;
24
25use crate::sys;
26
27bitflags! {
28 #[repr(transparent)]
30 pub struct ConfigFlags: i32 {
31 const NAV_ENABLE_KEYBOARD = sys::ImGuiConfigFlags_NavEnableKeyboard as i32;
33 const NAV_ENABLE_GAMEPAD = sys::ImGuiConfigFlags_NavEnableGamepad as i32;
35 const NO_MOUSE = sys::ImGuiConfigFlags_NoMouse as i32;
37 const NO_MOUSE_CURSOR_CHANGE = sys::ImGuiConfigFlags_NoMouseCursorChange as i32;
39 const IS_SRGB = sys::ImGuiConfigFlags_IsSRGB as i32;
41 const IS_TOUCH_SCREEN = sys::ImGuiConfigFlags_IsTouchScreen as i32;
43
44 const DOCKING_ENABLE = sys::ImGuiConfigFlags_DockingEnable as i32;
45
46 const VIEWPORTS_ENABLE = sys::ImGuiConfigFlags_ViewportsEnable as i32;
47 }
48}
49
50bitflags! {
51 #[repr(transparent)]
53 pub struct BackendFlags: i32 {
54 const HAS_GAMEPAD = sys::ImGuiBackendFlags_HasGamepad as i32;
56 const HAS_MOUSE_CURSORS = sys::ImGuiBackendFlags_HasMouseCursors as i32;
58 const HAS_SET_MOUSE_POS = sys::ImGuiBackendFlags_HasSetMousePos as i32;
60 const RENDERER_HAS_VTX_OFFSET = sys::ImGuiBackendFlags_RendererHasVtxOffset as i32;
62 const RENDERER_HAS_TEXTURES = sys::ImGuiBackendFlags_RendererHasTextures as i32;
64
65 #[cfg(feature = "multi-viewport")]
66 const PLATFORM_HAS_VIEWPORTS = sys::ImGuiBackendFlags_PlatformHasViewports as i32;
68 #[cfg(feature = "multi-viewport")]
69 const RENDERER_HAS_VIEWPORTS = sys::ImGuiBackendFlags_RendererHasViewports as i32;
71 }
72}
73
74#[cfg(feature = "multi-viewport")]
75bitflags! {
76 #[repr(transparent)]
78 pub struct ViewportFlags: i32 {
79 const NONE = 0;
81 const IS_PLATFORM_WINDOW = sys::ImGuiViewportFlags_IsPlatformWindow as i32;
83 const IS_PLATFORM_MONITOR = sys::ImGuiViewportFlags_IsPlatformMonitor as i32;
85 const OWNED_BY_APP = sys::ImGuiViewportFlags_OwnedByApp as i32;
87 const NO_DECORATION = sys::ImGuiViewportFlags_NoDecoration as i32;
89 const NO_TASK_BAR_ICON = sys::ImGuiViewportFlags_NoTaskBarIcon as i32;
91 const NO_FOCUS_ON_APPEARING = sys::ImGuiViewportFlags_NoFocusOnAppearing as i32;
93 const NO_FOCUS_ON_CLICK = sys::ImGuiViewportFlags_NoFocusOnClick as i32;
95 const NO_INPUTS = sys::ImGuiViewportFlags_NoInputs as i32;
97 const NO_RENDERER_CLEAR = sys::ImGuiViewportFlags_NoRendererClear as i32;
99 const NO_AUTO_MERGE = sys::ImGuiViewportFlags_NoAutoMerge as i32;
101 const TOP_MOST = sys::ImGuiViewportFlags_TopMost as i32;
103 const CAN_HOST_OTHER_WINDOWS = sys::ImGuiViewportFlags_CanHostOtherWindows as i32;
105 const IS_MINIMIZED = sys::ImGuiViewportFlags_IsMinimized as i32;
107 const IS_FOCUSED = sys::ImGuiViewportFlags_IsFocused as i32;
109 }
110}
111
112#[repr(transparent)]
115pub struct Io(sys::ImGuiIO);
116
117impl Io {
118 pub(crate) fn from_raw() -> &'static mut Self {
120 unsafe {
121 let io_ptr = sys::igGetIO_Nil();
124 &mut *(io_ptr as *mut Self)
125 }
126 }
127
128 pub fn display_size(&self) -> [f32; 2] {
130 [self.0.DisplaySize.x, self.0.DisplaySize.y]
131 }
132
133 pub fn set_display_size(&mut self, size: [f32; 2]) {
135 self.0.DisplaySize.x = size[0];
136 self.0.DisplaySize.y = size[1];
137 }
138
139 pub fn delta_time(&self) -> f32 {
141 self.0.DeltaTime
142 }
143
144 pub fn set_delta_time(&mut self, delta_time: f32) {
146 self.0.DeltaTime = delta_time;
147 }
148
149 pub fn mouse_pos(&self) -> [f32; 2] {
151 [self.0.MousePos.x, self.0.MousePos.y]
152 }
153
154 pub fn set_mouse_pos(&mut self, pos: [f32; 2]) {
156 self.0.MousePos.x = pos[0];
157 self.0.MousePos.y = pos[1];
158 }
159
160 pub fn mouse_wheel(&self) -> f32 {
162 self.0.MouseWheel
163 }
164
165 pub fn set_mouse_wheel(&mut self, wheel: f32) {
167 self.0.MouseWheel = wheel;
168 }
169
170 pub fn mouse_wheel_h(&self) -> f32 {
172 self.0.MouseWheelH
173 }
174
175 pub fn set_mouse_wheel_h(&mut self, wheel_h: f32) {
177 self.0.MouseWheelH = wheel_h;
178 }
179
180 pub fn mouse_down(&self, button: usize) -> bool {
182 if button < 5 {
183 self.0.MouseDown[button]
184 } else {
185 false
186 }
187 }
188
189 pub fn set_mouse_down(&mut self, button: usize, down: bool) {
191 if button < 5 {
192 self.0.MouseDown[button] = down;
193 }
194 }
195
196 pub fn want_capture_mouse(&self) -> bool {
198 self.0.WantCaptureMouse
199 }
200
201 pub fn want_capture_keyboard(&self) -> bool {
203 self.0.WantCaptureKeyboard
204 }
205
206 pub fn want_text_input(&self) -> bool {
208 self.0.WantTextInput
209 }
210
211 pub fn want_set_mouse_pos(&self) -> bool {
213 self.0.WantSetMousePos
214 }
215 pub fn mouse_draw_cursor(&self) -> bool {
217 self.0.MouseDrawCursor
218 }
219 pub fn set_mouse_draw_cursor(&mut self, draw: bool) {
221 self.0.MouseDrawCursor = draw;
222 }
223
224 pub fn want_save_ini_settings(&self) -> bool {
226 self.0.WantSaveIniSettings
227 }
228
229 pub fn framerate(&self) -> f32 {
231 self.0.Framerate
232 }
233
234 pub fn metrics_render_vertices(&self) -> i32 {
236 self.0.MetricsRenderVertices
237 }
238
239 pub fn metrics_render_indices(&self) -> i32 {
241 self.0.MetricsRenderIndices
242 }
243
244 pub fn metrics_render_windows(&self) -> i32 {
246 self.0.MetricsRenderWindows
247 }
248
249 pub fn metrics_active_windows(&self) -> i32 {
251 self.0.MetricsActiveWindows
252 }
253
254 pub fn config_flags(&self) -> ConfigFlags {
256 ConfigFlags::from_bits_truncate(self.0.ConfigFlags)
257 }
258
259 pub fn set_config_flags(&mut self, flags: ConfigFlags) {
261 self.0.ConfigFlags = flags.bits();
262 }
263
264 pub fn backend_flags(&self) -> BackendFlags {
266 BackendFlags::from_bits_truncate(self.0.BackendFlags)
267 }
268
269 pub fn set_backend_flags(&mut self, flags: BackendFlags) {
271 self.0.BackendFlags = flags.bits();
272 }
273
274 pub fn add_key_event(&mut self, key: crate::Key, down: bool) {
276 unsafe {
277 sys::ImGuiIO_AddKeyEvent(&mut self.0 as *mut _, key.into(), down);
278 }
279 }
280
281 pub fn add_input_character(&mut self, character: char) {
283 unsafe {
284 sys::ImGuiIO_AddInputCharacter(&mut self.0 as *mut _, character as u32);
285 }
286 }
287
288 pub fn add_mouse_pos_event(&mut self, pos: [f32; 2]) {
290 unsafe {
291 sys::ImGuiIO_AddMousePosEvent(&mut self.0 as *mut _, pos[0], pos[1]);
292 }
293 }
294
295 pub fn add_mouse_button_event(&mut self, button: crate::input::MouseButton, down: bool) {
297 unsafe {
298 sys::ImGuiIO_AddMouseButtonEvent(&mut self.0 as *mut _, button.into(), down);
299 }
300 }
301
302 pub fn add_mouse_wheel_event(&mut self, wheel: [f32; 2]) {
304 unsafe {
305 sys::ImGuiIO_AddMouseWheelEvent(&mut self.0 as *mut _, wheel[0], wheel[1]);
306 }
307 }
308
309 pub fn add_focus_event(&mut self, focused: bool) {
312 unsafe {
313 sys::ImGuiIO_AddFocusEvent(&mut self.0 as *mut _, focused);
314 }
315 }
316
317 pub fn font_global_scale(&self) -> f32 {
320 unsafe { (*sys::igGetStyle()).FontScaleMain }
321 }
322
323 pub fn set_font_global_scale(&mut self, _scale: f32) {
326 unsafe {
327 (*sys::igGetStyle()).FontScaleMain = _scale;
328 }
329 }
330
331 pub fn display_framebuffer_scale(&self) -> [f32; 2] {
333 let scale = self.0.DisplayFramebufferScale;
334 [scale.x, scale.y]
335 }
336
337 pub fn set_display_framebuffer_scale(&mut self, scale: [f32; 2]) {
340 self.0.DisplayFramebufferScale.x = scale[0];
341 self.0.DisplayFramebufferScale.y = scale[1];
342 }
343}