dear_implot_sys/
lib.rs

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