1#![allow(
2 clippy::cast_possible_truncation,
3 clippy::cast_sign_loss,
4 clippy::as_conversions
5)]
6use bitflags::bitflags;
7
8use crate::sys;
9
10bitflags! {
11 #[repr(transparent)]
13 pub struct ConfigFlags: i32 {
14 const NAV_ENABLE_KEYBOARD = sys::ImGuiConfigFlags_NavEnableKeyboard as i32;
16 const NAV_ENABLE_GAMEPAD = sys::ImGuiConfigFlags_NavEnableGamepad as i32;
18 const NO_MOUSE = sys::ImGuiConfigFlags_NoMouse as i32;
20 const NO_MOUSE_CURSOR_CHANGE = sys::ImGuiConfigFlags_NoMouseCursorChange as i32;
22 const IS_SRGB = sys::ImGuiConfigFlags_IsSRGB as i32;
24 const IS_TOUCH_SCREEN = sys::ImGuiConfigFlags_IsTouchScreen as i32;
26
27 const DOCKING_ENABLE = sys::ImGuiConfigFlags_DockingEnable as i32;
28
29 const VIEWPORTS_ENABLE = sys::ImGuiConfigFlags_ViewportsEnable as i32;
30 }
31}
32
33bitflags! {
34 #[repr(transparent)]
36 pub struct BackendFlags: i32 {
37 const HAS_GAMEPAD = sys::ImGuiBackendFlags_HasGamepad as i32;
39 const HAS_MOUSE_CURSORS = sys::ImGuiBackendFlags_HasMouseCursors as i32;
41 const HAS_SET_MOUSE_POS = sys::ImGuiBackendFlags_HasSetMousePos as i32;
43 const RENDERER_HAS_VTX_OFFSET = sys::ImGuiBackendFlags_RendererHasVtxOffset as i32;
45 const RENDERER_HAS_TEXTURES = sys::ImGuiBackendFlags_RendererHasTextures as i32;
47
48 #[cfg(feature = "multi-viewport")]
49 const PLATFORM_HAS_VIEWPORTS = sys::ImGuiBackendFlags_PlatformHasViewports as i32;
51 #[cfg(feature = "multi-viewport")]
52 const RENDERER_HAS_VIEWPORTS = sys::ImGuiBackendFlags_RendererHasViewports as i32;
54 }
55}
56
57#[cfg(feature = "multi-viewport")]
58bitflags! {
59 #[repr(transparent)]
61 pub struct ViewportFlags: i32 {
62 const NONE = 0;
64 const IS_PLATFORM_WINDOW = sys::ImGuiViewportFlags_IsPlatformWindow as i32;
66 const IS_PLATFORM_MONITOR = sys::ImGuiViewportFlags_IsPlatformMonitor as i32;
68 const OWNED_BY_APP = sys::ImGuiViewportFlags_OwnedByApp as i32;
70 const NO_DECORATION = sys::ImGuiViewportFlags_NoDecoration as i32;
72 const NO_TASK_BAR_ICON = sys::ImGuiViewportFlags_NoTaskBarIcon as i32;
74 const NO_FOCUS_ON_APPEARING = sys::ImGuiViewportFlags_NoFocusOnAppearing as i32;
76 const NO_FOCUS_ON_CLICK = sys::ImGuiViewportFlags_NoFocusOnClick as i32;
78 const NO_INPUTS = sys::ImGuiViewportFlags_NoInputs as i32;
80 const NO_RENDERER_CLEAR = sys::ImGuiViewportFlags_NoRendererClear as i32;
82 const NO_AUTO_MERGE = sys::ImGuiViewportFlags_NoAutoMerge as i32;
84 const TOP_MOST = sys::ImGuiViewportFlags_TopMost as i32;
86 const CAN_HOST_OTHER_WINDOWS = sys::ImGuiViewportFlags_CanHostOtherWindows as i32;
88 const IS_MINIMIZED = sys::ImGuiViewportFlags_IsMinimized as i32;
90 const IS_FOCUSED = sys::ImGuiViewportFlags_IsFocused as i32;
92 }
93}
94
95#[repr(transparent)]
98pub struct Io(sys::ImGuiIO);
99
100impl Io {
101 pub(crate) fn from_raw() -> &'static mut Self {
103 unsafe {
104 let io_ptr = sys::igGetIO_Nil();
107 &mut *(io_ptr as *mut Self)
108 }
109 }
110
111 pub fn display_size(&self) -> [f32; 2] {
113 [self.0.DisplaySize.x, self.0.DisplaySize.y]
114 }
115
116 pub fn set_display_size(&mut self, size: [f32; 2]) {
118 self.0.DisplaySize.x = size[0];
119 self.0.DisplaySize.y = size[1];
120 }
121
122 pub fn delta_time(&self) -> f32 {
124 self.0.DeltaTime
125 }
126
127 pub fn set_delta_time(&mut self, delta_time: f32) {
129 self.0.DeltaTime = delta_time;
130 }
131
132 pub fn mouse_pos(&self) -> [f32; 2] {
134 [self.0.MousePos.x, self.0.MousePos.y]
135 }
136
137 pub fn set_mouse_pos(&mut self, pos: [f32; 2]) {
139 self.0.MousePos.x = pos[0];
140 self.0.MousePos.y = pos[1];
141 }
142
143 pub fn mouse_wheel(&self) -> f32 {
145 self.0.MouseWheel
146 }
147
148 pub fn set_mouse_wheel(&mut self, wheel: f32) {
150 self.0.MouseWheel = wheel;
151 }
152
153 pub fn mouse_wheel_h(&self) -> f32 {
155 self.0.MouseWheelH
156 }
157
158 pub fn set_mouse_wheel_h(&mut self, wheel_h: f32) {
160 self.0.MouseWheelH = wheel_h;
161 }
162
163 pub fn mouse_down(&self, button: usize) -> bool {
165 if button < 5 {
166 self.0.MouseDown[button]
167 } else {
168 false
169 }
170 }
171
172 pub fn set_mouse_down(&mut self, button: usize, down: bool) {
174 if button < 5 {
175 self.0.MouseDown[button] = down;
176 }
177 }
178
179 pub fn want_capture_mouse(&self) -> bool {
181 self.0.WantCaptureMouse
182 }
183
184 pub fn want_capture_keyboard(&self) -> bool {
186 self.0.WantCaptureKeyboard
187 }
188
189 pub fn want_text_input(&self) -> bool {
191 self.0.WantTextInput
192 }
193
194 pub fn want_set_mouse_pos(&self) -> bool {
196 self.0.WantSetMousePos
197 }
198 pub fn mouse_draw_cursor(&self) -> bool {
200 self.0.MouseDrawCursor
201 }
202 pub fn set_mouse_draw_cursor(&mut self, draw: bool) {
204 self.0.MouseDrawCursor = draw;
205 }
206
207 pub fn want_save_ini_settings(&self) -> bool {
209 self.0.WantSaveIniSettings
210 }
211
212 pub fn framerate(&self) -> f32 {
214 self.0.Framerate
215 }
216
217 pub fn metrics_render_vertices(&self) -> i32 {
219 self.0.MetricsRenderVertices
220 }
221
222 pub fn metrics_render_indices(&self) -> i32 {
224 self.0.MetricsRenderIndices
225 }
226
227 pub fn metrics_render_windows(&self) -> i32 {
229 self.0.MetricsRenderWindows
230 }
231
232 pub fn metrics_active_windows(&self) -> i32 {
234 self.0.MetricsActiveWindows
235 }
236
237 pub fn config_flags(&self) -> ConfigFlags {
239 ConfigFlags::from_bits_truncate(self.0.ConfigFlags)
240 }
241
242 pub fn set_config_flags(&mut self, flags: ConfigFlags) {
244 self.0.ConfigFlags = flags.bits();
245 }
246
247 pub fn backend_flags(&self) -> BackendFlags {
249 BackendFlags::from_bits_truncate(self.0.BackendFlags)
250 }
251
252 pub fn set_backend_flags(&mut self, flags: BackendFlags) {
254 self.0.BackendFlags = flags.bits();
255 }
256
257 pub fn add_key_event(&mut self, key: crate::Key, down: bool) {
259 unsafe {
260 sys::ImGuiIO_AddKeyEvent(&mut self.0 as *mut _, key.into(), down);
261 }
262 }
263
264 pub fn add_input_character(&mut self, character: char) {
266 unsafe {
267 sys::ImGuiIO_AddInputCharacter(&mut self.0 as *mut _, character as u32);
268 }
269 }
270
271 pub fn add_mouse_pos_event(&mut self, pos: [f32; 2]) {
273 unsafe {
274 sys::ImGuiIO_AddMousePosEvent(&mut self.0 as *mut _, pos[0], pos[1]);
275 }
276 }
277
278 pub fn add_mouse_button_event(&mut self, button: crate::input::MouseButton, down: bool) {
280 unsafe {
281 sys::ImGuiIO_AddMouseButtonEvent(&mut self.0 as *mut _, button.into(), down);
282 }
283 }
284
285 pub fn add_mouse_wheel_event(&mut self, wheel: [f32; 2]) {
287 unsafe {
288 sys::ImGuiIO_AddMouseWheelEvent(&mut self.0 as *mut _, wheel[0], wheel[1]);
289 }
290 }
291
292 pub fn add_focus_event(&mut self, focused: bool) {
295 unsafe {
296 sys::ImGuiIO_AddFocusEvent(&mut self.0 as *mut _, focused);
297 }
298 }
299
300 pub fn font_global_scale(&self) -> f32 {
303 unsafe { (*sys::igGetStyle()).FontScaleMain }
304 }
305
306 pub fn set_font_global_scale(&mut self, _scale: f32) {
309 unsafe {
310 (*sys::igGetStyle()).FontScaleMain = _scale;
311 }
312 }
313
314 pub fn display_framebuffer_scale(&self) -> [f32; 2] {
316 let scale = self.0.DisplayFramebufferScale;
317 [scale.x, scale.y]
318 }
319
320 pub fn set_display_framebuffer_scale(&mut self, scale: [f32; 2]) {
323 self.0.DisplayFramebufferScale.x = scale[0];
324 self.0.DisplayFramebufferScale.y = scale[1];
325 }
326}