easy_imgui_sys/
lib.rs

1#![allow(non_upper_case_globals)]
2#![allow(non_camel_case_types)]
3#![allow(non_snake_case)]
4#![allow(dead_code)]
5#![allow(unnecessary_transmutes)]
6#![allow(clippy::all)]
7
8use std::ops::{Deref, DerefMut, Index};
9
10#[cfg(feature = "backend-sdl3")]
11pub use sdl3_sys;
12#[cfg(feature = "backend-sdl3")]
13use sdl3_sys::everything::*;
14
15include!(concat!(env!("OUT_DIR"), "/bindings.rs"));
16
17impl<T> Index<usize> for ImVector<T> {
18    type Output = T;
19
20    fn index(&self, index: usize) -> &Self::Output {
21        if index >= self.Size as usize {
22            panic!("ImVector out of bounds");
23        }
24        unsafe { &*self.Data.add(index) }
25    }
26}
27
28impl<T> Deref for ImVector<T> {
29    type Target = [T];
30    fn deref(&self) -> &[T] {
31        unsafe {
32            if self.Size == 0 {
33                // self.Data may be null, and that will not do for `from_raw_parts`
34                &[]
35            } else {
36                std::slice::from_raw_parts(self.Data, self.Size as usize)
37            }
38        }
39    }
40}
41
42impl<T> DerefMut for ImVector<T> {
43    fn deref_mut(&mut self) -> &mut [T] {
44        unsafe {
45            if self.Size == 0 {
46                // self.Data may be null, and that will not do for `from_raw_parts`
47                &mut []
48            } else {
49                std::slice::from_raw_parts_mut(self.Data, self.Size as usize)
50            }
51        }
52    }
53}
54
55impl<'a, T> IntoIterator for &'a ImVector<T> {
56    type Item = &'a T;
57    type IntoIter = std::slice::Iter<'a, T>;
58    fn into_iter(self) -> Self::IntoIter {
59        self.deref().into_iter()
60    }
61}
62
63impl<'a, T> IntoIterator for &'a mut ImVector<T> {
64    type Item = &'a mut T;
65    type IntoIter = std::slice::IterMut<'a, T>;
66    fn into_iter(self) -> Self::IntoIter {
67        self.deref_mut().into_iter()
68    }
69}
70
71#[cfg(target_env = "msvc")]
72impl From<ImVec2_rr> for ImVec2 {
73    fn from(rr: ImVec2_rr) -> ImVec2 {
74        ImVec2 { x: rr.x, y: rr.y }
75    }
76}