dear_imgui_sys/
wrapper_functions.rs

1// Windows-specific function wrappers to handle ABI issues
2// This module provides C-style wrappers for functions that have ABI issues on Windows
3
4use crate::*;
5
6// For now, we'll provide placeholder implementations
7// These should be replaced with actual function calls once the FFI is working
8
9#[cfg(target_os = "windows")]
10pub mod windows {
11    use super::*;
12
13    // Real implementations using the actual Dear ImGui functions
14    pub unsafe fn get_version() -> *const std::os::raw::c_char {
15        crate::ImGui_GetVersion()
16    }
17
18    pub unsafe fn create_context(shared_font_atlas: *mut ImFontAtlas) -> *mut ImGuiContext {
19        crate::ImGui_CreateContext(shared_font_atlas)
20    }
21
22    pub unsafe fn destroy_context(ctx: *mut ImGuiContext) {
23        crate::ImGui_DestroyContext(ctx)
24    }
25
26    pub unsafe fn get_current_context() -> *mut ImGuiContext {
27        crate::ImGui_GetCurrentContext()
28    }
29
30    pub unsafe fn set_current_context(ctx: *mut ImGuiContext) {
31        crate::ImGui_SetCurrentContext(ctx)
32    }
33
34    pub unsafe fn get_io() -> *mut ImGuiIO {
35        crate::ImGui_GetIO()
36    }
37
38    pub unsafe fn get_style() -> *mut ImGuiStyle {
39        crate::ImGui_GetStyle()
40    }
41
42    pub unsafe fn new_frame() {
43        crate::ImGui_NewFrame()
44    }
45
46    pub unsafe fn render() {
47        crate::ImGui_Render()
48    }
49
50    pub unsafe fn get_draw_data() -> *mut ImDrawData {
51        crate::ImGui_GetDrawData()
52    }
53
54    pub unsafe fn text_unformatted(
55        text: *const std::os::raw::c_char,
56        text_end: *const std::os::raw::c_char,
57    ) {
58        crate::ImGui_TextUnformatted(text, text_end)
59    }
60
61    pub unsafe fn button(label: *const std::os::raw::c_char, size: ImVec2) -> bool {
62        crate::ImGui_Button(label, &size)
63    }
64
65    pub unsafe fn begin(
66        name: *const std::os::raw::c_char,
67        p_open: *mut bool,
68        flags: ImGuiWindowFlags,
69    ) -> bool {
70        crate::ImGui_Begin(name, p_open, flags)
71    }
72
73    pub unsafe fn end() {
74        crate::ImGui_End()
75    }
76
77    pub unsafe fn set_next_window_size(size: ImVec2, cond: ImGuiCond) {
78        crate::ImGui_SetNextWindowSize(&size, cond)
79    }
80
81    pub unsafe fn set_next_window_pos(pos: ImVec2, cond: ImGuiCond, pivot: ImVec2) {
82        crate::ImGui_SetNextWindowPos(&pos, cond, &pivot)
83    }
84
85    pub unsafe fn set_next_window_size_constraints(
86        size_min: ImVec2,
87        size_max: ImVec2,
88        custom_callback: Option<unsafe extern "C" fn(*mut ImGuiSizeCallbackData)>,
89        custom_callback_data: *mut std::os::raw::c_void,
90    ) {
91        crate::ImGui_SetNextWindowSizeConstraints(
92            &size_min,
93            &size_max,
94            custom_callback,
95            custom_callback_data,
96        )
97    }
98}
99
100#[cfg(all(not(target_os = "windows"), feature = "wasm"))]
101pub mod wasm {
102    use super::*;
103
104    // For WASM, use the same ImGui_* function names as native for consistency
105    pub use crate::ImGui_Begin as begin;
106    pub use crate::ImGui_Button as button;
107    pub use crate::ImGui_CreateContext as create_context;
108    pub use crate::ImGui_DestroyContext as destroy_context;
109    pub use crate::ImGui_End as end;
110    pub use crate::ImGui_GetCurrentContext as get_current_context;
111    pub use crate::ImGui_GetDrawData as get_draw_data;
112    pub use crate::ImGui_GetIO as get_io;
113    pub use crate::ImGui_GetStyle as get_style;
114    pub use crate::ImGui_GetVersion as get_version;
115    pub use crate::ImGui_NewFrame as new_frame;
116    pub use crate::ImGui_Render as render;
117    pub use crate::ImGui_SetCurrentContext as set_current_context;
118    pub use crate::ImGui_SetNextWindowPos as set_next_window_pos;
119    pub use crate::ImGui_SetNextWindowSize as set_next_window_size;
120    pub use crate::ImGui_SetNextWindowSizeConstraints as set_next_window_size_constraints;
121    pub use crate::ImGui_Text as text;
122    pub use crate::ImGui_TextUnformatted as text_unformatted;
123}
124
125#[cfg(all(not(target_os = "windows"), not(feature = "wasm")))]
126pub mod unix {
127    use super::*;
128
129    // On non-Windows native platforms, use the ImGui_* function names
130    pub use crate::ImGui_Begin as begin;
131    pub use crate::ImGui_Button as button;
132    pub use crate::ImGui_CreateContext as create_context;
133    pub use crate::ImGui_DestroyContext as destroy_context;
134    pub use crate::ImGui_End as end;
135    pub use crate::ImGui_GetCurrentContext as get_current_context;
136    pub use crate::ImGui_GetDrawData as get_draw_data;
137    pub use crate::ImGui_GetIO as get_io;
138    pub use crate::ImGui_GetStyle as get_style;
139    pub use crate::ImGui_GetVersion as get_version;
140    pub use crate::ImGui_NewFrame as new_frame;
141    pub use crate::ImGui_Render as render;
142    pub use crate::ImGui_SetCurrentContext as set_current_context;
143    pub use crate::ImGui_SetNextWindowPos as set_next_window_pos;
144    pub use crate::ImGui_SetNextWindowSize as set_next_window_size;
145    pub use crate::ImGui_SetNextWindowSizeConstraints as set_next_window_size_constraints;
146    pub use crate::ImGui_TextUnformatted as text_unformatted;
147}
148
149// Public API that automatically selects the right implementation
150#[cfg(target_os = "windows")]
151pub use windows::*;
152
153#[cfg(all(not(target_os = "windows"), feature = "wasm"))]
154pub use wasm::*;
155
156#[cfg(all(not(target_os = "windows"), not(feature = "wasm")))]
157pub use unix::*;