dear_implot_sys/
lib.rs

1//! Low-level FFI bindings for ImPlot with Dear ImGui C++ compatibility
2//!
3//! This crate provides raw, unsafe bindings to the ImPlot C++ library,
4//! designed to work with dear-imgui-sys (C++ bindgen) rather than imgui-sys (cimgui).
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//! ## Safety
13//!
14//! This crate provides raw FFI bindings and is inherently unsafe. Users should
15//! prefer the high-level `dear-implot` crate for safe Rust bindings.
16//!
17//! ## Usage
18//!
19//! This crate is typically not used directly. Instead, use the `dear-implot` crate
20//! which provides safe, idiomatic Rust bindings built on top of these FFI bindings.
21
22#![allow(non_upper_case_globals)]
23#![allow(non_camel_case_types)]
24#![allow(non_snake_case)]
25#![allow(dead_code)]
26#![allow(unnecessary_transmutes)]
27#![allow(clippy::all)]
28
29// Re-export ImGui types from dear-imgui-sys to ensure compatibility
30pub use dear_imgui_sys::{
31    ImDrawData, ImDrawList, ImFontAtlas, ImGuiCond, ImGuiContext, ImGuiDragDropFlags, ImGuiIO,
32    ImGuiMouseButton, ImGuiStyle, ImTextureID, ImVec2, ImVec4,
33};
34
35// Include the generated bindings from bindgen
36include!(concat!(env!("OUT_DIR"), "/bindings.rs"));
37
38// TODO: Platform-specific function wrappers for MSVC ABI compatibility
39// #[cfg(target_os = "windows")]
40// pub mod wrapper_functions;
41
42// Convenience type aliases and implementations
43use std::ops::Range;
44
45impl From<Range<f64>> for ImPlotRange {
46    fn from(from: Range<f64>) -> Self {
47        ImPlotRange {
48            Min: from.start,
49            Max: from.end,
50        }
51    }
52}
53
54impl From<[f64; 2]> for ImPlotRange {
55    fn from(from: [f64; 2]) -> Self {
56        ImPlotRange {
57            Min: from[0],
58            Max: from[1],
59        }
60    }
61}
62
63impl From<(f64, f64)> for ImPlotRange {
64    fn from(from: (f64, f64)) -> Self {
65        ImPlotRange {
66            Min: from.0,
67            Max: from.1,
68        }
69    }
70}
71
72impl From<ImVec2> for ImPlotRange {
73    fn from(from: ImVec2) -> Self {
74        ImPlotRange {
75            Min: from.x as f64,
76            Max: from.y as f64,
77        }
78    }
79}
80
81#[cfg(test)]
82mod tests {
83    use super::*;
84
85    #[test]
86    fn test_implot_range_conversions() {
87        let range1: ImPlotRange = (0.0..10.0).into();
88        assert_eq!(range1.Min, 0.0);
89        assert_eq!(range1.Max, 10.0);
90
91        let range2: ImPlotRange = [1.0, 5.0].into();
92        assert_eq!(range2.Min, 1.0);
93        assert_eq!(range2.Max, 5.0);
94
95        let range3: ImPlotRange = (2.0, 8.0).into();
96        assert_eq!(range3.Min, 2.0);
97        assert_eq!(range3.Max, 8.0);
98    }
99}