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// 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
125#[cfg(feature = "glam")]
126impl From<glam::Vec2> for ImVec2 {
127    #[inline]
128    fn from(v: glam::Vec2) -> ImVec2 {
129        ImVec2::new(v.x, v.y)
130    }
131}
132
133impl ImVec4 {
134    #[inline]
135    pub const fn new(x: f32, y: f32, z: f32, w: f32) -> ImVec4 {
136        ImVec4 { x, y, z, w }
137    }
138
139    #[inline]
140    pub const fn zero() -> ImVec4 {
141        ImVec4 {
142            x: 0.0,
143            y: 0.0,
144            z: 0.0,
145            w: 0.0,
146        }
147    }
148}
149
150impl From<[f32; 4]> for ImVec4 {
151    #[inline]
152    fn from(array: [f32; 4]) -> ImVec4 {
153        ImVec4::new(array[0], array[1], array[2], array[3])
154    }
155}
156
157impl From<(f32, f32, f32, f32)> for ImVec4 {
158    #[inline]
159    fn from((x, y, z, w): (f32, f32, f32, f32)) -> ImVec4 {
160        ImVec4::new(x, y, z, w)
161    }
162}
163
164impl From<ImVec4> for [f32; 4] {
165    #[inline]
166    fn from(v: ImVec4) -> [f32; 4] {
167        [v.x, v.y, v.z, v.w]
168    }
169}
170
171impl From<ImVec4> for (f32, f32, f32, f32) {
172    #[inline]
173    fn from(v: ImVec4) -> (f32, f32, f32, f32) {
174        (v.x, v.y, v.z, v.w)
175    }
176}
177
178impl From<mint::Vector4<f32>> for ImVec4 {
179    #[inline]
180    fn from(v: mint::Vector4<f32>) -> ImVec4 {
181        ImVec4::new(v.x, v.y, v.z, v.w)
182    }
183}
184
185#[cfg(feature = "glam")]
186impl From<glam::Vec4> for ImVec4 {
187    #[inline]
188    fn from(v: glam::Vec4) -> ImVec4 {
189        ImVec4::new(v.x, v.y, v.z, v.w)
190    }
191}