extern crate implot_sys as sys;
#[macro_use]
extern crate lazy_static;
pub use sys::{imgui::Condition, ImPlotLimits, ImPlotPoint, ImPlotRange, ImVec2, ImVec4};
pub use self::context::*;
pub use self::plot::*;
pub use self::plot_elements::*;
mod context;
mod plot;
mod plot_elements;
pub struct PlotUi<'ui> {
context: &'ui Context,
}
#[repr(i32)]
#[derive(Copy, Clone, Debug)]
pub enum Marker {
None = sys::ImPlotMarker__ImPlotMarker_None,
Circle = sys::ImPlotMarker__ImPlotMarker_Circle,
Square = sys::ImPlotMarker__ImPlotMarker_Square,
Diamond = sys::ImPlotMarker__ImPlotMarker_Diamond,
Up = sys::ImPlotMarker__ImPlotMarker_Up,
Down = sys::ImPlotMarker__ImPlotMarker_Down,
Left = sys::ImPlotMarker__ImPlotMarker_Left,
Right = sys::ImPlotMarker__ImPlotMarker_Right,
Cross = sys::ImPlotMarker__ImPlotMarker_Cross,
Plus = sys::ImPlotMarker__ImPlotMarker_Plus,
Asterisk = sys::ImPlotMarker__ImPlotMarker_Asterisk,
}
#[repr(u32)]
#[derive(Copy, Clone, Debug)]
pub enum PlotColorElement {
Line = sys::ImPlotCol__ImPlotCol_Line,
Fill = sys::ImPlotCol__ImPlotCol_Fill,
MarkerOutline = sys::ImPlotCol__ImPlotCol_MarkerOutline,
MarkerFill = sys::ImPlotCol__ImPlotCol_MarkerFill,
ErrorBar = sys::ImPlotCol__ImPlotCol_ErrorBar,
FrameBg = sys::ImPlotCol__ImPlotCol_FrameBg,
PlotBg = sys::ImPlotCol__ImPlotCol_PlotBg,
PlotBorder = sys::ImPlotCol__ImPlotCol_PlotBorder,
LegendBackground = sys::ImPlotCol__ImPlotCol_LegendBg,
LegendBorder = sys::ImPlotCol__ImPlotCol_LegendBorder,
LegendText = sys::ImPlotCol__ImPlotCol_LegendText,
TitleText = sys::ImPlotCol__ImPlotCol_TitleText,
InlayText = sys::ImPlotCol__ImPlotCol_InlayText,
XAxis = sys::ImPlotCol__ImPlotCol_XAxis,
XAxisGrid = sys::ImPlotCol__ImPlotCol_XAxisGrid,
YAxis = sys::ImPlotCol__ImPlotCol_YAxis,
YAxisGrid = sys::ImPlotCol__ImPlotCol_YAxisGrid,
YAxis2 = sys::ImPlotCol__ImPlotCol_YAxis2,
YAxisGrid2 = sys::ImPlotCol__ImPlotCol_YAxisGrid2,
YAxis3 = sys::ImPlotCol__ImPlotCol_YAxis3,
YAxisGrid3 = sys::ImPlotCol__ImPlotCol_YAxisGrid3,
Selection = sys::ImPlotCol__ImPlotCol_Selection,
Crosshairs = sys::ImPlotCol__ImPlotCol_Crosshairs,
Query = sys::ImPlotCol__ImPlotCol_Query,
}
#[repr(u32)]
#[derive(Copy, Clone, Debug)]
pub enum Colormap {
Standard = sys::ImPlotColormap__ImPlotColormap_Default,
Deep = sys::ImPlotColormap__ImPlotColormap_Deep,
Dark = sys::ImPlotColormap__ImPlotColormap_Dark,
Pastel = sys::ImPlotColormap__ImPlotColormap_Pastel,
Paired = sys::ImPlotColormap__ImPlotColormap_Paired,
Viridis = sys::ImPlotColormap__ImPlotColormap_Viridis,
Plasma = sys::ImPlotColormap__ImPlotColormap_Plasma,
Hot = sys::ImPlotColormap__ImPlotColormap_Hot,
Cool = sys::ImPlotColormap__ImPlotColormap_Cool,
Pink = sys::ImPlotColormap__ImPlotColormap_Pink,
Jet = sys::ImPlotColormap__ImPlotColormap_Jet,
}
#[repr(u32)]
#[derive(Copy, Clone, Debug)]
pub enum StyleVar {
LineWeight = sys::ImPlotStyleVar__ImPlotStyleVar_LineWeight,
Marker = sys::ImPlotStyleVar__ImPlotStyleVar_Marker,
MarkerSize = sys::ImPlotStyleVar__ImPlotStyleVar_MarkerSize,
MarkerWeight = sys::ImPlotStyleVar__ImPlotStyleVar_MarkerWeight,
FillAlpha = sys::ImPlotStyleVar__ImPlotStyleVar_FillAlpha,
ErrorBarSize = sys::ImPlotStyleVar__ImPlotStyleVar_ErrorBarSize,
ErrorBarWeight = sys::ImPlotStyleVar__ImPlotStyleVar_ErrorBarWeight,
DigitalBitHeight = sys::ImPlotStyleVar__ImPlotStyleVar_DigitalBitHeight,
DigitalBitGap = sys::ImPlotStyleVar__ImPlotStyleVar_DigitalBitGap,
PlotBorderSize = sys::ImPlotStyleVar__ImPlotStyleVar_PlotBorderSize,
MinorAlpha = sys::ImPlotStyleVar__ImPlotStyleVar_MinorAlpha,
MajorTickLen = sys::ImPlotStyleVar__ImPlotStyleVar_MajorTickLen,
MinorTickLen = sys::ImPlotStyleVar__ImPlotStyleVar_MinorTickLen,
MajorTickSize = sys::ImPlotStyleVar__ImPlotStyleVar_MajorTickSize,
MinorTickSize = sys::ImPlotStyleVar__ImPlotStyleVar_MinorTickSize,
MajorGridSize = sys::ImPlotStyleVar__ImPlotStyleVar_MajorGridSize,
MinorGridSize = sys::ImPlotStyleVar__ImPlotStyleVar_MinorGridSize,
PlotPadding = sys::ImPlotStyleVar__ImPlotStyleVar_PlotPadding,
LabelPadding = sys::ImPlotStyleVar__ImPlotStyleVar_LabelPadding,
LegendPadding = sys::ImPlotStyleVar__ImPlotStyleVar_LegendPadding,
InfoPadding = sys::ImPlotStyleVar__ImPlotStyleVar_InfoPadding,
PlotMinSize = sys::ImPlotStyleVar__ImPlotStyleVar_PlotMinSize,
}
pub fn set_colormap_from_preset(preset: Colormap, samples: u32) {
unsafe {
sys::ImPlot_SetColormapPlotColormap(preset as i32, samples as i32);
}
}
pub fn set_colormap_from_vec(colors: Vec<ImVec4>) {
unsafe {
sys::ImPlot_SetColormapVec4Ptr(colors.as_ptr(), colors.len() as i32);
}
}
pub fn push_style_color(
element: &PlotColorElement,
red: f32,
green: f32,
blue: f32,
alpha: f32,
) -> StyleColorToken {
unsafe {
sys::ImPlot_PushStyleColorVec4(
*element as sys::ImPlotCol,
sys::ImVec4 {
x: red,
y: green,
z: blue,
w: alpha,
},
);
}
StyleColorToken { was_popped: false }
}
pub struct StyleColorToken {
was_popped: bool,
}
impl StyleColorToken {
pub fn pop(mut self) {
if self.was_popped {
panic!("Attempted to pop a style color token twice.")
}
self.was_popped = true;
unsafe {
sys::ImPlot_PopStyleColor(1);
}
}
}
pub fn push_style_var_f32(element: &StyleVar, value: f32) -> StyleVarToken {
unsafe {
sys::ImPlot_PushStyleVarFloat(*element as sys::ImPlotStyleVar, value);
}
StyleVarToken { was_popped: false }
}
pub fn push_style_var_i32(element: &StyleVar, value: i32) -> StyleVarToken {
unsafe {
sys::ImPlot_PushStyleVarInt(*element as sys::ImPlotStyleVar, value);
}
StyleVarToken { was_popped: false }
}
pub fn push_style_var_imvec2(element: &StyleVar, value: ImVec2) -> StyleVarToken {
unsafe {
sys::ImPlot_PushStyleVarVec2(*element as sys::ImPlotStyleVar, value);
}
StyleVarToken { was_popped: false }
}
pub struct StyleVarToken {
was_popped: bool,
}
impl StyleVarToken {
pub fn pop(mut self) {
if self.was_popped {
panic!("Attempted to pop a style var token twice.")
}
self.was_popped = true;
unsafe {
sys::ImPlot_PopStyleVar(1);
}
}
}
pub fn is_plot_hovered() -> bool {
unsafe { sys::ImPlot_IsPlotHovered() }
}
pub fn is_plot_queried() -> bool {
unsafe { sys::ImPlot_IsPlotQueried() }
}
pub fn get_plot_mouse_position() -> ImPlotPoint {
let y_axis_selection = 0;
let mut point = ImPlotPoint { x: 0.0, y: 0.0 }; unsafe {
sys::ImPlot_GetPlotMousePos(&mut point as *mut ImPlotPoint, y_axis_selection);
}
point
}
pub fn get_plot_limits() -> ImPlotLimits {
let y_axis_selection = 0;
let mut limits = ImPlotLimits {
X: ImPlotRange { Min: 0.0, Max: 0.0 },
Y: ImPlotRange { Min: 0.0, Max: 0.0 },
};
unsafe {
sys::ImPlot_GetPlotLimits(&mut limits as *mut ImPlotLimits, y_axis_selection);
}
limits
}
pub fn get_plot_query() -> ImPlotLimits {
let y_axis_selection = 0;
let mut limits = ImPlotLimits {
X: ImPlotRange { Min: 0.0, Max: 0.0 },
Y: ImPlotRange { Min: 0.0, Max: 0.0 },
};
unsafe {
sys::ImPlot_GetPlotQuery(&mut limits as *mut ImPlotLimits, y_axis_selection);
}
limits
}
pub fn show_demo_window(show: &mut bool) {
unsafe {
implot_sys::ImPlot_ShowDemoWindow(show);
}
}