1#![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
36use std::ops::{Deref, DerefMut, Index, IndexMut};
37
38include!(concat!(env!("OUT_DIR"), "/bindings.rs"));
40
41pub mod wrapper_functions;
43
44impl<T> Index<usize> for ImVector<T> {
46 type Output = T;
47
48 fn index(&self, index: usize) -> &Self::Output {
49 if index >= self.Size as usize {
50 panic!(
51 "ImVector index {} out of bounds (size: {})",
52 index, self.Size
53 );
54 }
55 unsafe { &*self.Data.add(index) }
56 }
57}
58
59impl<T> IndexMut<usize> for ImVector<T> {
61 fn index_mut(&mut self, index: usize) -> &mut Self::Output {
62 if index >= self.Size as usize {
63 panic!(
64 "ImVector index {} out of bounds (size: {})",
65 index, self.Size
66 );
67 }
68 unsafe { &mut *self.Data.add(index) }
69 }
70}
71
72impl<T> Deref for ImVector<T> {
74 type Target = [T];
75
76 fn deref(&self) -> &[T] {
77 unsafe {
78 if self.Size == 0 || self.Data.is_null() {
79 &[]
81 } else {
82 std::slice::from_raw_parts(self.Data, self.Size as usize)
83 }
84 }
85 }
86}
87
88impl<T> DerefMut for ImVector<T> {
90 fn deref_mut(&mut self) -> &mut [T] {
91 unsafe {
92 if self.Size == 0 || self.Data.is_null() {
93 &mut []
95 } else {
96 std::slice::from_raw_parts_mut(self.Data, self.Size as usize)
97 }
98 }
99 }
100}
101
102impl<'a, T> IntoIterator for &'a ImVector<T> {
104 type Item = &'a T;
105 type IntoIter = std::slice::Iter<'a, T>;
106
107 fn into_iter(self) -> Self::IntoIter {
108 self.deref().iter()
109 }
110}
111
112impl<'a, T> IntoIterator for &'a mut ImVector<T> {
114 type Item = &'a mut T;
115 type IntoIter = std::slice::IterMut<'a, T>;
116
117 fn into_iter(self) -> Self::IntoIter {
118 self.deref_mut().iter_mut()
119 }
120}
121
122#[cfg(target_env = "msvc")]
124impl From<ImVec2_Pod> for ImVec2 {
125 #[inline]
126 fn from(pod: ImVec2_Pod) -> ImVec2 {
127 ImVec2 { x: pod.x, y: pod.y }
128 }
129}
130
131#[cfg(target_env = "msvc")]
132impl From<ImVec2> for ImVec2_Pod {
133 #[inline]
134 fn from(v: ImVec2) -> ImVec2_Pod {
135 ImVec2_Pod { x: v.x, y: v.y }
136 }
137}
138
139pub use ImColor as Color;
141pub use ImVec2 as Vector2;
142pub use ImVec4 as Vector4;
143
144pub const IMGUI_VERSION: &str = env!("CARGO_PKG_VERSION");
146
147#[cfg(feature = "docking")]
149pub const HAS_DOCKING: bool = true;
150
151#[cfg(not(feature = "docking"))]
152pub const HAS_DOCKING: bool = false;
153
154#[cfg(feature = "freetype")]
156pub const HAS_FREETYPE: bool = true;
157
158#[cfg(not(feature = "freetype"))]
159pub const HAS_FREETYPE: bool = false;
160
161#[cfg(feature = "wasm")]
163pub const HAS_WASM: bool = true;
164
165#[cfg(not(feature = "wasm"))]
166pub const HAS_WASM: bool = false;
167
168impl ImVec2 {
169 #[inline]
170 pub const fn new(x: f32, y: f32) -> ImVec2 {
171 ImVec2 { x, y }
172 }
173
174 #[inline]
175 pub const fn zero() -> ImVec2 {
176 ImVec2 { x: 0.0, y: 0.0 }
177 }
178}
179
180impl From<[f32; 2]> for ImVec2 {
181 #[inline]
182 fn from(array: [f32; 2]) -> ImVec2 {
183 ImVec2::new(array[0], array[1])
184 }
185}
186
187impl From<(f32, f32)> for ImVec2 {
188 #[inline]
189 fn from((x, y): (f32, f32)) -> ImVec2 {
190 ImVec2::new(x, y)
191 }
192}
193
194impl From<ImVec2> for [f32; 2] {
195 #[inline]
196 fn from(v: ImVec2) -> [f32; 2] {
197 [v.x, v.y]
198 }
199}
200
201impl From<ImVec2> for (f32, f32) {
202 #[inline]
203 fn from(v: ImVec2) -> (f32, f32) {
204 (v.x, v.y)
205 }
206}
207
208impl From<mint::Vector2<f32>> for ImVec2 {
209 #[inline]
210 fn from(v: mint::Vector2<f32>) -> ImVec2 {
211 ImVec2::new(v.x, v.y)
212 }
213}
214
215impl ImVec4 {
216 #[inline]
217 pub const fn new(x: f32, y: f32, z: f32, w: f32) -> ImVec4 {
218 ImVec4 { x, y, z, w }
219 }
220
221 #[inline]
222 pub const fn zero() -> ImVec4 {
223 ImVec4 {
224 x: 0.0,
225 y: 0.0,
226 z: 0.0,
227 w: 0.0,
228 }
229 }
230}
231
232impl From<[f32; 4]> for ImVec4 {
233 #[inline]
234 fn from(array: [f32; 4]) -> ImVec4 {
235 ImVec4::new(array[0], array[1], array[2], array[3])
236 }
237}
238
239impl From<(f32, f32, f32, f32)> for ImVec4 {
240 #[inline]
241 fn from((x, y, z, w): (f32, f32, f32, f32)) -> ImVec4 {
242 ImVec4::new(x, y, z, w)
243 }
244}
245
246impl From<ImVec4> for [f32; 4] {
247 #[inline]
248 fn from(v: ImVec4) -> [f32; 4] {
249 [v.x, v.y, v.z, v.w]
250 }
251}
252
253impl From<ImVec4> for (f32, f32, f32, f32) {
254 #[inline]
255 fn from(v: ImVec4) -> (f32, f32, f32, f32) {
256 (v.x, v.y, v.z, v.w)
257 }
258}
259
260impl From<mint::Vector4<f32>> for ImVec4 {
261 #[inline]
262 fn from(v: mint::Vector4<f32>) -> ImVec4 {
263 ImVec4::new(v.x, v.y, v.z, v.w)
264 }
265}