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(unsafe_op_in_unsafe_fn)]
30#![allow(clippy::all)]
31#![allow(unpredictable_function_pointer_comparisons)]
32
33// Re-export ImGui types from dear-imgui-sys to ensure compatibility
34pub use dear_imgui_sys::{
35    ImDrawData, ImDrawList, ImFontAtlas, ImGuiCond, ImGuiContext, ImGuiDragDropFlags, ImGuiIO,
36    ImGuiMouseButton, ImGuiStyle, ImTextureID, ImVec2, ImVec4,
37};
38
39// Include the generated bindings from bindgen
40include!(concat!(env!("OUT_DIR"), "/bindings.rs"));
41
42// TODO: Platform-specific function wrappers for MSVC ABI compatibility
43// #[cfg(target_os = "windows")]
44// pub mod wrapper_functions;
45
46// Convenience type aliases and implementations
47use std::ops::Range;
48
49impl From<Range<f64>> for ImPlotRange {
50    fn from(from: Range<f64>) -> Self {
51        ImPlotRange {
52            Min: from.start,
53            Max: from.end,
54        }
55    }
56}
57
58impl From<[f64; 2]> for ImPlotRange {
59    fn from(from: [f64; 2]) -> Self {
60        ImPlotRange {
61            Min: from[0],
62            Max: from[1],
63        }
64    }
65}
66
67impl From<(f64, f64)> for ImPlotRange {
68    fn from(from: (f64, f64)) -> Self {
69        ImPlotRange {
70            Min: from.0,
71            Max: from.1,
72        }
73    }
74}
75
76impl From<ImVec2> for ImPlotRange {
77    fn from(from: ImVec2) -> Self {
78        ImPlotRange {
79            Min: from.x as f64,
80            Max: from.y as f64,
81        }
82    }
83}
84
85#[cfg(test)]
86mod tests {
87    use super::*;
88
89    #[test]
90    fn test_implot_range_conversions() {
91        let range1: ImPlotRange = (0.0..10.0).into();
92        assert_eq!(range1.Min, 0.0);
93        assert_eq!(range1.Max, 10.0);
94
95        let range2: ImPlotRange = [1.0, 5.0].into();
96        assert_eq!(range2.Min, 1.0);
97        assert_eq!(range2.Max, 5.0);
98
99        let range3: ImPlotRange = (2.0, 8.0).into();
100        assert_eq!(range3.Min, 2.0);
101        assert_eq!(range3.Max, 8.0);
102    }
103}