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` crate for safe Rust bindings.
23//!
24//! ## Usage
25//!
26//! This crate is typically not used directly. Instead, use the `dear-imgui` 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// Ensure common ImGui typedefs are available even if bindgen doesn't emit them explicitly
45
46// cimgui exposes typed vectors (e.g., ImVector_ImVec2) instead of a generic ImVector<T>.
47// The sys crate intentionally avoids adding higher-level helpers here.
48
49// cimgui C API avoids C++ ABI pitfalls; no MSVC-specific conversions are required.
50
51// Re-export commonly used types for convenience
52pub use ImColor as Color;
53pub use ImVec2 as Vector2;
54pub use ImVec4 as Vector4;
55
56/// Version information for the Dear ImGui library
57pub const IMGUI_VERSION: &str = env!("CARGO_PKG_VERSION");
58
59/// Docking features are always available in this crate
60pub const HAS_DOCKING: bool = true;
61
62/// Check if FreeType support is available
63#[cfg(feature = "freetype")]
64pub const HAS_FREETYPE: bool = true;
65
66#[cfg(not(feature = "freetype"))]
67pub const HAS_FREETYPE: bool = false;
68
69/// Check if WASM support is available
70#[cfg(feature = "wasm")]
71pub const HAS_WASM: bool = true;
72
73#[cfg(not(feature = "wasm"))]
74pub const HAS_WASM: bool = false;
75
76// (No wasm-specific shims are required when using shared memory import style.)
77
78impl ImVec2 {
79    #[inline]
80    pub const fn new(x: f32, y: f32) -> ImVec2 {
81        ImVec2 { x, y }
82    }
83
84    #[inline]
85    pub const fn zero() -> ImVec2 {
86        ImVec2 { x: 0.0, y: 0.0 }
87    }
88}
89
90impl From<[f32; 2]> for ImVec2 {
91    #[inline]
92    fn from(array: [f32; 2]) -> ImVec2 {
93        ImVec2::new(array[0], array[1])
94    }
95}
96
97impl From<(f32, f32)> for ImVec2 {
98    #[inline]
99    fn from((x, y): (f32, f32)) -> ImVec2 {
100        ImVec2::new(x, y)
101    }
102}
103
104impl From<ImVec2> for [f32; 2] {
105    #[inline]
106    fn from(v: ImVec2) -> [f32; 2] {
107        [v.x, v.y]
108    }
109}
110
111impl From<ImVec2> for (f32, f32) {
112    #[inline]
113    fn from(v: ImVec2) -> (f32, f32) {
114        (v.x, v.y)
115    }
116}
117
118impl From<mint::Vector2<f32>> for ImVec2 {
119    #[inline]
120    fn from(v: mint::Vector2<f32>) -> ImVec2 {
121        ImVec2::new(v.x, v.y)
122    }
123}
124
125impl ImVec4 {
126    #[inline]
127    pub const fn new(x: f32, y: f32, z: f32, w: f32) -> ImVec4 {
128        ImVec4 { x, y, z, w }
129    }
130
131    #[inline]
132    pub const fn zero() -> ImVec4 {
133        ImVec4 {
134            x: 0.0,
135            y: 0.0,
136            z: 0.0,
137            w: 0.0,
138        }
139    }
140}
141
142impl From<[f32; 4]> for ImVec4 {
143    #[inline]
144    fn from(array: [f32; 4]) -> ImVec4 {
145        ImVec4::new(array[0], array[1], array[2], array[3])
146    }
147}
148
149impl From<(f32, f32, f32, f32)> for ImVec4 {
150    #[inline]
151    fn from((x, y, z, w): (f32, f32, f32, f32)) -> ImVec4 {
152        ImVec4::new(x, y, z, w)
153    }
154}
155
156impl From<ImVec4> for [f32; 4] {
157    #[inline]
158    fn from(v: ImVec4) -> [f32; 4] {
159        [v.x, v.y, v.z, v.w]
160    }
161}
162
163impl From<ImVec4> for (f32, f32, f32, f32) {
164    #[inline]
165    fn from(v: ImVec4) -> (f32, f32, f32, f32) {
166        (v.x, v.y, v.z, v.w)
167    }
168}
169
170impl From<mint::Vector4<f32>> for ImVec4 {
171    #[inline]
172    fn from(v: mint::Vector4<f32>) -> ImVec4 {
173        ImVec4::new(v.x, v.y, v.z, v.w)
174    }
175}