1#![allow(non_upper_case_globals)]
90#![allow(non_camel_case_types)]
91#![allow(non_snake_case)]
92#![allow(dead_code)]
93#![allow(unnecessary_transmutes)]
94#![allow(clippy::all)]
95#![allow(unpredictable_function_pointer_comparisons)]
98
99#[cfg(all(feature = "stack-layout", dear_imgui_rs_wasm_import_target))]
100compile_error!("feature `stack-layout` is native-only and cannot be combined with WASM");
101
102#[cfg(all(feature = "test-engine", dear_imgui_rs_wasm_import_target))]
103compile_error!("feature `test-engine` is native source-only and cannot be combined with WASM");
104
105#[cfg(all(feature = "prebuilt", dear_imgui_rs_wasm_import_target))]
106compile_error!("feature `prebuilt` is native-only and cannot be combined with WASM");
107
108mod ffi;
111pub use ffi::*;
112
113#[cfg_attr(
114 dear_imgui_rs_wasm_import_target,
115 link(wasm_import_module = "imgui-sys-v1")
116)]
117unsafe extern "C" {
118 pub fn dear_imgui_rs_show_demo_window_without_font_atlas(p_open: *mut bool);
119 pub fn dear_imgui_rs_show_metrics_window_without_font_atlas(p_open: *mut bool);
120 pub fn dear_imgui_rs_show_style_editor_without_font_atlas(ref_: *mut ImGuiStyle);
121 pub fn dear_imgui_rs_show_font_atlas_debug_panel();
122 pub fn dear_imgui_rs_dock_builder_keep_root_alive(root_id: ImGuiID) -> ::std::os::raw::c_int;
123 pub fn dear_imgui_rs_dock_builder_root_has_active_content_window(
124 root_id: ImGuiID,
125 ) -> ::std::os::raw::c_int;
126 pub fn dear_imgui_rs_dock_builder_copy_node(
127 source_root_id: ImGuiID,
128 destination_root_id: ImGuiID,
129 remap_data: *mut ImGuiID,
130 remap_capacity: ::std::os::raw::c_int,
131 ) -> ::std::os::raw::c_int;
132}
133
134pub mod backend_shim;
141
142const _: [(); 4] = [(); std::mem::size_of::<ImWchar>()];
146
147pub const HAS_PLATFORM_IO_AGGREGATE_HOOKS: bool = cfg!(dear_imgui_rs_platform_io_hooks);
157
158#[cfg(feature = "stack-layout")]
159mod stack_layout {
160 use super::*;
161
162 unsafe extern "C" {
163 fn dear_imgui_stack_begin_horizontal_str(
164 str_id: *const std::os::raw::c_char,
165 size: ImVec2,
166 align: f32,
167 );
168 fn dear_imgui_stack_begin_horizontal_ptr(
169 ptr_id: *const std::ffi::c_void,
170 size: ImVec2,
171 align: f32,
172 );
173 fn dear_imgui_stack_begin_horizontal_int(id: std::os::raw::c_int, size: ImVec2, align: f32);
174 fn dear_imgui_stack_begin_horizontal_id(id: ImGuiID, size: ImVec2, align: f32);
175 fn dear_imgui_stack_end_horizontal();
176 fn dear_imgui_stack_begin_vertical_str(
177 str_id: *const std::os::raw::c_char,
178 size: ImVec2,
179 align: f32,
180 );
181 fn dear_imgui_stack_begin_vertical_ptr(
182 ptr_id: *const std::ffi::c_void,
183 size: ImVec2,
184 align: f32,
185 );
186 fn dear_imgui_stack_begin_vertical_int(id: std::os::raw::c_int, size: ImVec2, align: f32);
187 fn dear_imgui_stack_begin_vertical_id(id: ImGuiID, size: ImVec2, align: f32);
188 fn dear_imgui_stack_end_vertical();
189 fn dear_imgui_stack_spring(weight: f32, spacing: f32);
190 fn dear_imgui_stack_suspend_layout();
191 fn dear_imgui_stack_resume_layout();
192 fn dear_imgui_stack_destroy_context_state(context: *mut ImGuiContext);
193 fn dear_imgui_stack_state_count() -> usize;
194 }
195
196 #[inline]
206 pub unsafe fn ImGuiStack_BeginHorizontal_Str(
207 str_id: *const std::os::raw::c_char,
208 size: ImVec2,
209 align: f32,
210 ) {
211 unsafe { dear_imgui_stack_begin_horizontal_str(str_id, size, align) }
212 }
213
214 #[inline]
221 pub unsafe fn ImGuiStack_BeginHorizontal_Ptr(
222 ptr_id: *const std::ffi::c_void,
223 size: ImVec2,
224 align: f32,
225 ) {
226 unsafe { dear_imgui_stack_begin_horizontal_ptr(ptr_id, size, align) }
227 }
228
229 #[inline]
235 pub unsafe fn ImGuiStack_BeginHorizontal_Int(
236 id: std::os::raw::c_int,
237 size: ImVec2,
238 align: f32,
239 ) {
240 unsafe { dear_imgui_stack_begin_horizontal_int(id, size, align) }
241 }
242
243 #[inline]
249 pub unsafe fn ImGuiStack_BeginHorizontal_Id(id: ImGuiID, size: ImVec2, align: f32) {
250 unsafe { dear_imgui_stack_begin_horizontal_id(id, size, align) }
251 }
252
253 #[inline]
259 pub unsafe fn ImGuiStack_EndHorizontal() {
260 unsafe { dear_imgui_stack_end_horizontal() }
261 }
262
263 #[inline]
270 pub unsafe fn ImGuiStack_BeginVertical_Str(
271 str_id: *const std::os::raw::c_char,
272 size: ImVec2,
273 align: f32,
274 ) {
275 unsafe { dear_imgui_stack_begin_vertical_str(str_id, size, align) }
276 }
277
278 #[inline]
285 pub unsafe fn ImGuiStack_BeginVertical_Ptr(
286 ptr_id: *const std::ffi::c_void,
287 size: ImVec2,
288 align: f32,
289 ) {
290 unsafe { dear_imgui_stack_begin_vertical_ptr(ptr_id, size, align) }
291 }
292
293 #[inline]
299 pub unsafe fn ImGuiStack_BeginVertical_Int(id: std::os::raw::c_int, size: ImVec2, align: f32) {
300 unsafe { dear_imgui_stack_begin_vertical_int(id, size, align) }
301 }
302
303 #[inline]
309 pub unsafe fn ImGuiStack_BeginVertical_Id(id: ImGuiID, size: ImVec2, align: f32) {
310 unsafe { dear_imgui_stack_begin_vertical_id(id, size, align) }
311 }
312
313 #[inline]
319 pub unsafe fn ImGuiStack_EndVertical() {
320 unsafe { dear_imgui_stack_end_vertical() }
321 }
322
323 #[inline]
329 pub unsafe fn ImGuiStack_Spring(weight: f32, spacing: f32) {
330 unsafe { dear_imgui_stack_spring(weight, spacing) }
331 }
332
333 #[inline]
339 pub unsafe fn ImGuiStack_SuspendLayout() {
340 unsafe { dear_imgui_stack_suspend_layout() }
341 }
342
343 #[inline]
349 pub unsafe fn ImGuiStack_ResumeLayout() {
350 unsafe { dear_imgui_stack_resume_layout() }
351 }
352
353 #[inline]
360 pub unsafe fn ImGuiStack_DestroyContextState(context: *mut ImGuiContext) {
361 unsafe { dear_imgui_stack_destroy_context_state(context) }
362 }
363
364 #[doc(hidden)]
370 #[inline]
371 pub unsafe fn ImGuiStack_StateCount() -> usize {
372 unsafe { dear_imgui_stack_state_count() }
373 }
374}
375
376#[cfg(feature = "stack-layout")]
377pub use stack_layout::*;
378
379#[cfg(dear_imgui_rs_platform_io_hooks)]
380unsafe extern "C" {
381 fn dear_imgui_rs_platform_io_set_platform_set_window_pos(
382 platform_io: *mut ImGuiPlatformIO,
383 user_callback: Option<unsafe extern "C" fn(vp: *mut ImGuiViewport, pos: *const ImVec2)>,
384 );
385
386 fn dear_imgui_rs_platform_io_set_platform_get_window_pos(
387 platform_io: *mut ImGuiPlatformIO,
388 user_callback: Option<unsafe extern "C" fn(vp: *mut ImGuiViewport, out_pos: *mut ImVec2)>,
389 );
390
391 fn dear_imgui_rs_platform_io_set_platform_set_window_size(
392 platform_io: *mut ImGuiPlatformIO,
393 user_callback: Option<unsafe extern "C" fn(vp: *mut ImGuiViewport, size: *const ImVec2)>,
394 );
395
396 fn dear_imgui_rs_platform_io_set_platform_get_window_size(
397 platform_io: *mut ImGuiPlatformIO,
398 user_callback: Option<unsafe extern "C" fn(vp: *mut ImGuiViewport, out_size: *mut ImVec2)>,
399 );
400
401 fn dear_imgui_rs_platform_io_set_platform_get_window_framebuffer_scale(
402 platform_io: *mut ImGuiPlatformIO,
403 user_callback: Option<unsafe extern "C" fn(vp: *mut ImGuiViewport, out_scale: *mut ImVec2)>,
404 );
405
406 fn dear_imgui_rs_platform_io_set_platform_get_window_work_area_insets(
407 platform_io: *mut ImGuiPlatformIO,
408 user_callback: Option<
409 unsafe extern "C" fn(vp: *mut ImGuiViewport, out_insets: *mut ImVec4),
410 >,
411 );
412
413 fn dear_imgui_rs_platform_io_clear_platform_set_window_pos_if_pointer_param(
414 platform_io: *mut ImGuiPlatformIO,
415 user_callback: unsafe extern "C" fn(vp: *mut ImGuiViewport, pos: *const ImVec2),
416 ) -> std::os::raw::c_int;
417
418 fn dear_imgui_rs_platform_io_clear_platform_set_window_size_if_pointer_param(
419 platform_io: *mut ImGuiPlatformIO,
420 user_callback: unsafe extern "C" fn(vp: *mut ImGuiViewport, size: *const ImVec2),
421 ) -> std::os::raw::c_int;
422
423 fn dear_imgui_rs_platform_io_clear_platform_get_window_pos_if_out_param(
424 platform_io: *mut ImGuiPlatformIO,
425 user_callback: unsafe extern "C" fn(vp: *mut ImGuiViewport, out_pos: *mut ImVec2),
426 ) -> std::os::raw::c_int;
427
428 fn dear_imgui_rs_platform_io_clear_platform_get_window_size_if_out_param(
429 platform_io: *mut ImGuiPlatformIO,
430 user_callback: unsafe extern "C" fn(vp: *mut ImGuiViewport, out_size: *mut ImVec2),
431 ) -> std::os::raw::c_int;
432
433 fn dear_imgui_rs_platform_io_clear_platform_get_window_framebuffer_scale_if_out_param(
434 platform_io: *mut ImGuiPlatformIO,
435 user_callback: unsafe extern "C" fn(vp: *mut ImGuiViewport, out_scale: *mut ImVec2),
436 ) -> std::os::raw::c_int;
437
438 fn dear_imgui_rs_platform_io_get_platform_set_window_pos_pointer_param(
439 platform_io: *mut ImGuiPlatformIO,
440 out_callback: *mut Option<unsafe extern "C" fn(vp: *mut ImGuiViewport, pos: *const ImVec2)>,
441 ) -> std::os::raw::c_int;
442
443 fn dear_imgui_rs_platform_io_get_platform_set_window_size_pointer_param(
444 platform_io: *mut ImGuiPlatformIO,
445 out_callback: *mut Option<
446 unsafe extern "C" fn(vp: *mut ImGuiViewport, size: *const ImVec2),
447 >,
448 ) -> std::os::raw::c_int;
449
450 fn dear_imgui_rs_platform_io_get_platform_get_window_pos_out_param(
451 platform_io: *mut ImGuiPlatformIO,
452 out_callback: *mut Option<
453 unsafe extern "C" fn(vp: *mut ImGuiViewport, out_pos: *mut ImVec2),
454 >,
455 ) -> std::os::raw::c_int;
456
457 fn dear_imgui_rs_platform_io_get_platform_get_window_size_out_param(
458 platform_io: *mut ImGuiPlatformIO,
459 out_callback: *mut Option<
460 unsafe extern "C" fn(vp: *mut ImGuiViewport, out_size: *mut ImVec2),
461 >,
462 ) -> std::os::raw::c_int;
463
464 fn dear_imgui_rs_platform_io_get_platform_get_window_framebuffer_scale_out_param(
465 platform_io: *mut ImGuiPlatformIO,
466 out_callback: *mut Option<
467 unsafe extern "C" fn(vp: *mut ImGuiViewport, out_scale: *mut ImVec2),
468 >,
469 ) -> std::os::raw::c_int;
470
471 fn dear_imgui_rs_platform_io_clear_platform_get_window_work_area_insets_if_out_param(
472 platform_io: *mut ImGuiPlatformIO,
473 user_callback: unsafe extern "C" fn(vp: *mut ImGuiViewport, out_insets: *mut ImVec4),
474 ) -> std::os::raw::c_int;
475
476 fn dear_imgui_rs_platform_io_set_renderer_set_window_size(
477 platform_io: *mut ImGuiPlatformIO,
478 user_callback: Option<unsafe extern "C" fn(vp: *mut ImGuiViewport, size: *const ImVec2)>,
479 );
480
481 fn dear_imgui_rs_platform_io_renderer_set_window_size_matches_pointer_param(
482 platform_io: *mut ImGuiPlatformIO,
483 user_callback: unsafe extern "C" fn(vp: *mut ImGuiViewport, size: *const ImVec2),
484 ) -> std::os::raw::c_int;
485
486 fn dear_imgui_rs_platform_io_get_renderer_set_window_size_pointer_param(
487 platform_io: *mut ImGuiPlatformIO,
488 out_callback: *mut Option<
489 unsafe extern "C" fn(vp: *mut ImGuiViewport, size: *const ImVec2),
490 >,
491 ) -> std::os::raw::c_int;
492
493 fn dear_imgui_rs_platform_io_clear_renderer_set_window_size_if_pointer_param(
494 platform_io: *mut ImGuiPlatformIO,
495 user_callback: unsafe extern "C" fn(vp: *mut ImGuiViewport, size: *const ImVec2),
496 ) -> std::os::raw::c_int;
497
498 fn dear_imgui_rs_platform_io_probe_aggregate_callbacks(
499 platform_io: *mut ImGuiPlatformIO,
500 out_result: *mut DearImguiRsPlatformIoAggregateProbeResult,
501 ) -> std::os::raw::c_int;
502
503 fn dear_imgui_rs_platform_io_invoke_platform_set_window_pos(
504 callbacks: *const ImGuiPlatformIO,
505 viewport: *mut ImGuiViewport,
506 pos: *const ImVec2,
507 ) -> std::os::raw::c_int;
508
509 fn dear_imgui_rs_platform_io_invoke_platform_set_window_size(
510 callbacks: *const ImGuiPlatformIO,
511 viewport: *mut ImGuiViewport,
512 size: *const ImVec2,
513 ) -> std::os::raw::c_int;
514
515 fn dear_imgui_rs_platform_io_invoke_platform_get_window_pos(
516 callbacks: *const ImGuiPlatformIO,
517 viewport: *mut ImGuiViewport,
518 out_pos: *mut ImVec2,
519 ) -> std::os::raw::c_int;
520
521 fn dear_imgui_rs_platform_io_invoke_platform_get_window_size(
522 callbacks: *const ImGuiPlatformIO,
523 viewport: *mut ImGuiViewport,
524 out_size: *mut ImVec2,
525 ) -> std::os::raw::c_int;
526
527 fn dear_imgui_rs_platform_io_invoke_platform_get_window_framebuffer_scale(
528 callbacks: *const ImGuiPlatformIO,
529 viewport: *mut ImGuiViewport,
530 out_scale: *mut ImVec2,
531 ) -> std::os::raw::c_int;
532
533 fn dear_imgui_rs_platform_io_invoke_renderer_set_window_size(
534 callbacks: *const ImGuiPlatformIO,
535 viewport: *mut ImGuiViewport,
536 size: *const ImVec2,
537 ) -> std::os::raw::c_int;
538
539 fn dear_imgui_rs_platform_io_aggregate_callback_storage_count() -> std::os::raw::c_int;
540
541 fn dear_imgui_rs_find_live_viewport_by_address(
542 context: *mut ImGuiContext,
543 address: usize,
544 ) -> *mut ImGuiViewport;
545}
546
547#[doc(hidden)]
558#[inline]
559pub unsafe fn ImGuiContext_FindLiveViewportByAddress(
560 context: *mut ImGuiContext,
561 address: usize,
562) -> *mut ImGuiViewport {
563 #[cfg(dear_imgui_rs_platform_io_hooks)]
564 {
565 unsafe { dear_imgui_rs_find_live_viewport_by_address(context, address) }
566 }
567 #[cfg(not(dear_imgui_rs_platform_io_hooks))]
568 {
569 let _ = (context, address);
570 std::ptr::null_mut()
571 }
572}
573
574#[repr(C)]
579#[derive(Clone, Copy, Debug, Default, PartialEq)]
580pub struct DearImguiRsPlatformIoAggregateProbeResult {
581 pub PlatformGetWindowPos: ImVec2,
582 pub PlatformGetWindowSize: ImVec2,
583 pub PlatformGetWindowFramebufferScale: ImVec2,
584 pub PlatformGetWindowWorkAreaInsets: ImVec4,
585}
586
587#[cfg(feature = "abi-probe")]
591#[doc(hidden)]
592#[repr(C)]
593#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
594pub struct DearImguiRsPublicAggregateLayoutProbe {
595 pub ImDrawDataSize: usize,
596 pub ImDrawDataAlign: usize,
597 pub ImDrawDataFrameCountOffset: usize,
598 pub ImDrawDataCmdListsOffset: usize,
599 pub ImDrawDataTexturesOffset: usize,
600 pub ImTextureDataSize: usize,
601 pub ImTextureDataAlign: usize,
602 pub ImTextureDataUniqueIDOffset: usize,
603 pub ImTextureDataQueueUserDataOffset: usize,
604 pub ImTextureDataTexIDOffset: usize,
605 pub ImTextureDataUpdatesOffset: usize,
606 pub ImTextureDataWantDestroyNextFrameOffset: usize,
607 pub ImGuiPlatformIOSize: usize,
608 pub ImGuiPlatformIOAlign: usize,
609 pub ImGuiPlatformIOSessionDateOffset: usize,
610 pub ImGuiPlatformIORenderStateOffset: usize,
611 pub ImGuiPlatformIOPlatformCreateWindowOffset: usize,
612 pub ImGuiPlatformIORendererCreateWindowOffset: usize,
613 pub ImGuiPlatformIOMonitorsOffset: usize,
614 pub ImGuiPlatformIOTexturesOffset: usize,
615 pub ImGuiPlatformIOViewportsOffset: usize,
616}
617
618#[cfg(feature = "abi-probe")]
619unsafe extern "C" {
620 fn dear_imgui_rs_probe_public_aggregate_layouts(
621 out_probe: *mut DearImguiRsPublicAggregateLayoutProbe,
622 ) -> std::os::raw::c_int;
623}
624
625#[cfg(feature = "abi-probe")]
629#[doc(hidden)]
630#[inline]
631pub fn ImGui_ProbePublicAggregateLayouts(
632 out_probe: &mut DearImguiRsPublicAggregateLayoutProbe,
633) -> bool {
634 unsafe { dear_imgui_rs_probe_public_aggregate_layouts(out_probe) != 0 }
635}
636
637#[inline]
645pub unsafe fn ImGuiPlatformIO_Set_Platform_SetWindowPos_PointerParam(
646 platform_io: *mut ImGuiPlatformIO,
647 user_callback: Option<unsafe extern "C" fn(vp: *mut ImGuiViewport, pos: *const ImVec2)>,
648) {
649 #[cfg(dear_imgui_rs_platform_io_hooks)]
650 unsafe {
651 dear_imgui_rs_platform_io_set_platform_set_window_pos(platform_io, user_callback)
652 }
653
654 #[cfg(not(dear_imgui_rs_platform_io_hooks))]
655 {
656 if user_callback.is_some() {
657 panic!(
658 "dear-imgui-sys was built without PlatformIO aggregate ABI hooks; \
659 rebuild without IMGUI_SYS_SKIP_CC to install Platform_SetWindowPos callbacks"
660 );
661 } else if let Some(platform_io) = unsafe { platform_io.as_mut() } {
662 platform_io.Platform_SetWindowPos = None;
663 }
664 }
665}
666
667#[inline]
678pub unsafe fn ImGuiPlatformIO_Set_Platform_GetWindowPos_OutParam(
679 platform_io: *mut ImGuiPlatformIO,
680 user_callback: Option<unsafe extern "C" fn(vp: *mut ImGuiViewport, out_pos: *mut ImVec2)>,
681) {
682 #[cfg(dear_imgui_rs_platform_io_hooks)]
683 unsafe {
684 dear_imgui_rs_platform_io_set_platform_get_window_pos(platform_io, user_callback)
685 }
686
687 #[cfg(not(dear_imgui_rs_platform_io_hooks))]
688 {
689 if user_callback.is_some() {
690 panic!(
691 "dear-imgui-sys was built without PlatformIO aggregate ABI hooks; \
692 rebuild without IMGUI_SYS_SKIP_CC to install Platform_GetWindowPos callbacks"
693 );
694 } else if let Some(platform_io) = unsafe { platform_io.as_mut() } {
695 platform_io.Platform_GetWindowPos = None;
696 }
697 }
698}
699
700#[inline]
708pub unsafe fn ImGuiPlatformIO_Set_Platform_SetWindowSize_PointerParam(
709 platform_io: *mut ImGuiPlatformIO,
710 user_callback: Option<unsafe extern "C" fn(vp: *mut ImGuiViewport, size: *const ImVec2)>,
711) {
712 #[cfg(dear_imgui_rs_platform_io_hooks)]
713 unsafe {
714 dear_imgui_rs_platform_io_set_platform_set_window_size(platform_io, user_callback)
715 }
716
717 #[cfg(not(dear_imgui_rs_platform_io_hooks))]
718 {
719 if user_callback.is_some() {
720 panic!(
721 "dear-imgui-sys was built without PlatformIO aggregate ABI hooks; \
722 rebuild without IMGUI_SYS_SKIP_CC to install Platform_SetWindowSize callbacks"
723 );
724 } else if let Some(platform_io) = unsafe { platform_io.as_mut() } {
725 platform_io.Platform_SetWindowSize = None;
726 }
727 }
728}
729
730#[inline]
739pub unsafe fn ImGuiPlatformIO_Set_Platform_GetWindowSize_OutParam(
740 platform_io: *mut ImGuiPlatformIO,
741 user_callback: Option<unsafe extern "C" fn(vp: *mut ImGuiViewport, out_size: *mut ImVec2)>,
742) {
743 #[cfg(dear_imgui_rs_platform_io_hooks)]
744 unsafe {
745 dear_imgui_rs_platform_io_set_platform_get_window_size(platform_io, user_callback)
746 }
747
748 #[cfg(not(dear_imgui_rs_platform_io_hooks))]
749 {
750 if user_callback.is_some() {
751 panic!(
752 "dear-imgui-sys was built without PlatformIO aggregate ABI hooks; \
753 rebuild without IMGUI_SYS_SKIP_CC to install Platform_GetWindowSize callbacks"
754 );
755 } else if let Some(platform_io) = unsafe { platform_io.as_mut() } {
756 platform_io.Platform_GetWindowSize = None;
757 }
758 }
759}
760
761#[inline]
771pub unsafe fn ImGuiPlatformIO_Set_Platform_GetWindowFramebufferScale_OutParam(
772 platform_io: *mut ImGuiPlatformIO,
773 user_callback: Option<unsafe extern "C" fn(vp: *mut ImGuiViewport, out_scale: *mut ImVec2)>,
774) {
775 #[cfg(dear_imgui_rs_platform_io_hooks)]
776 unsafe {
777 dear_imgui_rs_platform_io_set_platform_get_window_framebuffer_scale(
778 platform_io,
779 user_callback,
780 )
781 }
782
783 #[cfg(not(dear_imgui_rs_platform_io_hooks))]
784 {
785 if user_callback.is_some() {
786 panic!(
787 "dear-imgui-sys was built without PlatformIO aggregate ABI hooks; \
788 rebuild without IMGUI_SYS_SKIP_CC to install \
789 Platform_GetWindowFramebufferScale callbacks"
790 );
791 } else if let Some(platform_io) = unsafe { platform_io.as_mut() } {
792 platform_io.Platform_GetWindowFramebufferScale = None;
793 }
794 }
795}
796
797#[inline]
807pub unsafe fn ImGuiPlatformIO_Set_Platform_GetWindowWorkAreaInsets_OutParam(
808 platform_io: *mut ImGuiPlatformIO,
809 user_callback: Option<unsafe extern "C" fn(vp: *mut ImGuiViewport, out_insets: *mut ImVec4)>,
810) {
811 #[cfg(dear_imgui_rs_platform_io_hooks)]
812 unsafe {
813 dear_imgui_rs_platform_io_set_platform_get_window_work_area_insets(
814 platform_io,
815 user_callback,
816 )
817 }
818
819 #[cfg(not(dear_imgui_rs_platform_io_hooks))]
820 {
821 if user_callback.is_some() {
822 panic!(
823 "dear-imgui-sys was built without PlatformIO aggregate ABI hooks; \
824 rebuild without IMGUI_SYS_SKIP_CC to install Platform_GetWindowWorkAreaInsets \
825 callbacks"
826 );
827 } else if let Some(platform_io) = unsafe { platform_io.as_mut() } {
828 platform_io.Platform_GetWindowWorkAreaInsets = None;
829 }
830 }
831}
832
833#[doc(hidden)]
835#[inline]
836pub unsafe fn ImGuiPlatformIO_ClearPlatformSetWindowPosIfPointerParam(
837 platform_io: *mut ImGuiPlatformIO,
838 user_callback: unsafe extern "C" fn(vp: *mut ImGuiViewport, pos: *const ImVec2),
839) -> bool {
840 #[cfg(dear_imgui_rs_platform_io_hooks)]
841 unsafe {
842 return dear_imgui_rs_platform_io_clear_platform_set_window_pos_if_pointer_param(
843 platform_io,
844 user_callback,
845 ) != 0;
846 }
847
848 #[cfg(not(dear_imgui_rs_platform_io_hooks))]
849 {
850 let _ = platform_io;
851 let _ = user_callback;
852 false
853 }
854}
855
856#[doc(hidden)]
858#[inline]
859pub unsafe fn ImGuiPlatformIO_ClearPlatformSetWindowSizeIfPointerParam(
860 platform_io: *mut ImGuiPlatformIO,
861 user_callback: unsafe extern "C" fn(vp: *mut ImGuiViewport, size: *const ImVec2),
862) -> bool {
863 #[cfg(dear_imgui_rs_platform_io_hooks)]
864 unsafe {
865 return dear_imgui_rs_platform_io_clear_platform_set_window_size_if_pointer_param(
866 platform_io,
867 user_callback,
868 ) != 0;
869 }
870
871 #[cfg(not(dear_imgui_rs_platform_io_hooks))]
872 {
873 let _ = platform_io;
874 let _ = user_callback;
875 false
876 }
877}
878
879#[doc(hidden)]
881#[inline]
882pub unsafe fn ImGuiPlatformIO_ClearPlatformGetWindowPosIfOutParam(
883 platform_io: *mut ImGuiPlatformIO,
884 user_callback: unsafe extern "C" fn(vp: *mut ImGuiViewport, out_pos: *mut ImVec2),
885) -> bool {
886 #[cfg(dear_imgui_rs_platform_io_hooks)]
887 unsafe {
888 return dear_imgui_rs_platform_io_clear_platform_get_window_pos_if_out_param(
889 platform_io,
890 user_callback,
891 ) != 0;
892 }
893
894 #[cfg(not(dear_imgui_rs_platform_io_hooks))]
895 {
896 let _ = platform_io;
897 let _ = user_callback;
898 false
899 }
900}
901
902#[doc(hidden)]
904#[inline]
905pub unsafe fn ImGuiPlatformIO_ClearPlatformGetWindowSizeIfOutParam(
906 platform_io: *mut ImGuiPlatformIO,
907 user_callback: unsafe extern "C" fn(vp: *mut ImGuiViewport, out_size: *mut ImVec2),
908) -> bool {
909 #[cfg(dear_imgui_rs_platform_io_hooks)]
910 unsafe {
911 return dear_imgui_rs_platform_io_clear_platform_get_window_size_if_out_param(
912 platform_io,
913 user_callback,
914 ) != 0;
915 }
916
917 #[cfg(not(dear_imgui_rs_platform_io_hooks))]
918 {
919 let _ = platform_io;
920 let _ = user_callback;
921 false
922 }
923}
924
925#[doc(hidden)]
927#[inline]
928pub unsafe fn ImGuiPlatformIO_ClearPlatformGetWindowFramebufferScaleIfOutParam(
929 platform_io: *mut ImGuiPlatformIO,
930 user_callback: unsafe extern "C" fn(vp: *mut ImGuiViewport, out_scale: *mut ImVec2),
931) -> bool {
932 #[cfg(dear_imgui_rs_platform_io_hooks)]
933 unsafe {
934 return dear_imgui_rs_platform_io_clear_platform_get_window_framebuffer_scale_if_out_param(
935 platform_io,
936 user_callback,
937 ) != 0;
938 }
939
940 #[cfg(not(dear_imgui_rs_platform_io_hooks))]
941 {
942 let _ = platform_io;
943 let _ = user_callback;
944 false
945 }
946}
947
948macro_rules! define_platform_callback_getter {
949 ($name:ident, $native:ident, $callback:ty) => {
950 #[doc(hidden)]
955 #[inline]
956 pub unsafe fn $name(platform_io: *mut ImGuiPlatformIO) -> Option<$callback> {
957 #[cfg(dear_imgui_rs_platform_io_hooks)]
958 unsafe {
959 let mut callback = None;
960 if $native(platform_io, &mut callback) != 0 {
961 return callback;
962 }
963 None
964 }
965
966 #[cfg(not(dear_imgui_rs_platform_io_hooks))]
967 {
968 let _ = platform_io;
969 None
970 }
971 }
972 };
973}
974
975define_platform_callback_getter!(
976 ImGuiPlatformIO_PlatformSetWindowPosPointerParam,
977 dear_imgui_rs_platform_io_get_platform_set_window_pos_pointer_param,
978 unsafe extern "C" fn(*mut ImGuiViewport, *const ImVec2)
979);
980define_platform_callback_getter!(
981 ImGuiPlatformIO_PlatformSetWindowSizePointerParam,
982 dear_imgui_rs_platform_io_get_platform_set_window_size_pointer_param,
983 unsafe extern "C" fn(*mut ImGuiViewport, *const ImVec2)
984);
985define_platform_callback_getter!(
986 ImGuiPlatformIO_PlatformGetWindowPosOutParam,
987 dear_imgui_rs_platform_io_get_platform_get_window_pos_out_param,
988 unsafe extern "C" fn(*mut ImGuiViewport, *mut ImVec2)
989);
990define_platform_callback_getter!(
991 ImGuiPlatformIO_PlatformGetWindowSizeOutParam,
992 dear_imgui_rs_platform_io_get_platform_get_window_size_out_param,
993 unsafe extern "C" fn(*mut ImGuiViewport, *mut ImVec2)
994);
995define_platform_callback_getter!(
996 ImGuiPlatformIO_PlatformGetWindowFramebufferScaleOutParam,
997 dear_imgui_rs_platform_io_get_platform_get_window_framebuffer_scale_out_param,
998 unsafe extern "C" fn(*mut ImGuiViewport, *mut ImVec2)
999);
1000
1001#[doc(hidden)]
1003#[inline]
1004pub unsafe fn ImGuiPlatformIO_ClearPlatformGetWindowWorkAreaInsetsIfOutParam(
1005 platform_io: *mut ImGuiPlatformIO,
1006 user_callback: unsafe extern "C" fn(vp: *mut ImGuiViewport, out_insets: *mut ImVec4),
1007) -> bool {
1008 #[cfg(dear_imgui_rs_platform_io_hooks)]
1009 unsafe {
1010 return dear_imgui_rs_platform_io_clear_platform_get_window_work_area_insets_if_out_param(
1011 platform_io,
1012 user_callback,
1013 ) != 0;
1014 }
1015
1016 #[cfg(not(dear_imgui_rs_platform_io_hooks))]
1017 {
1018 let _ = platform_io;
1019 let _ = user_callback;
1020 false
1021 }
1022}
1023
1024#[inline]
1032pub unsafe fn ImGuiPlatformIO_Set_Renderer_SetWindowSize_PointerParam(
1033 platform_io: *mut ImGuiPlatformIO,
1034 user_callback: Option<unsafe extern "C" fn(vp: *mut ImGuiViewport, size: *const ImVec2)>,
1035) {
1036 #[cfg(dear_imgui_rs_platform_io_hooks)]
1037 unsafe {
1038 dear_imgui_rs_platform_io_set_renderer_set_window_size(platform_io, user_callback)
1039 }
1040
1041 #[cfg(not(dear_imgui_rs_platform_io_hooks))]
1042 {
1043 if user_callback.is_some() {
1044 panic!(
1045 "dear-imgui-sys was built without PlatformIO aggregate ABI hooks; \
1046 rebuild without IMGUI_SYS_SKIP_CC to install Renderer_SetWindowSize callbacks"
1047 );
1048 } else if let Some(platform_io) = unsafe { platform_io.as_mut() } {
1049 platform_io.Renderer_SetWindowSize = None;
1050 }
1051 }
1052}
1053
1054#[doc(hidden)]
1059#[inline]
1060pub unsafe fn ImGuiPlatformIO_RendererSetWindowSizeMatchesPointerParam(
1061 platform_io: *mut ImGuiPlatformIO,
1062 user_callback: unsafe extern "C" fn(vp: *mut ImGuiViewport, size: *const ImVec2),
1063) -> bool {
1064 #[cfg(dear_imgui_rs_platform_io_hooks)]
1065 unsafe {
1066 return dear_imgui_rs_platform_io_renderer_set_window_size_matches_pointer_param(
1067 platform_io,
1068 user_callback,
1069 ) != 0;
1070 }
1071
1072 #[cfg(not(dear_imgui_rs_platform_io_hooks))]
1073 {
1074 let _ = platform_io;
1075 let _ = user_callback;
1076 false
1077 }
1078}
1079
1080#[doc(hidden)]
1085#[inline]
1086pub unsafe fn ImGuiPlatformIO_RendererSetWindowSizePointerParam(
1087 platform_io: *mut ImGuiPlatformIO,
1088) -> Option<unsafe extern "C" fn(vp: *mut ImGuiViewport, size: *const ImVec2)> {
1089 #[cfg(dear_imgui_rs_platform_io_hooks)]
1090 unsafe {
1091 let mut callback = None;
1092 if dear_imgui_rs_platform_io_get_renderer_set_window_size_pointer_param(
1093 platform_io,
1094 &mut callback,
1095 ) != 0
1096 {
1097 return callback;
1098 }
1099 None
1100 }
1101
1102 #[cfg(not(dear_imgui_rs_platform_io_hooks))]
1103 {
1104 let _ = platform_io;
1105 None
1106 }
1107}
1108
1109#[doc(hidden)]
1113#[inline]
1114pub unsafe fn ImGuiPlatformIO_ClearRendererSetWindowSizeIfPointerParam(
1115 platform_io: *mut ImGuiPlatformIO,
1116 user_callback: unsafe extern "C" fn(vp: *mut ImGuiViewport, size: *const ImVec2),
1117) -> bool {
1118 #[cfg(dear_imgui_rs_platform_io_hooks)]
1119 unsafe {
1120 return dear_imgui_rs_platform_io_clear_renderer_set_window_size_if_pointer_param(
1121 platform_io,
1122 user_callback,
1123 ) != 0;
1124 }
1125
1126 #[cfg(not(dear_imgui_rs_platform_io_hooks))]
1127 {
1128 let _ = platform_io;
1129 let _ = user_callback;
1130 false
1131 }
1132}
1133
1134#[inline]
1144pub unsafe fn ImGuiPlatformIO_ProbeAggregateCallbacks(
1145 platform_io: *mut ImGuiPlatformIO,
1146 out_result: *mut DearImguiRsPlatformIoAggregateProbeResult,
1147) -> bool {
1148 #[cfg(dear_imgui_rs_platform_io_hooks)]
1149 unsafe {
1150 return dear_imgui_rs_platform_io_probe_aggregate_callbacks(platform_io, out_result) != 0;
1151 }
1152
1153 #[cfg(not(dear_imgui_rs_platform_io_hooks))]
1154 {
1155 let _ = platform_io;
1156 let _ = out_result;
1157 false
1158 }
1159}
1160
1161#[doc(hidden)]
1174#[inline]
1175pub unsafe fn ImGuiPlatformIO_InvokePlatformSetWindowPos(
1176 callbacks: *const ImGuiPlatformIO,
1177 viewport: *mut ImGuiViewport,
1178 pos: *const ImVec2,
1179) -> bool {
1180 #[cfg(dear_imgui_rs_platform_io_hooks)]
1181 unsafe {
1182 return dear_imgui_rs_platform_io_invoke_platform_set_window_pos(callbacks, viewport, pos)
1183 != 0;
1184 }
1185
1186 #[cfg(not(dear_imgui_rs_platform_io_hooks))]
1187 {
1188 let _ = callbacks;
1189 let _ = viewport;
1190 let _ = pos;
1191 false
1192 }
1193}
1194
1195#[doc(hidden)]
1208#[inline]
1209pub unsafe fn ImGuiPlatformIO_InvokePlatformSetWindowSize(
1210 callbacks: *const ImGuiPlatformIO,
1211 viewport: *mut ImGuiViewport,
1212 size: *const ImVec2,
1213) -> bool {
1214 #[cfg(dear_imgui_rs_platform_io_hooks)]
1215 unsafe {
1216 return dear_imgui_rs_platform_io_invoke_platform_set_window_size(
1217 callbacks, viewport, size,
1218 ) != 0;
1219 }
1220
1221 #[cfg(not(dear_imgui_rs_platform_io_hooks))]
1222 {
1223 let _ = callbacks;
1224 let _ = viewport;
1225 let _ = size;
1226 false
1227 }
1228}
1229
1230#[doc(hidden)]
1242#[inline]
1243pub unsafe fn ImGuiPlatformIO_InvokePlatformGetWindowPos(
1244 callbacks: *const ImGuiPlatformIO,
1245 viewport: *mut ImGuiViewport,
1246 out_pos: *mut ImVec2,
1247) -> bool {
1248 #[cfg(dear_imgui_rs_platform_io_hooks)]
1249 unsafe {
1250 return dear_imgui_rs_platform_io_invoke_platform_get_window_pos(
1251 callbacks, viewport, out_pos,
1252 ) != 0;
1253 }
1254
1255 #[cfg(not(dear_imgui_rs_platform_io_hooks))]
1256 unsafe {
1257 if !out_pos.is_null() {
1258 out_pos.write(ImVec2 { x: 0.0, y: 0.0 });
1259 }
1260 let _ = callbacks;
1261 let _ = viewport;
1262 false
1263 }
1264}
1265
1266#[doc(hidden)]
1278#[inline]
1279pub unsafe fn ImGuiPlatformIO_InvokePlatformGetWindowSize(
1280 callbacks: *const ImGuiPlatformIO,
1281 viewport: *mut ImGuiViewport,
1282 out_size: *mut ImVec2,
1283) -> bool {
1284 #[cfg(dear_imgui_rs_platform_io_hooks)]
1285 unsafe {
1286 return dear_imgui_rs_platform_io_invoke_platform_get_window_size(
1287 callbacks, viewport, out_size,
1288 ) != 0;
1289 }
1290
1291 #[cfg(not(dear_imgui_rs_platform_io_hooks))]
1292 unsafe {
1293 if !out_size.is_null() {
1294 out_size.write(ImVec2 { x: 0.0, y: 0.0 });
1295 }
1296 let _ = callbacks;
1297 let _ = viewport;
1298 false
1299 }
1300}
1301
1302#[doc(hidden)]
1314#[inline]
1315pub unsafe fn ImGuiPlatformIO_InvokePlatformGetWindowFramebufferScale(
1316 callbacks: *const ImGuiPlatformIO,
1317 viewport: *mut ImGuiViewport,
1318 out_scale: *mut ImVec2,
1319) -> bool {
1320 #[cfg(dear_imgui_rs_platform_io_hooks)]
1321 unsafe {
1322 return dear_imgui_rs_platform_io_invoke_platform_get_window_framebuffer_scale(
1323 callbacks, viewport, out_scale,
1324 ) != 0;
1325 }
1326
1327 #[cfg(not(dear_imgui_rs_platform_io_hooks))]
1328 unsafe {
1329 if !out_scale.is_null() {
1330 out_scale.write(ImVec2 { x: 0.0, y: 0.0 });
1331 }
1332 let _ = callbacks;
1333 let _ = viewport;
1334 false
1335 }
1336}
1337
1338#[doc(hidden)]
1348#[inline]
1349pub unsafe fn ImGuiPlatformIO_InvokeRendererSetWindowSize(
1350 callbacks: *const ImGuiPlatformIO,
1351 viewport: *mut ImGuiViewport,
1352 size: *const ImVec2,
1353) -> bool {
1354 #[cfg(dear_imgui_rs_platform_io_hooks)]
1355 unsafe {
1356 return dear_imgui_rs_platform_io_invoke_renderer_set_window_size(
1357 callbacks, viewport, size,
1358 ) != 0;
1359 }
1360
1361 #[cfg(not(dear_imgui_rs_platform_io_hooks))]
1362 {
1363 let _ = callbacks;
1364 let _ = viewport;
1365 let _ = size;
1366 false
1367 }
1368}
1369
1370#[doc(hidden)]
1379#[inline]
1380pub unsafe fn ImGuiPlatformIO_AggregateCallbackStorageCount() -> usize {
1381 #[cfg(dear_imgui_rs_platform_io_hooks)]
1382 unsafe {
1383 return dear_imgui_rs_platform_io_aggregate_callback_storage_count() as usize;
1384 }
1385
1386 #[cfg(not(dear_imgui_rs_platform_io_hooks))]
1387 {
1388 0
1389 }
1390}
1391
1392pub use ImColor as Color;
1394pub use ImVec2 as Vector2;
1395pub use ImVec4 as Vector4;
1396
1397pub const BINDING_VERSION: &str = env!("CARGO_PKG_VERSION");
1401
1402pub const HAS_DOCKING: bool = true;
1404
1405#[cfg(feature = "freetype")]
1407pub const HAS_FREETYPE: bool = true;
1408
1409#[cfg(not(feature = "freetype"))]
1410pub const HAS_FREETYPE: bool = false;
1411
1412#[cfg(all(dear_imgui_rs_wasm_import_target, feature = "wasm"))]
1414pub const HAS_WASM: bool = true;
1415
1416#[cfg(not(all(dear_imgui_rs_wasm_import_target, feature = "wasm")))]
1417pub const HAS_WASM: bool = false;
1418
1419#[cfg(test)]
1420mod target_contract_tests {
1421 #[test]
1422 fn wasm_availability_requires_the_build_selected_import_target() {
1423 assert_eq!(
1424 super::HAS_WASM,
1425 cfg!(all(dear_imgui_rs_wasm_import_target, feature = "wasm"))
1426 );
1427 }
1428}
1429
1430#[cfg(all(test, not(dear_imgui_rs_platform_io_hooks)))]
1431mod aggregate_setter_fallback_tests {
1432 use std::panic::{AssertUnwindSafe, catch_unwind};
1433 use std::ptr;
1434
1435 use super::*;
1436
1437 unsafe extern "C" fn set_vec2_pointer(_viewport: *mut ImGuiViewport, _value: *const ImVec2) {}
1438
1439 unsafe extern "C" fn get_vec2_out(_viewport: *mut ImGuiViewport, _value: *mut ImVec2) {}
1440
1441 unsafe extern "C" fn get_vec4_out(_viewport: *mut ImGuiViewport, _value: *mut ImVec4) {}
1442
1443 unsafe extern "C" fn raw_set_vec2(_viewport: *mut ImGuiViewport, _value: ImVec2) {}
1444
1445 unsafe extern "C" fn raw_get_vec2(_viewport: *mut ImGuiViewport) -> ImVec2 {
1446 ImVec2::zero()
1447 }
1448
1449 unsafe extern "C" fn raw_get_vec4(_viewport: *mut ImGuiViewport) -> ImVec4 {
1450 ImVec4::zero()
1451 }
1452
1453 fn assert_panics(action: impl FnOnce()) {
1454 assert!(catch_unwind(AssertUnwindSafe(action)).is_err());
1455 }
1456
1457 #[test]
1458 fn aggregate_setters_without_cpp_hooks_reject_some_callbacks() {
1459 assert_panics(|| unsafe {
1460 ImGuiPlatformIO_Set_Platform_SetWindowPos_PointerParam(
1461 ptr::null_mut(),
1462 Some(set_vec2_pointer),
1463 );
1464 });
1465 assert_panics(|| unsafe {
1466 ImGuiPlatformIO_Set_Platform_GetWindowPos_OutParam(ptr::null_mut(), Some(get_vec2_out));
1467 });
1468 assert_panics(|| unsafe {
1469 ImGuiPlatformIO_Set_Platform_SetWindowSize_PointerParam(
1470 ptr::null_mut(),
1471 Some(set_vec2_pointer),
1472 );
1473 });
1474 assert_panics(|| unsafe {
1475 ImGuiPlatformIO_Set_Platform_GetWindowSize_OutParam(
1476 ptr::null_mut(),
1477 Some(get_vec2_out),
1478 );
1479 });
1480 assert_panics(|| unsafe {
1481 ImGuiPlatformIO_Set_Platform_GetWindowFramebufferScale_OutParam(
1482 ptr::null_mut(),
1483 Some(get_vec2_out),
1484 );
1485 });
1486 assert_panics(|| unsafe {
1487 ImGuiPlatformIO_Set_Platform_GetWindowWorkAreaInsets_OutParam(
1488 ptr::null_mut(),
1489 Some(get_vec4_out),
1490 );
1491 });
1492 assert_panics(|| unsafe {
1493 ImGuiPlatformIO_Set_Renderer_SetWindowSize_PointerParam(
1494 ptr::null_mut(),
1495 Some(set_vec2_pointer),
1496 );
1497 });
1498 }
1499
1500 #[test]
1501 fn aggregate_setters_without_cpp_hooks_clear_matching_raw_slots() {
1502 let mut platform_io = ImGuiPlatformIO {
1503 Platform_SetWindowPos: Some(raw_set_vec2),
1504 Platform_GetWindowPos: Some(raw_get_vec2),
1505 Platform_SetWindowSize: Some(raw_set_vec2),
1506 Platform_GetWindowSize: Some(raw_get_vec2),
1507 Platform_GetWindowFramebufferScale: Some(raw_get_vec2),
1508 Platform_GetWindowWorkAreaInsets: Some(raw_get_vec4),
1509 Renderer_SetWindowSize: Some(raw_set_vec2),
1510 ..ImGuiPlatformIO::default()
1511 };
1512
1513 unsafe {
1514 ImGuiPlatformIO_Set_Platform_SetWindowPos_PointerParam(&mut platform_io, None);
1515 }
1516 assert!(platform_io.Platform_SetWindowPos.is_none());
1517 assert!(platform_io.Platform_GetWindowPos.is_some());
1518
1519 unsafe {
1520 ImGuiPlatformIO_Set_Platform_GetWindowPos_OutParam(&mut platform_io, None);
1521 }
1522 assert!(platform_io.Platform_GetWindowPos.is_none());
1523 assert!(platform_io.Platform_SetWindowSize.is_some());
1524
1525 unsafe {
1526 ImGuiPlatformIO_Set_Platform_SetWindowSize_PointerParam(&mut platform_io, None);
1527 }
1528 assert!(platform_io.Platform_SetWindowSize.is_none());
1529 assert!(platform_io.Platform_GetWindowSize.is_some());
1530
1531 unsafe {
1532 ImGuiPlatformIO_Set_Platform_GetWindowSize_OutParam(&mut platform_io, None);
1533 }
1534 assert!(platform_io.Platform_GetWindowSize.is_none());
1535 assert!(platform_io.Platform_GetWindowFramebufferScale.is_some());
1536
1537 unsafe {
1538 ImGuiPlatformIO_Set_Platform_GetWindowFramebufferScale_OutParam(&mut platform_io, None);
1539 }
1540 assert!(platform_io.Platform_GetWindowFramebufferScale.is_none());
1541 assert!(platform_io.Platform_GetWindowWorkAreaInsets.is_some());
1542
1543 unsafe {
1544 ImGuiPlatformIO_Set_Platform_GetWindowWorkAreaInsets_OutParam(&mut platform_io, None);
1545 }
1546 assert!(platform_io.Platform_GetWindowWorkAreaInsets.is_none());
1547 assert!(platform_io.Renderer_SetWindowSize.is_some());
1548
1549 unsafe {
1550 ImGuiPlatformIO_Set_Renderer_SetWindowSize_PointerParam(&mut platform_io, None);
1551 }
1552 assert!(platform_io.Renderer_SetWindowSize.is_none());
1553 }
1554}
1555
1556#[cfg(all(test, dear_imgui_rs_platform_io_hooks))]
1557mod aggregate_callback_identity_tests {
1558 use super::*;
1559
1560 type SetCallback = unsafe extern "C" fn(*mut ImGuiViewport, *const ImVec2);
1561 type GetCallback = unsafe extern "C" fn(*mut ImGuiViewport, *mut ImVec2);
1562
1563 unsafe extern "C" fn set_a(_viewport: *mut ImGuiViewport, _value: *const ImVec2) {}
1564
1565 unsafe extern "C" fn set_b(_viewport: *mut ImGuiViewport, _value: *const ImVec2) {}
1566
1567 unsafe extern "C" fn get_a(_viewport: *mut ImGuiViewport, _value: *mut ImVec2) {}
1568
1569 unsafe extern "C" fn get_b(_viewport: *mut ImGuiViewport, _value: *mut ImVec2) {}
1570
1571 fn assert_set_identity(
1572 platform_io: &mut ImGuiPlatformIO,
1573 install: unsafe fn(*mut ImGuiPlatformIO, Option<SetCallback>),
1574 raw_slot_address: fn(&ImGuiPlatformIO) -> usize,
1575 query: unsafe fn(*mut ImGuiPlatformIO) -> Option<SetCallback>,
1576 ) {
1577 unsafe { install(platform_io, Some(set_a)) };
1578 let hook = raw_slot_address(platform_io);
1579 unsafe { install(platform_io, Some(set_b)) };
1580 assert_eq!(raw_slot_address(platform_io), hook);
1581 assert!(std::ptr::fn_addr_eq(
1582 unsafe { query(platform_io) }.unwrap(),
1583 set_b as SetCallback
1584 ));
1585 assert!(
1586 raw_slot_address(platform_io) == hook,
1587 "query must not mutate the raw slot"
1588 );
1589 assert!(
1590 std::ptr::fn_addr_eq(unsafe { query(platform_io) }.unwrap(), set_b as SetCallback),
1591 "query must not mutate hook storage"
1592 );
1593 unsafe { install(platform_io, None) };
1594 }
1595
1596 fn assert_get_identity(
1597 platform_io: &mut ImGuiPlatformIO,
1598 install: unsafe fn(*mut ImGuiPlatformIO, Option<GetCallback>),
1599 raw_slot_address: fn(&ImGuiPlatformIO) -> usize,
1600 query: unsafe fn(*mut ImGuiPlatformIO) -> Option<GetCallback>,
1601 ) {
1602 unsafe { install(platform_io, Some(get_a)) };
1603 let hook = raw_slot_address(platform_io);
1604 unsafe { install(platform_io, Some(get_b)) };
1605 assert_eq!(raw_slot_address(platform_io), hook);
1606 assert!(std::ptr::fn_addr_eq(
1607 unsafe { query(platform_io) }.unwrap(),
1608 get_b as GetCallback
1609 ));
1610 assert!(
1611 raw_slot_address(platform_io) == hook,
1612 "query must not mutate the raw slot"
1613 );
1614 assert!(
1615 std::ptr::fn_addr_eq(unsafe { query(platform_io) }.unwrap(), get_b as GetCallback),
1616 "query must not mutate hook storage"
1617 );
1618 unsafe { install(platform_io, None) };
1619 }
1620
1621 #[test]
1622 fn platform_vec2_hooks_expose_exact_callback_identity_without_mutation() {
1623 let mut platform_io = ImGuiPlatformIO::default();
1624
1625 assert_set_identity(
1626 &mut platform_io,
1627 ImGuiPlatformIO_Set_Platform_SetWindowPos_PointerParam,
1628 |io| io.Platform_SetWindowPos.unwrap() as usize,
1629 ImGuiPlatformIO_PlatformSetWindowPosPointerParam,
1630 );
1631 assert_set_identity(
1632 &mut platform_io,
1633 ImGuiPlatformIO_Set_Platform_SetWindowSize_PointerParam,
1634 |io| io.Platform_SetWindowSize.unwrap() as usize,
1635 ImGuiPlatformIO_PlatformSetWindowSizePointerParam,
1636 );
1637 assert_get_identity(
1638 &mut platform_io,
1639 ImGuiPlatformIO_Set_Platform_GetWindowPos_OutParam,
1640 |io| io.Platform_GetWindowPos.unwrap() as usize,
1641 ImGuiPlatformIO_PlatformGetWindowPosOutParam,
1642 );
1643 assert_get_identity(
1644 &mut platform_io,
1645 ImGuiPlatformIO_Set_Platform_GetWindowSize_OutParam,
1646 |io| io.Platform_GetWindowSize.unwrap() as usize,
1647 ImGuiPlatformIO_PlatformGetWindowSizeOutParam,
1648 );
1649 assert_get_identity(
1650 &mut platform_io,
1651 ImGuiPlatformIO_Set_Platform_GetWindowFramebufferScale_OutParam,
1652 |io| io.Platform_GetWindowFramebufferScale.unwrap() as usize,
1653 ImGuiPlatformIO_PlatformGetWindowFramebufferScaleOutParam,
1654 );
1655 }
1656}
1657
1658impl ImVec2 {
1661 #[inline]
1662 pub const fn new(x: f32, y: f32) -> ImVec2 {
1663 ImVec2 { x, y }
1664 }
1665
1666 #[inline]
1667 pub const fn zero() -> ImVec2 {
1668 ImVec2 { x: 0.0, y: 0.0 }
1669 }
1670}
1671
1672impl From<[f32; 2]> for ImVec2 {
1673 #[inline]
1674 fn from(array: [f32; 2]) -> ImVec2 {
1675 ImVec2::new(array[0], array[1])
1676 }
1677}
1678
1679impl From<(f32, f32)> for ImVec2 {
1680 #[inline]
1681 fn from((x, y): (f32, f32)) -> ImVec2 {
1682 ImVec2::new(x, y)
1683 }
1684}
1685
1686impl From<ImVec2> for [f32; 2] {
1687 #[inline]
1688 fn from(v: ImVec2) -> [f32; 2] {
1689 [v.x, v.y]
1690 }
1691}
1692
1693impl From<ImVec2> for (f32, f32) {
1694 #[inline]
1695 fn from(v: ImVec2) -> (f32, f32) {
1696 (v.x, v.y)
1697 }
1698}
1699
1700impl From<mint::Vector2<f32>> for ImVec2 {
1701 #[inline]
1702 fn from(v: mint::Vector2<f32>) -> ImVec2 {
1703 ImVec2::new(v.x, v.y)
1704 }
1705}
1706
1707#[cfg(feature = "glam")]
1708impl From<glam::Vec2> for ImVec2 {
1709 #[inline]
1710 fn from(v: glam::Vec2) -> ImVec2 {
1711 ImVec2::new(v.x, v.y)
1712 }
1713}
1714
1715impl ImVec4 {
1716 #[inline]
1717 pub const fn new(x: f32, y: f32, z: f32, w: f32) -> ImVec4 {
1718 ImVec4 { x, y, z, w }
1719 }
1720
1721 #[inline]
1722 pub const fn zero() -> ImVec4 {
1723 ImVec4 {
1724 x: 0.0,
1725 y: 0.0,
1726 z: 0.0,
1727 w: 0.0,
1728 }
1729 }
1730}
1731
1732impl From<[f32; 4]> for ImVec4 {
1733 #[inline]
1734 fn from(array: [f32; 4]) -> ImVec4 {
1735 ImVec4::new(array[0], array[1], array[2], array[3])
1736 }
1737}
1738
1739impl From<(f32, f32, f32, f32)> for ImVec4 {
1740 #[inline]
1741 fn from((x, y, z, w): (f32, f32, f32, f32)) -> ImVec4 {
1742 ImVec4::new(x, y, z, w)
1743 }
1744}
1745
1746impl From<ImVec4> for [f32; 4] {
1747 #[inline]
1748 fn from(v: ImVec4) -> [f32; 4] {
1749 [v.x, v.y, v.z, v.w]
1750 }
1751}
1752
1753impl From<ImVec4> for (f32, f32, f32, f32) {
1754 #[inline]
1755 fn from(v: ImVec4) -> (f32, f32, f32, f32) {
1756 (v.x, v.y, v.z, v.w)
1757 }
1758}
1759
1760impl From<mint::Vector4<f32>> for ImVec4 {
1761 #[inline]
1762 fn from(v: mint::Vector4<f32>) -> ImVec4 {
1763 ImVec4::new(v.x, v.y, v.z, v.w)
1764 }
1765}
1766
1767#[cfg(feature = "glam")]
1768impl From<glam::Vec4> for ImVec4 {
1769 #[inline]
1770 fn from(v: glam::Vec4) -> ImVec4 {
1771 ImVec4::new(v.x, v.y, v.z, v.w)
1772 }
1773}