dear_imgui_sys/
lib.rs

1//! Low-level FFI bindings for Dear ImGui (via cimgui C API) with docking support
2//!
3//! This crate provides raw, unsafe bindings to Dear ImGui using the cimgui C API,
4//! specifically targeting the docking branch (multi-viewport capable).
5//!
6//! ## Features
7//!
8//! - **docking**: Enable docking and multi-viewport features (default)
9//! - **freetype**: Enable FreeType font rasterizer support
10//! - **wasm**: Enable WebAssembly compatibility
11//!
12//! ## WebAssembly Support
13//!
14//! When the `wasm` feature is enabled, this crate provides full WASM compatibility:
15//! - Disables platform-specific functions (file I/O, shell functions, etc.)
16//! - Configures Dear ImGui for WASM environment
17//! - Compatible with wasm-bindgen and web targets
18//!
19//! ## Safety
20//!
21//! This crate provides raw FFI bindings and is inherently unsafe. Users should
22//! prefer the high-level `dear-imgui-rs` crate for safe Rust bindings.
23//!
24//! ## Usage
25//!
26//! This crate is typically not used directly. Instead, use the `dear-imgui-rs` crate
27//! which provides safe, idiomatic Rust bindings built on top of these FFI bindings.
28
29#![allow(non_upper_case_globals)]
30#![allow(non_camel_case_types)]
31#![allow(non_snake_case)]
32#![allow(dead_code)]
33#![allow(unnecessary_transmutes)]
34#![allow(clippy::all)]
35// Bindgen may derive Eq/Hash for structs containing function pointers.
36// New Clippy lint warns these comparisons are unpredictable; suppress for raw FFI types.
37#![allow(unpredictable_function_pointer_comparisons)]
38
39// Bindings are generated into OUT_DIR and included via a submodule so that
40// possible inner attributes in the generated file are accepted at module root.
41mod ffi;
42pub use ffi::*;
43
44// This project always builds Dear ImGui with `IMGUI_USE_WCHAR32`, so `ImWchar` must be 32-bit.
45const _: [(); 4] = [(); std::mem::size_of::<ImWchar>()];
46
47// Ensure common ImGui typedefs are available even if bindgen doesn't emit them explicitly
48
49// cimgui exposes typed vectors (e.g., ImVector_ImVec2) instead of a generic ImVector<T>.
50// The sys crate intentionally avoids adding higher-level helpers here.
51
52// cimgui C API avoids C++ ABI pitfalls; no MSVC-specific conversions are required.
53
54// Re-export commonly used types for convenience
55pub use ImColor as Color;
56pub use ImVec2 as Vector2;
57pub use ImVec4 as Vector4;
58
59/// Version information for the Dear ImGui library
60pub const IMGUI_VERSION: &str = env!("CARGO_PKG_VERSION");
61
62/// Docking features are always available in this crate
63pub const HAS_DOCKING: bool = true;
64
65/// Check if FreeType support is available
66#[cfg(feature = "freetype")]
67pub const HAS_FREETYPE: bool = true;
68
69#[cfg(not(feature = "freetype"))]
70pub const HAS_FREETYPE: bool = false;
71
72/// Check if WASM support is available
73#[cfg(feature = "wasm")]
74pub const HAS_WASM: bool = true;
75
76#[cfg(not(feature = "wasm"))]
77pub const HAS_WASM: bool = false;
78
79// (No wasm-specific shims are required when using shared memory import style.)
80
81impl ImVec2 {
82    #[inline]
83    pub const fn new(x: f32, y: f32) -> ImVec2 {
84        ImVec2 { x, y }
85    }
86
87    #[inline]
88    pub const fn zero() -> ImVec2 {
89        ImVec2 { x: 0.0, y: 0.0 }
90    }
91}
92
93impl From<[f32; 2]> for ImVec2 {
94    #[inline]
95    fn from(array: [f32; 2]) -> ImVec2 {
96        ImVec2::new(array[0], array[1])
97    }
98}
99
100impl From<(f32, f32)> for ImVec2 {
101    #[inline]
102    fn from((x, y): (f32, f32)) -> ImVec2 {
103        ImVec2::new(x, y)
104    }
105}
106
107impl From<ImVec2> for [f32; 2] {
108    #[inline]
109    fn from(v: ImVec2) -> [f32; 2] {
110        [v.x, v.y]
111    }
112}
113
114impl From<ImVec2> for (f32, f32) {
115    #[inline]
116    fn from(v: ImVec2) -> (f32, f32) {
117        (v.x, v.y)
118    }
119}
120
121impl From<mint::Vector2<f32>> for ImVec2 {
122    #[inline]
123    fn from(v: mint::Vector2<f32>) -> ImVec2 {
124        ImVec2::new(v.x, v.y)
125    }
126}
127
128#[cfg(feature = "glam")]
129impl From<glam::Vec2> for ImVec2 {
130    #[inline]
131    fn from(v: glam::Vec2) -> ImVec2 {
132        ImVec2::new(v.x, v.y)
133    }
134}
135
136impl ImVec4 {
137    #[inline]
138    pub const fn new(x: f32, y: f32, z: f32, w: f32) -> ImVec4 {
139        ImVec4 { x, y, z, w }
140    }
141
142    #[inline]
143    pub const fn zero() -> ImVec4 {
144        ImVec4 {
145            x: 0.0,
146            y: 0.0,
147            z: 0.0,
148            w: 0.0,
149        }
150    }
151}
152
153impl From<[f32; 4]> for ImVec4 {
154    #[inline]
155    fn from(array: [f32; 4]) -> ImVec4 {
156        ImVec4::new(array[0], array[1], array[2], array[3])
157    }
158}
159
160impl From<(f32, f32, f32, f32)> for ImVec4 {
161    #[inline]
162    fn from((x, y, z, w): (f32, f32, f32, f32)) -> ImVec4 {
163        ImVec4::new(x, y, z, w)
164    }
165}
166
167impl From<ImVec4> for [f32; 4] {
168    #[inline]
169    fn from(v: ImVec4) -> [f32; 4] {
170        [v.x, v.y, v.z, v.w]
171    }
172}
173
174impl From<ImVec4> for (f32, f32, f32, f32) {
175    #[inline]
176    fn from(v: ImVec4) -> (f32, f32, f32, f32) {
177        (v.x, v.y, v.z, v.w)
178    }
179}
180
181impl From<mint::Vector4<f32>> for ImVec4 {
182    #[inline]
183    fn from(v: mint::Vector4<f32>) -> ImVec4 {
184        ImVec4::new(v.x, v.y, v.z, v.w)
185    }
186}
187
188#[cfg(feature = "glam")]
189impl From<glam::Vec4> for ImVec4 {
190    #[inline]
191    fn from(v: glam::Vec4) -> ImVec4 {
192        ImVec4::new(v.x, v.y, v.z, v.w)
193    }
194}