From f85c50657bdc096394f14f8a9dc533f8e3add9b7 Mon Sep 17 00:00:00 2001 From: 4bb4 <67376761+4bb4@users.noreply.github.com> Date: Sun, 4 Oct 2020 14:43:18 +0200 Subject: [PATCH] Initial work on move to implot 0.7 compatibility. See notes. - This updates the bindings generator, the low-level bindings as well as the higher-level bindings and the examples to work with a newer master of cimplot that links to implot 0.7. - Several things are not done properly yet: - Contexts can be created and as long as they are not dropped things work out (shown in the examples). However, this should be done more imgui-rs like, where operations that require a context make that explicit by requiring a context reference to be passed. - The README has not been updated yet to all the new features that were added. --- implot-examples/examples/bar_plots.rs | 3 +- implot-examples/examples/line_plots.rs | 19 +- implot-examples/examples/scatter_plots.rs | 11 +- implot-examples/examples/text_plots.rs | 3 +- implot-sys/build.rs | 10 +- implot-sys/src/bindings.rs | 903 ++++++++++++++++++---- implot-sys/third-party/cimplot | 2 +- src/lib.rs | 281 ++++--- 8 files changed, 988 insertions(+), 244 deletions(-) diff --git a/implot-examples/examples/bar_plots.rs b/implot-examples/examples/bar_plots.rs index 719cbd3..10c4147 100644 --- a/implot-examples/examples/bar_plots.rs +++ b/implot-examples/examples/bar_plots.rs @@ -2,7 +2,7 @@ //! features of the libray, see the line_plots example. use imgui::{im_str, CollapsingHeader, Condition, Ui, Window}; -use implot::{Plot, PlotBars}; +use implot::{Context, Plot, PlotBars}; mod support; @@ -44,6 +44,7 @@ fn show_basic_horizontal_plot(ui: &Ui) { fn main() { let system = support::init(file!()); let mut showing_demo = false; + let _plotcontext = Context::create(); // TODO(4bb4) use this as soon as things have been adapted system.main_loop(move |_, ui| { Window::new(im_str!("Bar plots example")) .size([430.0, 450.0], Condition::FirstUseEver) diff --git a/implot-examples/examples/line_plots.rs b/implot-examples/examples/line_plots.rs index ce4808b..b13a9f8 100644 --- a/implot-examples/examples/line_plots.rs +++ b/implot-examples/examples/line_plots.rs @@ -4,9 +4,9 @@ use imgui::{im_str, CollapsingHeader, Condition, Ui, Window}; use implot::{ get_plot_limits, get_plot_mouse_position, get_plot_query, is_plot_hovered, is_plot_queried, - push_style_color, push_style_var_f32, push_style_var_u32, set_colormap_from_preset, - set_colormap_from_vec, AxisFlags, Colormap, ImPlotLimits, ImPlotPoint, ImPlotRange, ImVec4, - Marker, Plot, PlotColorElement, PlotFlags, PlotLine, StyleVar, + push_style_color, push_style_var_f32, push_style_var_i32, set_colormap_from_preset, + set_colormap_from_vec, AxisFlags, Colormap, Context, ImPlotLimits, ImPlotPoint, ImPlotRange, + ImVec4, Marker, Plot, PlotColorElement, PlotFlags, PlotLine, StyleVar, }; mod support; @@ -46,11 +46,11 @@ fn show_configurable_plot(ui: &Ui) { let y_min = 1.0; let y_max = 2.0; // - Plot flags, see the PlotFlags docs for more info - let plot_flags = PlotFlags::DEFAULT; + let plot_flags = PlotFlags::NONE; // - Axis flags, see the AxisFlags docs for more info. All flags are bitflags-created, // so they support a bunch of convenient operations, see https://docs.rs/bitflags - let x_axis_flags = AxisFlags::DEFAULT; - let y_axis_flags = AxisFlags::DEFAULT; + let x_axis_flags = AxisFlags::NONE; + let y_axis_flags = AxisFlags::NONE; // - Unlabelled X axis ticks let x_ticks = vec![2.2, 2.5, 2.8]; @@ -154,12 +154,12 @@ fn show_style_plot(ui: &Ui) { }, Condition::Always, ) - .with_plot_flags(&(PlotFlags::DEFAULT)) - .with_y_axis_flags(&(AxisFlags::DEFAULT)) + .with_plot_flags(&(PlotFlags::NONE)) + .with_y_axis_flags(&(AxisFlags::NONE)) .build(|| { // Markers can be selected as shown here. The markers are internally represented // as an u32, hence this calling style. - let markerchoice = push_style_var_u32(&StyleVar::Marker, Marker::CROSS.bits()); + let markerchoice = push_style_var_i32(&StyleVar::Marker, Marker::Cross as i32); PlotLine::new("Left eye").plot(&vec![2.0, 2.0], &vec![2.0, 1.0]); // Calling pop() on the return value of the push above will undo the marker choice. markerchoice.pop(); @@ -232,6 +232,7 @@ fn show_colormaps_plot(ui: &Ui) { fn main() { let system = support::init(file!()); let mut showing_demo = false; + let _plotcontext = Context::create(); // TODO(4bb4) use this as soon as things have been adapted system.main_loop(move |_, ui| { Window::new(im_str!("Line plots example")) .size([430.0, 450.0], Condition::FirstUseEver) diff --git a/implot-examples/examples/scatter_plots.rs b/implot-examples/examples/scatter_plots.rs index db0c9fe..0d7f2ec 100644 --- a/implot-examples/examples/scatter_plots.rs +++ b/implot-examples/examples/scatter_plots.rs @@ -2,7 +2,9 @@ //! features of the libray, see the line_plots example. use imgui::{im_str, CollapsingHeader, Condition, Ui, Window}; -use implot::{push_style_var_f32, push_style_var_u32, Marker, Plot, PlotScatter, StyleVar}; +use implot::{ + push_style_var_f32, push_style_var_i32, Context, Marker, Plot, PlotScatter, StyleVar, +}; mod support; @@ -28,7 +30,7 @@ fn show_custom_markers_plot(ui: &Ui) { "This header shows how markers can be used in scatter plots." )); let content_width = ui.window_content_region_width(); - Plot::new("Simple scatter plot") + Plot::new("Multi-marker scatter plot") // The size call could also be omitted, though the defaults don't consider window // width, which is why we're not doing so here. .size(content_width, 300.0) @@ -36,14 +38,14 @@ fn show_custom_markers_plot(ui: &Ui) { // Change to cross marker for one scatter plot call let x_positions = vec![0.1, 0.2, 0.1, 0.5, 0.9]; let y_positions = vec![0.1, 0.1, 0.3, 0.3, 0.9]; - let markerchoice = push_style_var_u32(&StyleVar::Marker, Marker::CROSS.bits()); + let markerchoice = push_style_var_i32(&StyleVar::Marker, Marker::Cross as i32); PlotScatter::new("legend label 1").plot(&x_positions, &y_positions); markerchoice.pop(); // One can combine things like marker size and markor choice let x_positions = vec![0.4, 0.1]; let y_positions = vec![0.5, 0.3]; - let marker_choice = push_style_var_u32(&StyleVar::Marker, Marker::DIAMOND.bits()); + let marker_choice = push_style_var_i32(&StyleVar::Marker, Marker::Diamond as i32); let marker_size = push_style_var_f32(&StyleVar::MarkerSize, 12.0); PlotScatter::new("legend label 2").plot(&x_positions, &y_positions); @@ -57,6 +59,7 @@ fn show_custom_markers_plot(ui: &Ui) { fn main() { let system = support::init(file!()); let mut showing_demo = false; + let _plotcontext = Context::create(); // TODO(4bb4) use this as soon as things have been adapted system.main_loop(move |_, ui| { Window::new(im_str!("Scatter plots example")) .size([430.0, 450.0], Condition::FirstUseEver) diff --git a/implot-examples/examples/text_plots.rs b/implot-examples/examples/text_plots.rs index cf74565..41e9a19 100644 --- a/implot-examples/examples/text_plots.rs +++ b/implot-examples/examples/text_plots.rs @@ -2,7 +2,7 @@ //! features of the libray, see the line_plots example. use imgui::{im_str, CollapsingHeader, Condition, Ui, Window}; -use implot::{Plot, PlotText}; +use implot::{Context, Plot, PlotText}; mod support; @@ -33,6 +33,7 @@ fn show_basic_plot(ui: &Ui) { fn main() { let system = support::init(file!()); let mut showing_demo = false; + let _plotcontext = Context::create(); // TODO(4bb4) use this as soon as things have been adapted system.main_loop(move |_, ui| { Window::new(im_str!("Text plots example")) .size([430.0, 450.0], Condition::FirstUseEver) diff --git a/implot-sys/build.rs b/implot-sys/build.rs index 5fb680a..0e8a4cf 100644 --- a/implot-sys/build.rs +++ b/implot-sys/build.rs @@ -5,12 +5,15 @@ // for now, but expected to diverge from that over time. use std::{env, fs, io, path::Path}; -const CPP_FILES: [&str; 3] = [ +const CPP_FILES: &[&str] = &[ "third-party/cimplot/cimplot.cpp", "third-party/cimplot/implot/implot.cpp", + "third-party/cimplot/implot/implot_items.cpp", "third-party/cimplot/implot/implot_demo.cpp", // Could remove this if demo not used ]; +const IMPLOT_INCLUDE_DIRECTORIES: &[&str] = &["third-party/cimplot/implot/"]; + fn assert_file_exists(path: &str) -> io::Result<()> { match fs::metadata(path) { Ok(_) => Ok(()), @@ -46,10 +49,13 @@ fn main() -> io::Result<()> { let imgui_include_path = Path::new(&cimgui_include_path).join("imgui"); build.include(&cimgui_include_path); build.include(&imgui_include_path); + for path in IMPLOT_INCLUDE_DIRECTORIES { + build.include(path); + } // Taken from the imgui-sys build as well build.flag_if_supported("-Wno-return-type-c-linkage"); - for path in &CPP_FILES { + for path in CPP_FILES { assert_file_exists(path)?; build.file(path); } diff --git a/implot-sys/src/bindings.rs b/implot-sys/src/bindings.rs index d660b9b..59e5085 100644 --- a/implot-sys/src/bindings.rs +++ b/implot-sys/src/bindings.rs @@ -8981,37 +8981,42 @@ extern "C" { extern "C" { pub fn ImVector_ImWchar_UnInit(p: *mut ImVector_ImWchar); } +#[repr(C)] +#[derive(Debug, Copy, Clone)] +pub struct ImPlotContext { + _unused: [u8; 0], +} pub type ImPlotFlags = ::std::os::raw::c_int; pub type ImPlotAxisFlags = ::std::os::raw::c_int; pub type ImPlotCol = ::std::os::raw::c_int; pub type ImPlotStyleVar = ::std::os::raw::c_int; pub type ImPlotMarker = ::std::os::raw::c_int; pub type ImPlotColormap = ::std::os::raw::c_int; -pub const ImPlotFlags__ImPlotFlags_MousePos: ImPlotFlags_ = 1; -pub const ImPlotFlags__ImPlotFlags_Legend: ImPlotFlags_ = 2; -pub const ImPlotFlags__ImPlotFlags_Highlight: ImPlotFlags_ = 4; -pub const ImPlotFlags__ImPlotFlags_BoxSelect: ImPlotFlags_ = 8; -pub const ImPlotFlags__ImPlotFlags_Query: ImPlotFlags_ = 16; -pub const ImPlotFlags__ImPlotFlags_ContextMenu: ImPlotFlags_ = 32; -pub const ImPlotFlags__ImPlotFlags_Crosshairs: ImPlotFlags_ = 64; -pub const ImPlotFlags__ImPlotFlags_CullData: ImPlotFlags_ = 128; -pub const ImPlotFlags__ImPlotFlags_AntiAliased: ImPlotFlags_ = 256; -pub const ImPlotFlags__ImPlotFlags_NoChild: ImPlotFlags_ = 512; -pub const ImPlotFlags__ImPlotFlags_YAxis2: ImPlotFlags_ = 1024; -pub const ImPlotFlags__ImPlotFlags_YAxis3: ImPlotFlags_ = 2048; -pub const ImPlotFlags__ImPlotFlags_Default: ImPlotFlags_ = 175; +pub const ImPlotFlags__ImPlotFlags_None: ImPlotFlags_ = 0; +pub const ImPlotFlags__ImPlotFlags_NoLegend: ImPlotFlags_ = 1; +pub const ImPlotFlags__ImPlotFlags_NoMenus: ImPlotFlags_ = 2; +pub const ImPlotFlags__ImPlotFlags_NoBoxSelect: ImPlotFlags_ = 4; +pub const ImPlotFlags__ImPlotFlags_NoMousePos: ImPlotFlags_ = 8; +pub const ImPlotFlags__ImPlotFlags_NoHighlight: ImPlotFlags_ = 16; +pub const ImPlotFlags__ImPlotFlags_NoChild: ImPlotFlags_ = 32; +pub const ImPlotFlags__ImPlotFlags_YAxis2: ImPlotFlags_ = 64; +pub const ImPlotFlags__ImPlotFlags_YAxis3: ImPlotFlags_ = 128; +pub const ImPlotFlags__ImPlotFlags_Query: ImPlotFlags_ = 256; +pub const ImPlotFlags__ImPlotFlags_Crosshairs: ImPlotFlags_ = 512; +pub const ImPlotFlags__ImPlotFlags_AntiAliased: ImPlotFlags_ = 1024; +pub const ImPlotFlags__ImPlotFlags_CanvasOnly: ImPlotFlags_ = 15; pub type ImPlotFlags_ = u32; -pub const ImPlotAxisFlags__ImPlotAxisFlags_GridLines: ImPlotAxisFlags_ = 1; -pub const ImPlotAxisFlags__ImPlotAxisFlags_TickMarks: ImPlotAxisFlags_ = 2; -pub const ImPlotAxisFlags__ImPlotAxisFlags_TickLabels: ImPlotAxisFlags_ = 4; -pub const ImPlotAxisFlags__ImPlotAxisFlags_Invert: ImPlotAxisFlags_ = 8; -pub const ImPlotAxisFlags__ImPlotAxisFlags_LockMin: ImPlotAxisFlags_ = 16; -pub const ImPlotAxisFlags__ImPlotAxisFlags_LockMax: ImPlotAxisFlags_ = 32; -pub const ImPlotAxisFlags__ImPlotAxisFlags_Adaptive: ImPlotAxisFlags_ = 64; -pub const ImPlotAxisFlags__ImPlotAxisFlags_LogScale: ImPlotAxisFlags_ = 128; -pub const ImPlotAxisFlags__ImPlotAxisFlags_Scientific: ImPlotAxisFlags_ = 256; -pub const ImPlotAxisFlags__ImPlotAxisFlags_Default: ImPlotAxisFlags_ = 71; -pub const ImPlotAxisFlags__ImPlotAxisFlags_Auxiliary: ImPlotAxisFlags_ = 70; +pub const ImPlotAxisFlags__ImPlotAxisFlags_None: ImPlotAxisFlags_ = 0; +pub const ImPlotAxisFlags__ImPlotAxisFlags_NoGridLines: ImPlotAxisFlags_ = 1; +pub const ImPlotAxisFlags__ImPlotAxisFlags_NoTickMarks: ImPlotAxisFlags_ = 2; +pub const ImPlotAxisFlags__ImPlotAxisFlags_NoTickLabels: ImPlotAxisFlags_ = 4; +pub const ImPlotAxisFlags__ImPlotAxisFlags_LogScale: ImPlotAxisFlags_ = 8; +pub const ImPlotAxisFlags__ImPlotAxisFlags_Time: ImPlotAxisFlags_ = 16; +pub const ImPlotAxisFlags__ImPlotAxisFlags_Invert: ImPlotAxisFlags_ = 32; +pub const ImPlotAxisFlags__ImPlotAxisFlags_LockMin: ImPlotAxisFlags_ = 64; +pub const ImPlotAxisFlags__ImPlotAxisFlags_LockMax: ImPlotAxisFlags_ = 128; +pub const ImPlotAxisFlags__ImPlotAxisFlags_Lock: ImPlotAxisFlags_ = 192; +pub const ImPlotAxisFlags__ImPlotAxisFlags_NoDecorations: ImPlotAxisFlags_ = 7; pub type ImPlotAxisFlags_ = u32; pub const ImPlotCol__ImPlotCol_Line: ImPlotCol_ = 0; pub const ImPlotCol__ImPlotCol_Fill: ImPlotCol_ = 1; @@ -9021,47 +9026,73 @@ pub const ImPlotCol__ImPlotCol_ErrorBar: ImPlotCol_ = 4; pub const ImPlotCol__ImPlotCol_FrameBg: ImPlotCol_ = 5; pub const ImPlotCol__ImPlotCol_PlotBg: ImPlotCol_ = 6; pub const ImPlotCol__ImPlotCol_PlotBorder: ImPlotCol_ = 7; -pub const ImPlotCol__ImPlotCol_XAxis: ImPlotCol_ = 8; -pub const ImPlotCol__ImPlotCol_YAxis: ImPlotCol_ = 9; -pub const ImPlotCol__ImPlotCol_YAxis2: ImPlotCol_ = 10; -pub const ImPlotCol__ImPlotCol_YAxis3: ImPlotCol_ = 11; -pub const ImPlotCol__ImPlotCol_Selection: ImPlotCol_ = 12; -pub const ImPlotCol__ImPlotCol_Query: ImPlotCol_ = 13; -pub const ImPlotCol__ImPlotCol_COUNT: ImPlotCol_ = 14; +pub const ImPlotCol__ImPlotCol_LegendBg: ImPlotCol_ = 8; +pub const ImPlotCol__ImPlotCol_LegendBorder: ImPlotCol_ = 9; +pub const ImPlotCol__ImPlotCol_LegendText: ImPlotCol_ = 10; +pub const ImPlotCol__ImPlotCol_TitleText: ImPlotCol_ = 11; +pub const ImPlotCol__ImPlotCol_InlayText: ImPlotCol_ = 12; +pub const ImPlotCol__ImPlotCol_XAxis: ImPlotCol_ = 13; +pub const ImPlotCol__ImPlotCol_XAxisGrid: ImPlotCol_ = 14; +pub const ImPlotCol__ImPlotCol_YAxis: ImPlotCol_ = 15; +pub const ImPlotCol__ImPlotCol_YAxisGrid: ImPlotCol_ = 16; +pub const ImPlotCol__ImPlotCol_YAxis2: ImPlotCol_ = 17; +pub const ImPlotCol__ImPlotCol_YAxisGrid2: ImPlotCol_ = 18; +pub const ImPlotCol__ImPlotCol_YAxis3: ImPlotCol_ = 19; +pub const ImPlotCol__ImPlotCol_YAxisGrid3: ImPlotCol_ = 20; +pub const ImPlotCol__ImPlotCol_Selection: ImPlotCol_ = 21; +pub const ImPlotCol__ImPlotCol_Query: ImPlotCol_ = 22; +pub const ImPlotCol__ImPlotCol_Crosshairs: ImPlotCol_ = 23; +pub const ImPlotCol__ImPlotCol_COUNT: ImPlotCol_ = 24; pub type ImPlotCol_ = u32; pub const ImPlotStyleVar__ImPlotStyleVar_LineWeight: ImPlotStyleVar_ = 0; pub const ImPlotStyleVar__ImPlotStyleVar_Marker: ImPlotStyleVar_ = 1; pub const ImPlotStyleVar__ImPlotStyleVar_MarkerSize: ImPlotStyleVar_ = 2; pub const ImPlotStyleVar__ImPlotStyleVar_MarkerWeight: ImPlotStyleVar_ = 3; -pub const ImPlotStyleVar__ImPlotStyleVar_ErrorBarSize: ImPlotStyleVar_ = 4; -pub const ImPlotStyleVar__ImPlotStyleVar_ErrorBarWeight: ImPlotStyleVar_ = 5; -pub const ImPlotStyleVar__ImPlotStyleVar_DigitalBitHeight: ImPlotStyleVar_ = 6; -pub const ImPlotStyleVar__ImPlotStyleVar_DigitalBitGap: ImPlotStyleVar_ = 7; -pub const ImPlotStyleVar__ImPlotStyleVar_COUNT: ImPlotStyleVar_ = 8; +pub const ImPlotStyleVar__ImPlotStyleVar_FillAlpha: ImPlotStyleVar_ = 4; +pub const ImPlotStyleVar__ImPlotStyleVar_ErrorBarSize: ImPlotStyleVar_ = 5; +pub const ImPlotStyleVar__ImPlotStyleVar_ErrorBarWeight: ImPlotStyleVar_ = 6; +pub const ImPlotStyleVar__ImPlotStyleVar_DigitalBitHeight: ImPlotStyleVar_ = 7; +pub const ImPlotStyleVar__ImPlotStyleVar_DigitalBitGap: ImPlotStyleVar_ = 8; +pub const ImPlotStyleVar__ImPlotStyleVar_PlotBorderSize: ImPlotStyleVar_ = 9; +pub const ImPlotStyleVar__ImPlotStyleVar_MinorAlpha: ImPlotStyleVar_ = 10; +pub const ImPlotStyleVar__ImPlotStyleVar_MajorTickLen: ImPlotStyleVar_ = 11; +pub const ImPlotStyleVar__ImPlotStyleVar_MinorTickLen: ImPlotStyleVar_ = 12; +pub const ImPlotStyleVar__ImPlotStyleVar_MajorTickSize: ImPlotStyleVar_ = 13; +pub const ImPlotStyleVar__ImPlotStyleVar_MinorTickSize: ImPlotStyleVar_ = 14; +pub const ImPlotStyleVar__ImPlotStyleVar_MajorGridSize: ImPlotStyleVar_ = 15; +pub const ImPlotStyleVar__ImPlotStyleVar_MinorGridSize: ImPlotStyleVar_ = 16; +pub const ImPlotStyleVar__ImPlotStyleVar_PlotPadding: ImPlotStyleVar_ = 17; +pub const ImPlotStyleVar__ImPlotStyleVar_LabelPadding: ImPlotStyleVar_ = 18; +pub const ImPlotStyleVar__ImPlotStyleVar_LegendPadding: ImPlotStyleVar_ = 19; +pub const ImPlotStyleVar__ImPlotStyleVar_InfoPadding: ImPlotStyleVar_ = 20; +pub const ImPlotStyleVar__ImPlotStyleVar_PlotMinSize: ImPlotStyleVar_ = 21; +pub const ImPlotStyleVar__ImPlotStyleVar_COUNT: ImPlotStyleVar_ = 22; pub type ImPlotStyleVar_ = u32; -pub const ImPlotMarker__ImPlotMarker_None: ImPlotMarker_ = 1; -pub const ImPlotMarker__ImPlotMarker_Circle: ImPlotMarker_ = 2; -pub const ImPlotMarker__ImPlotMarker_Square: ImPlotMarker_ = 4; -pub const ImPlotMarker__ImPlotMarker_Diamond: ImPlotMarker_ = 8; -pub const ImPlotMarker__ImPlotMarker_Up: ImPlotMarker_ = 16; -pub const ImPlotMarker__ImPlotMarker_Down: ImPlotMarker_ = 32; -pub const ImPlotMarker__ImPlotMarker_Left: ImPlotMarker_ = 64; -pub const ImPlotMarker__ImPlotMarker_Right: ImPlotMarker_ = 128; -pub const ImPlotMarker__ImPlotMarker_Cross: ImPlotMarker_ = 256; -pub const ImPlotMarker__ImPlotMarker_Plus: ImPlotMarker_ = 512; -pub const ImPlotMarker__ImPlotMarker_Asterisk: ImPlotMarker_ = 1024; -pub type ImPlotMarker_ = u32; +pub const ImPlotMarker__ImPlotMarker_None: ImPlotMarker_ = -1; +pub const ImPlotMarker__ImPlotMarker_Circle: ImPlotMarker_ = 0; +pub const ImPlotMarker__ImPlotMarker_Square: ImPlotMarker_ = 1; +pub const ImPlotMarker__ImPlotMarker_Diamond: ImPlotMarker_ = 2; +pub const ImPlotMarker__ImPlotMarker_Up: ImPlotMarker_ = 3; +pub const ImPlotMarker__ImPlotMarker_Down: ImPlotMarker_ = 4; +pub const ImPlotMarker__ImPlotMarker_Left: ImPlotMarker_ = 5; +pub const ImPlotMarker__ImPlotMarker_Right: ImPlotMarker_ = 6; +pub const ImPlotMarker__ImPlotMarker_Cross: ImPlotMarker_ = 7; +pub const ImPlotMarker__ImPlotMarker_Plus: ImPlotMarker_ = 8; +pub const ImPlotMarker__ImPlotMarker_Asterisk: ImPlotMarker_ = 9; +pub const ImPlotMarker__ImPlotMarker_COUNT: ImPlotMarker_ = 10; +pub type ImPlotMarker_ = i32; pub const ImPlotColormap__ImPlotColormap_Default: ImPlotColormap_ = 0; -pub const ImPlotColormap__ImPlotColormap_Dark: ImPlotColormap_ = 1; -pub const ImPlotColormap__ImPlotColormap_Pastel: ImPlotColormap_ = 2; -pub const ImPlotColormap__ImPlotColormap_Paired: ImPlotColormap_ = 3; -pub const ImPlotColormap__ImPlotColormap_Viridis: ImPlotColormap_ = 4; -pub const ImPlotColormap__ImPlotColormap_Plasma: ImPlotColormap_ = 5; -pub const ImPlotColormap__ImPlotColormap_Hot: ImPlotColormap_ = 6; -pub const ImPlotColormap__ImPlotColormap_Cool: ImPlotColormap_ = 7; -pub const ImPlotColormap__ImPlotColormap_Pink: ImPlotColormap_ = 8; -pub const ImPlotColormap__ImPlotColormap_Jet: ImPlotColormap_ = 9; -pub const ImPlotColormap__ImPlotColormap_COUNT: ImPlotColormap_ = 10; +pub const ImPlotColormap__ImPlotColormap_Deep: ImPlotColormap_ = 1; +pub const ImPlotColormap__ImPlotColormap_Dark: ImPlotColormap_ = 2; +pub const ImPlotColormap__ImPlotColormap_Pastel: ImPlotColormap_ = 3; +pub const ImPlotColormap__ImPlotColormap_Paired: ImPlotColormap_ = 4; +pub const ImPlotColormap__ImPlotColormap_Viridis: ImPlotColormap_ = 5; +pub const ImPlotColormap__ImPlotColormap_Plasma: ImPlotColormap_ = 6; +pub const ImPlotColormap__ImPlotColormap_Hot: ImPlotColormap_ = 7; +pub const ImPlotColormap__ImPlotColormap_Cool: ImPlotColormap_ = 8; +pub const ImPlotColormap__ImPlotColormap_Pink: ImPlotColormap_ = 9; +pub const ImPlotColormap__ImPlotColormap_Jet: ImPlotColormap_ = 10; +pub const ImPlotColormap__ImPlotColormap_COUNT: ImPlotColormap_ = 11; pub type ImPlotColormap_ = u32; #[repr(C)] #[derive(Debug, Copy, Clone)] @@ -9184,20 +9215,36 @@ fn bindgen_test_layout_ImPlotLimits() { #[derive(Debug, Copy, Clone)] pub struct ImPlotStyle { pub LineWeight: f32, - pub Marker: ImPlotMarker, + pub Marker: ::std::os::raw::c_int, pub MarkerSize: f32, pub MarkerWeight: f32, + pub FillAlpha: f32, pub ErrorBarSize: f32, pub ErrorBarWeight: f32, pub DigitalBitHeight: f32, pub DigitalBitGap: f32, - pub Colors: [ImVec4; 14usize], + pub PlotBorderSize: f32, + pub MinorAlpha: f32, + pub MajorTickLen: ImVec2, + pub MinorTickLen: ImVec2, + pub MajorTickSize: ImVec2, + pub MinorTickSize: ImVec2, + pub MajorGridSize: ImVec2, + pub MinorGridSize: ImVec2, + pub PlotPadding: ImVec2, + pub LabelPadding: ImVec2, + pub LegendPadding: ImVec2, + pub InfoPadding: ImVec2, + pub PlotMinSize: ImVec2, + pub Colors: [ImVec4; 24usize], + pub AntiAliasedLines: bool, + pub UseLocalTime: bool, } #[test] fn bindgen_test_layout_ImPlotStyle() { assert_eq!( ::std::mem::size_of::(), - 256usize, + 520usize, concat!("Size of: ", stringify!(ImPlotStyle)) ); assert_eq!( @@ -9246,8 +9293,18 @@ fn bindgen_test_layout_ImPlotStyle() { ) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).ErrorBarSize as *const _ as usize }, + unsafe { &(*(::std::ptr::null::())).FillAlpha as *const _ as usize }, 16usize, + concat!( + "Offset of field: ", + stringify!(ImPlotStyle), + "::", + stringify!(FillAlpha) + ) + ); + assert_eq!( + unsafe { &(*(::std::ptr::null::())).ErrorBarSize as *const _ as usize }, + 20usize, concat!( "Offset of field: ", stringify!(ImPlotStyle), @@ -9257,7 +9314,7 @@ fn bindgen_test_layout_ImPlotStyle() { ); assert_eq!( unsafe { &(*(::std::ptr::null::())).ErrorBarWeight as *const _ as usize }, - 20usize, + 24usize, concat!( "Offset of field: ", stringify!(ImPlotStyle), @@ -9267,7 +9324,7 @@ fn bindgen_test_layout_ImPlotStyle() { ); assert_eq!( unsafe { &(*(::std::ptr::null::())).DigitalBitHeight as *const _ as usize }, - 24usize, + 28usize, concat!( "Offset of field: ", stringify!(ImPlotStyle), @@ -9277,7 +9334,7 @@ fn bindgen_test_layout_ImPlotStyle() { ); assert_eq!( unsafe { &(*(::std::ptr::null::())).DigitalBitGap as *const _ as usize }, - 28usize, + 32usize, concat!( "Offset of field: ", stringify!(ImPlotStyle), @@ -9285,9 +9342,139 @@ fn bindgen_test_layout_ImPlotStyle() { stringify!(DigitalBitGap) ) ); + assert_eq!( + unsafe { &(*(::std::ptr::null::())).PlotBorderSize as *const _ as usize }, + 36usize, + concat!( + "Offset of field: ", + stringify!(ImPlotStyle), + "::", + stringify!(PlotBorderSize) + ) + ); + assert_eq!( + unsafe { &(*(::std::ptr::null::())).MinorAlpha as *const _ as usize }, + 40usize, + concat!( + "Offset of field: ", + stringify!(ImPlotStyle), + "::", + stringify!(MinorAlpha) + ) + ); + assert_eq!( + unsafe { &(*(::std::ptr::null::())).MajorTickLen as *const _ as usize }, + 44usize, + concat!( + "Offset of field: ", + stringify!(ImPlotStyle), + "::", + stringify!(MajorTickLen) + ) + ); + assert_eq!( + unsafe { &(*(::std::ptr::null::())).MinorTickLen as *const _ as usize }, + 52usize, + concat!( + "Offset of field: ", + stringify!(ImPlotStyle), + "::", + stringify!(MinorTickLen) + ) + ); + assert_eq!( + unsafe { &(*(::std::ptr::null::())).MajorTickSize as *const _ as usize }, + 60usize, + concat!( + "Offset of field: ", + stringify!(ImPlotStyle), + "::", + stringify!(MajorTickSize) + ) + ); + assert_eq!( + unsafe { &(*(::std::ptr::null::())).MinorTickSize as *const _ as usize }, + 68usize, + concat!( + "Offset of field: ", + stringify!(ImPlotStyle), + "::", + stringify!(MinorTickSize) + ) + ); + assert_eq!( + unsafe { &(*(::std::ptr::null::())).MajorGridSize as *const _ as usize }, + 76usize, + concat!( + "Offset of field: ", + stringify!(ImPlotStyle), + "::", + stringify!(MajorGridSize) + ) + ); + assert_eq!( + unsafe { &(*(::std::ptr::null::())).MinorGridSize as *const _ as usize }, + 84usize, + concat!( + "Offset of field: ", + stringify!(ImPlotStyle), + "::", + stringify!(MinorGridSize) + ) + ); + assert_eq!( + unsafe { &(*(::std::ptr::null::())).PlotPadding as *const _ as usize }, + 92usize, + concat!( + "Offset of field: ", + stringify!(ImPlotStyle), + "::", + stringify!(PlotPadding) + ) + ); + assert_eq!( + unsafe { &(*(::std::ptr::null::())).LabelPadding as *const _ as usize }, + 100usize, + concat!( + "Offset of field: ", + stringify!(ImPlotStyle), + "::", + stringify!(LabelPadding) + ) + ); + assert_eq!( + unsafe { &(*(::std::ptr::null::())).LegendPadding as *const _ as usize }, + 108usize, + concat!( + "Offset of field: ", + stringify!(ImPlotStyle), + "::", + stringify!(LegendPadding) + ) + ); + assert_eq!( + unsafe { &(*(::std::ptr::null::())).InfoPadding as *const _ as usize }, + 116usize, + concat!( + "Offset of field: ", + stringify!(ImPlotStyle), + "::", + stringify!(InfoPadding) + ) + ); + assert_eq!( + unsafe { &(*(::std::ptr::null::())).PlotMinSize as *const _ as usize }, + 124usize, + concat!( + "Offset of field: ", + stringify!(ImPlotStyle), + "::", + stringify!(PlotMinSize) + ) + ); assert_eq!( unsafe { &(*(::std::ptr::null::())).Colors as *const _ as usize }, - 32usize, + 132usize, concat!( "Offset of field: ", stringify!(ImPlotStyle), @@ -9295,6 +9482,179 @@ fn bindgen_test_layout_ImPlotStyle() { stringify!(Colors) ) ); + assert_eq!( + unsafe { &(*(::std::ptr::null::())).AntiAliasedLines as *const _ as usize }, + 516usize, + concat!( + "Offset of field: ", + stringify!(ImPlotStyle), + "::", + stringify!(AntiAliasedLines) + ) + ); + assert_eq!( + unsafe { &(*(::std::ptr::null::())).UseLocalTime as *const _ as usize }, + 517usize, + concat!( + "Offset of field: ", + stringify!(ImPlotStyle), + "::", + stringify!(UseLocalTime) + ) + ); +} +#[repr(C)] +#[derive(Debug, Copy, Clone)] +pub struct ImPlotInputMap { + pub PanButton: ImGuiMouseButton, + pub PanMod: ImGuiKeyModFlags, + pub FitButton: ImGuiMouseButton, + pub ContextMenuButton: ImGuiMouseButton, + pub BoxSelectButton: ImGuiMouseButton, + pub BoxSelectMod: ImGuiKeyModFlags, + pub BoxSelectCancelButton: ImGuiMouseButton, + pub QueryButton: ImGuiMouseButton, + pub QueryMod: ImGuiKeyModFlags, + pub QueryToggleMod: ImGuiKeyModFlags, + pub HorizontalMod: ImGuiKeyModFlags, + pub VerticalMod: ImGuiKeyModFlags, +} +#[test] +fn bindgen_test_layout_ImPlotInputMap() { + assert_eq!( + ::std::mem::size_of::(), + 48usize, + concat!("Size of: ", stringify!(ImPlotInputMap)) + ); + assert_eq!( + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(ImPlotInputMap)) + ); + assert_eq!( + unsafe { &(*(::std::ptr::null::())).PanButton as *const _ as usize }, + 0usize, + concat!( + "Offset of field: ", + stringify!(ImPlotInputMap), + "::", + stringify!(PanButton) + ) + ); + assert_eq!( + unsafe { &(*(::std::ptr::null::())).PanMod as *const _ as usize }, + 4usize, + concat!( + "Offset of field: ", + stringify!(ImPlotInputMap), + "::", + stringify!(PanMod) + ) + ); + assert_eq!( + unsafe { &(*(::std::ptr::null::())).FitButton as *const _ as usize }, + 8usize, + concat!( + "Offset of field: ", + stringify!(ImPlotInputMap), + "::", + stringify!(FitButton) + ) + ); + assert_eq!( + unsafe { + &(*(::std::ptr::null::())).ContextMenuButton as *const _ as usize + }, + 12usize, + concat!( + "Offset of field: ", + stringify!(ImPlotInputMap), + "::", + stringify!(ContextMenuButton) + ) + ); + assert_eq!( + unsafe { &(*(::std::ptr::null::())).BoxSelectButton as *const _ as usize }, + 16usize, + concat!( + "Offset of field: ", + stringify!(ImPlotInputMap), + "::", + stringify!(BoxSelectButton) + ) + ); + assert_eq!( + unsafe { &(*(::std::ptr::null::())).BoxSelectMod as *const _ as usize }, + 20usize, + concat!( + "Offset of field: ", + stringify!(ImPlotInputMap), + "::", + stringify!(BoxSelectMod) + ) + ); + assert_eq!( + unsafe { + &(*(::std::ptr::null::())).BoxSelectCancelButton as *const _ as usize + }, + 24usize, + concat!( + "Offset of field: ", + stringify!(ImPlotInputMap), + "::", + stringify!(BoxSelectCancelButton) + ) + ); + assert_eq!( + unsafe { &(*(::std::ptr::null::())).QueryButton as *const _ as usize }, + 28usize, + concat!( + "Offset of field: ", + stringify!(ImPlotInputMap), + "::", + stringify!(QueryButton) + ) + ); + assert_eq!( + unsafe { &(*(::std::ptr::null::())).QueryMod as *const _ as usize }, + 32usize, + concat!( + "Offset of field: ", + stringify!(ImPlotInputMap), + "::", + stringify!(QueryMod) + ) + ); + assert_eq!( + unsafe { &(*(::std::ptr::null::())).QueryToggleMod as *const _ as usize }, + 36usize, + concat!( + "Offset of field: ", + stringify!(ImPlotInputMap), + "::", + stringify!(QueryToggleMod) + ) + ); + assert_eq!( + unsafe { &(*(::std::ptr::null::())).HorizontalMod as *const _ as usize }, + 40usize, + concat!( + "Offset of field: ", + stringify!(ImPlotInputMap), + "::", + stringify!(HorizontalMod) + ) + ); + assert_eq!( + unsafe { &(*(::std::ptr::null::())).VerticalMod as *const _ as usize }, + 44usize, + concat!( + "Offset of field: ", + stringify!(ImPlotInputMap), + "::", + stringify!(VerticalMod) + ) + ); } extern "C" { pub fn ImPlotPoint_ImPlotPointNil() -> *mut ImPlotPoint; @@ -9306,23 +9666,20 @@ extern "C" { pub fn ImPlotPoint_ImPlotPointdouble(_x: f64, _y: f64) -> *mut ImPlotPoint; } extern "C" { - pub fn ImPlotRange_ImPlotRange() -> *mut ImPlotRange; + pub fn ImPlotRange_ImPlotRangeNil() -> *mut ImPlotRange; } extern "C" { pub fn ImPlotRange_destroy(self_: *mut ImPlotRange); } +extern "C" { + pub fn ImPlotRange_ImPlotRangedouble(_min: f64, _max: f64) -> *mut ImPlotRange; +} extern "C" { pub fn ImPlotRange_Contains(self_: *mut ImPlotRange, value: f64) -> bool; } extern "C" { pub fn ImPlotRange_Size(self_: *mut ImPlotRange) -> f64; } -extern "C" { - pub fn ImPlotLimits_ImPlotLimits() -> *mut ImPlotLimits; -} -extern "C" { - pub fn ImPlotLimits_destroy(self_: *mut ImPlotLimits); -} extern "C" { pub fn ImPlotLimits_ContainsPlotPoInt(self_: *mut ImPlotLimits, p: ImPlotPoint) -> bool; } @@ -9335,6 +9692,24 @@ extern "C" { extern "C" { pub fn ImPlotStyle_destroy(self_: *mut ImPlotStyle); } +extern "C" { + pub fn ImPlotInputMap_ImPlotInputMap() -> *mut ImPlotInputMap; +} +extern "C" { + pub fn ImPlotInputMap_destroy(self_: *mut ImPlotInputMap); +} +extern "C" { + pub fn ImPlot_CreateContext() -> *mut ImPlotContext; +} +extern "C" { + pub fn ImPlot_DestroyContext(ctx: *mut ImPlotContext); +} +extern "C" { + pub fn ImPlot_GetCurrentContext() -> *mut ImPlotContext; +} +extern "C" { + pub fn ImPlot_SetCurrentContext(ctx: *mut ImPlotContext); +} extern "C" { pub fn ImPlot_BeginPlot( title_id: *const ::std::os::raw::c_char, @@ -9487,6 +9862,91 @@ extern "C" { offset: ::std::os::raw::c_int, ); } +extern "C" { + pub fn ImPlot_PlotShadedFloatPtrIntFloat( + label_id: *const ::std::os::raw::c_char, + values: *const f32, + count: ::std::os::raw::c_int, + y_ref: f32, + offset: ::std::os::raw::c_int, + stride: ::std::os::raw::c_int, + ); +} +extern "C" { + pub fn ImPlot_PlotShadeddoublePtrIntdouble( + label_id: *const ::std::os::raw::c_char, + values: *const f64, + count: ::std::os::raw::c_int, + y_ref: f64, + offset: ::std::os::raw::c_int, + stride: ::std::os::raw::c_int, + ); +} +extern "C" { + pub fn ImPlot_PlotShadedFloatPtrFloatPtrIntFloat( + label_id: *const ::std::os::raw::c_char, + xs: *const f32, + ys: *const f32, + count: ::std::os::raw::c_int, + y_ref: f32, + offset: ::std::os::raw::c_int, + stride: ::std::os::raw::c_int, + ); +} +extern "C" { + pub fn ImPlot_PlotShadeddoublePtrdoublePtrIntdouble( + label_id: *const ::std::os::raw::c_char, + xs: *const f64, + ys: *const f64, + count: ::std::os::raw::c_int, + y_ref: f64, + offset: ::std::os::raw::c_int, + stride: ::std::os::raw::c_int, + ); +} +extern "C" { + pub fn ImPlot_PlotShadedFloatPtrFloatPtrFloatPtr( + label_id: *const ::std::os::raw::c_char, + xs: *const f32, + ys1: *const f32, + ys2: *const f32, + count: ::std::os::raw::c_int, + offset: ::std::os::raw::c_int, + stride: ::std::os::raw::c_int, + ); +} +extern "C" { + pub fn ImPlot_PlotShadeddoublePtrdoublePtrdoublePtr( + label_id: *const ::std::os::raw::c_char, + xs: *const f64, + ys1: *const f64, + ys2: *const f64, + count: ::std::os::raw::c_int, + offset: ::std::os::raw::c_int, + stride: ::std::os::raw::c_int, + ); +} +extern "C" { + pub fn ImPlot_PlotShadedFnPlotPoIntPtr( + label_id: *const ::std::os::raw::c_char, + getter1: ::std::option::Option< + unsafe extern "C" fn( + data: *mut ::std::os::raw::c_void, + idx: ::std::os::raw::c_int, + ) -> ImPlotPoint, + >, + data1: *mut ::std::os::raw::c_void, + getter2: ::std::option::Option< + unsafe extern "C" fn( + data: *mut ::std::os::raw::c_void, + idx: ::std::os::raw::c_int, + ) -> ImPlotPoint, + >, + data2: *mut ::std::os::raw::c_void, + count: ::std::os::raw::c_int, + offset: ::std::os::raw::c_int, + ); +} extern "C" { pub fn ImPlot_PlotBarsFloatPtrIntFloat( label_id: *const ::std::os::raw::c_char, @@ -9697,6 +10157,48 @@ extern "C" { stride: ::std::os::raw::c_int, ); } +extern "C" { + pub fn ImPlot_PlotStemsFloatPtrIntFloat( + label_id: *const ::std::os::raw::c_char, + values: *const f32, + count: ::std::os::raw::c_int, + y_ref: f32, + offset: ::std::os::raw::c_int, + stride: ::std::os::raw::c_int, + ); +} +extern "C" { + pub fn ImPlot_PlotStemsdoublePtrIntdouble( + label_id: *const ::std::os::raw::c_char, + values: *const f64, + count: ::std::os::raw::c_int, + y_ref: f64, + offset: ::std::os::raw::c_int, + stride: ::std::os::raw::c_int, + ); +} +extern "C" { + pub fn ImPlot_PlotStemsFloatPtrFloatPtr( + label_id: *const ::std::os::raw::c_char, + xs: *const f32, + ys: *const f32, + count: ::std::os::raw::c_int, + y_ref: f32, + offset: ::std::os::raw::c_int, + stride: ::std::os::raw::c_int, + ); +} +extern "C" { + pub fn ImPlot_PlotStemsdoublePtrdoublePtr( + label_id: *const ::std::os::raw::c_char, + xs: *const f64, + ys: *const f64, + count: ::std::os::raw::c_int, + y_ref: f64, + offset: ::std::os::raw::c_int, + stride: ::std::os::raw::c_int, + ); +} extern "C" { pub fn ImPlot_PlotPieChartFloatPtr( label_ids: *mut *const ::std::os::raw::c_char, @@ -9802,76 +10304,34 @@ extern "C" { ); } extern "C" { - pub fn ImPlot_IsPlotHovered() -> bool; + pub fn ImPlot_SetNextPlotLimits(xmin: f64, xmax: f64, ymin: f64, ymax: f64, cond: ImGuiCond); } extern "C" { - pub fn ImPlot_GetPlotMousePos(y_axis: ::std::os::raw::c_int) -> ImPlotPoint; -} -extern "C" { - pub fn ImPlot_GetPlotLimits(y_axis: ::std::os::raw::c_int) -> ImPlotLimits; -} -extern "C" { - pub fn ImPlot_IsPlotQueried() -> bool; -} -extern "C" { - pub fn ImPlot_GetPlotQuery(y_axis: ::std::os::raw::c_int) -> ImPlotLimits; -} -extern "C" { - pub fn ImPlot_GetStyle() -> *mut ImPlotStyle; -} -extern "C" { - pub fn ImPlot_PushStyleColorU32(idx: ImPlotCol, col: ImU32); -} -extern "C" { - pub fn ImPlot_PushStyleColorVec4(idx: ImPlotCol, col: ImVec4); -} -extern "C" { - pub fn ImPlot_PopStyleColor(count: ::std::os::raw::c_int); -} -extern "C" { - pub fn ImPlot_PushStyleVarFloat(idx: ImPlotStyleVar, val: f32); -} -extern "C" { - pub fn ImPlot_PushStyleVarInt(idx: ImPlotStyleVar, val: ::std::os::raw::c_int); -} -extern "C" { - pub fn ImPlot_PopStyleVar(count: ::std::os::raw::c_int); -} -extern "C" { - pub fn ImPlot_SetColormapPlotColormap(colormap: ImPlotColormap, samples: ::std::os::raw::c_int); -} -extern "C" { - pub fn ImPlot_SetColormapVec4Ptr(colors: *const ImVec4, num_colors: ::std::os::raw::c_int); -} -extern "C" { - pub fn ImPlot_GetColormapSize() -> ::std::os::raw::c_int; -} -extern "C" { - pub fn ImPlot_GetColormapColor(pOut: *mut ImVec4, index: ::std::os::raw::c_int); -} -extern "C" { - pub fn ImPlot_LerpColormap(pOut: *mut ImVec4, t: f32); -} -extern "C" { - pub fn ImPlot_SetNextPlotLimits( - x_min: f64, - x_max: f64, - y_min: f64, - y_max: f64, - cond: ImGuiCond, - ); -} -extern "C" { - pub fn ImPlot_SetNextPlotLimitsX(x_min: f64, x_max: f64, cond: ImGuiCond); + pub fn ImPlot_SetNextPlotLimitsX(xmin: f64, xmax: f64, cond: ImGuiCond); } extern "C" { pub fn ImPlot_SetNextPlotLimitsY( - y_min: f64, - y_max: f64, + ymin: f64, + ymax: f64, cond: ImGuiCond, y_axis: ::std::os::raw::c_int, ); } +extern "C" { + pub fn ImPlot_LinkNextPlotLimits( + xmin: *mut f64, + xmax: *mut f64, + ymin: *mut f64, + ymax: *mut f64, + ymin2: *mut f64, + ymax2: *mut f64, + ymin3: *mut f64, + ymax3: *mut f64, + ); +} +extern "C" { + pub fn ImPlot_FitNextPlotAxes(x: bool, y: bool, y2: bool, y3: bool); +} extern "C" { pub fn ImPlot_SetNextPlotTicksXdoublePtr( values: *const f64, @@ -9911,6 +10371,36 @@ extern "C" { extern "C" { pub fn ImPlot_SetPlotYAxis(y_axis: ::std::os::raw::c_int); } +extern "C" { + pub fn ImPlot_PixelsToPlotVec2( + pOut: *mut ImPlotPoint, + pix: ImVec2, + y_axis: ::std::os::raw::c_int, + ); +} +extern "C" { + pub fn ImPlot_PixelsToPlotFloat( + pOut: *mut ImPlotPoint, + x: f32, + y: f32, + y_axis: ::std::os::raw::c_int, + ); +} +extern "C" { + pub fn ImPlot_PlotToPixelsPlotPoInt( + pOut: *mut ImVec2, + plt: ImPlotPoint, + y_axis: ::std::os::raw::c_int, + ); +} +extern "C" { + pub fn ImPlot_PlotToPixelsdouble( + pOut: *mut ImVec2, + x: f64, + y: f64, + y_axis: ::std::os::raw::c_int, + ); +} extern "C" { pub fn ImPlot_GetPlotPos(pOut: *mut ImVec2); } @@ -9918,20 +10408,161 @@ extern "C" { pub fn ImPlot_GetPlotSize(pOut: *mut ImVec2); } extern "C" { - pub fn ImPlot_PixelsToPlot(pix: ImVec2, y_axis: ::std::os::raw::c_int) -> ImPlotPoint; + pub fn ImPlot_IsPlotHovered() -> bool; } extern "C" { - pub fn ImPlot_PlotToPixels(pOut: *mut ImVec2, plt: ImPlotPoint, y_axis: ::std::os::raw::c_int); + pub fn ImPlot_IsPlotXAxisHovered() -> bool; +} +extern "C" { + pub fn ImPlot_IsPlotYAxisHovered(y_axis: ::std::os::raw::c_int) -> bool; +} +extern "C" { + pub fn ImPlot_GetPlotMousePos(pOut: *mut ImPlotPoint, y_axis: ::std::os::raw::c_int); +} +extern "C" { + pub fn ImPlot_GetPlotLimits(pOut: *mut ImPlotLimits, y_axis: ::std::os::raw::c_int); +} +extern "C" { + pub fn ImPlot_IsPlotQueried() -> bool; +} +extern "C" { + pub fn ImPlot_GetPlotQuery(pOut: *mut ImPlotLimits, y_axis: ::std::os::raw::c_int); +} +extern "C" { + pub fn ImPlot_GetStyle() -> *mut ImPlotStyle; +} +extern "C" { + pub fn ImPlot_StyleColorsAuto(dst: *mut ImPlotStyle); +} +extern "C" { + pub fn ImPlot_StyleColorsClassic(dst: *mut ImPlotStyle); +} +extern "C" { + pub fn ImPlot_StyleColorsDark(dst: *mut ImPlotStyle); +} +extern "C" { + pub fn ImPlot_StyleColorsLight(dst: *mut ImPlotStyle); +} +extern "C" { + pub fn ImPlot_PushStyleColorU32(idx: ImPlotCol, col: ImU32); +} +extern "C" { + pub fn ImPlot_PushStyleColorVec4(idx: ImPlotCol, col: ImVec4); +} +extern "C" { + pub fn ImPlot_PopStyleColor(count: ::std::os::raw::c_int); +} +extern "C" { + pub fn ImPlot_PushStyleVarFloat(idx: ImPlotStyleVar, val: f32); +} +extern "C" { + pub fn ImPlot_PushStyleVarInt(idx: ImPlotStyleVar, val: ::std::os::raw::c_int); +} +extern "C" { + pub fn ImPlot_PushStyleVarVec2(idx: ImPlotStyleVar, val: ImVec2); +} +extern "C" { + pub fn ImPlot_PopStyleVar(count: ::std::os::raw::c_int); +} +extern "C" { + pub fn ImPlot_SetNextLineStyle(col: ImVec4, weight: f32); +} +extern "C" { + pub fn ImPlot_SetNextFillStyle(col: ImVec4, alpha_mod: f32); +} +extern "C" { + pub fn ImPlot_SetNextMarkerStyle( + marker: ImPlotMarker, + size: f32, + fill: ImVec4, + weight: f32, + outline: ImVec4, + ); +} +extern "C" { + pub fn ImPlot_SetNextErrorBarStyle(col: ImVec4, size: f32, weight: f32); +} +extern "C" { + pub fn ImPlot_GetStyleColorName(color: ImPlotCol) -> *const ::std::os::raw::c_char; +} +extern "C" { + pub fn ImPlot_GetMarkerName(marker: ImPlotMarker) -> *const ::std::os::raw::c_char; +} +extern "C" { + pub fn ImPlot_PushColormapPlotColormap(colormap: ImPlotColormap); +} +extern "C" { + pub fn ImPlot_PushColormapVec4Ptr(colormap: *const ImVec4, size: ::std::os::raw::c_int); +} +extern "C" { + pub fn ImPlot_PopColormap(count: ::std::os::raw::c_int); +} +extern "C" { + pub fn ImPlot_SetColormapVec4Ptr(colormap: *const ImVec4, size: ::std::os::raw::c_int); +} +extern "C" { + pub fn ImPlot_SetColormapPlotColormap(colormap: ImPlotColormap, samples: ::std::os::raw::c_int); +} +extern "C" { + pub fn ImPlot_GetColormapSize() -> ::std::os::raw::c_int; +} +extern "C" { + pub fn ImPlot_GetColormapColor(pOut: *mut ImVec4, index: ::std::os::raw::c_int); +} +extern "C" { + pub fn ImPlot_LerpColormap(pOut: *mut ImVec4, t: f32); +} +extern "C" { + pub fn ImPlot_NextColormapColor(pOut: *mut ImVec4); } extern "C" { pub fn ImPlot_ShowColormapScale(scale_min: f64, scale_max: f64, height: f32); } +extern "C" { + pub fn ImPlot_GetColormapName(colormap: ImPlotColormap) -> *const ::std::os::raw::c_char; +} +extern "C" { + pub fn ImPlot_IsLegendEntryHovered(label_id: *const ::std::os::raw::c_char) -> bool; +} +extern "C" { + pub fn ImPlot_BeginLegendDragDropSource( + label_id: *const ::std::os::raw::c_char, + flags: ImGuiDragDropFlags, + ) -> bool; +} +extern "C" { + pub fn ImPlot_EndLegendDragDropSource(); +} +extern "C" { + pub fn ImPlot_BeginLegendPopup( + label_id: *const ::std::os::raw::c_char, + mouse_button: ImGuiMouseButton, + ) -> bool; +} +extern "C" { + pub fn ImPlot_EndLegendPopup(); +} +extern "C" { + pub fn ImPlot_GetInputMap() -> *mut ImPlotInputMap; +} +extern "C" { + pub fn ImPlot_GetPlotDrawList() -> *mut ImDrawList; +} extern "C" { pub fn ImPlot_PushPlotClipRect(); } extern "C" { pub fn ImPlot_PopPlotClipRect(); } +extern "C" { + pub fn ImPlot_ShowStyleSelector(label: *const ::std::os::raw::c_char) -> bool; +} +extern "C" { + pub fn ImPlot_ShowStyleEditor(ref_: *mut ImPlotStyle); +} +extern "C" { + pub fn ImPlot_ShowUserGuide(); +} extern "C" { pub fn ImPlot_ShowDemoWindow(p_open: *mut bool); } diff --git a/implot-sys/third-party/cimplot b/implot-sys/third-party/cimplot index 929f61d..54ed676 160000 --- a/implot-sys/third-party/cimplot +++ b/implot-sys/third-party/cimplot @@ -1 +1 @@ -Subproject commit 929f61d27b8b4e3c899b2a386679a7f4a82826ce +Subproject commit 54ed676f42b7d96d6622f1c90df7d884246cc944 diff --git a/src/lib.rs b/src/lib.rs index 97aadb1..e1920f6 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -9,11 +9,10 @@ //! pub extern crate implot_sys as sys; use bitflags::bitflags; -use std::convert::TryFrom; pub use sys::imgui::Condition; use sys::imgui::{im_str, ImString}; // TODO(4bb4) facade-wrap these -pub use sys::{ImPlotLimits, ImPlotPoint, ImPlotRange, ImVec4}; +pub use sys::{ImPlotLimits, ImPlotPoint, ImPlotRange, ImVec2, ImVec4}; const DEFAULT_PLOT_SIZE_X: f32 = 400.0; const DEFAULT_PLOT_SIZE_Y: f32 = 400.0; @@ -23,27 +22,23 @@ const DEFAULT_PLOT_SIZE_Y: f32 = 400.0; // as enumerations in the traditional sense are plain enums. bitflags! { - /// Window hover check option flags. Documentation copied from implot.h for convenience. + /// Flags for customizing plot behavior and interaction. Documentation copied from implot.h for + /// convenience. ImPlot itself also has a "CanvasOnly" flag, which can be emulated here with + /// the combination of `NO_LEGEND`, `NO_MENUS`, `NO_BOX_SELECT` and `NO_MOUSE_POSITION`. #[repr(transparent)] pub struct PlotFlags: u32 { - /// The mouse position, in plot coordinates, will be displayed in the bottom-right - const MOUSE_POSITION = sys::ImPlotFlags__ImPlotFlags_MousePos; - /// A legend will be displayed in the top-left - const LEGEND = sys::ImPlotFlags__ImPlotFlags_Legend; - /// Plot items will be highlighted when their legend entry is hovered - const HIGHLIGHT = sys::ImPlotFlags__ImPlotFlags_Highlight; - /// The user will be able to box-select with right-mouse - const BOX_SELECT = sys::ImPlotFlags__ImPlotFlags_BoxSelect; - /// The user will be able to draw query rects with middle-mouse - const QUERY = sys::ImPlotFlags__ImPlotFlags_Query; - /// The user will be able to open a context menu with double-right click - const CONTEXT_MENU = sys::ImPlotFlags__ImPlotFlags_ContextMenu; - /// The default mouse cursor will be replaced with a crosshair when hovered - const CROSSHAIRS = sys::ImPlotFlags__ImPlotFlags_Crosshairs; - /// Plot data outside the plot area will be culled from rendering - const CULL_DATA = sys::ImPlotFlags__ImPlotFlags_CullData; - /// Lines and fills will be anti-aliased (not recommended) - const ANTIALIASED = sys::ImPlotFlags__ImPlotFlags_AntiAliased; + /// "Default" according to original docs + const NONE = sys::ImPlotFlags__ImPlotFlags_None; + /// Plot items will not be highlighted when their legend entry is hovered + const NO_LEGEND = sys::ImPlotFlags__ImPlotFlags_NoLegend; + /// The user will not be able to open context menus with double-right click + const NO_MENUS = sys::ImPlotFlags__ImPlotFlags_NoMenus; + /// The user will not be able to box-select with right-mouse + const NO_BOX_SELECT = sys::ImPlotFlags__ImPlotFlags_NoBoxSelect; + /// The mouse position, in plot coordinates, will not be displayed + const NO_MOUSE_POSITION = sys::ImPlotFlags__ImPlotFlags_NoMousePos; + /// Plot items will not be highlighted when their legend entry is hovered + const NO_HIGHLIGHT = sys::ImPlotFlags__ImPlotFlags_NoHighlight; /// A child window region will not be used to capture mouse scroll (can boost performance /// for single ImGui window applications) const NO_CHILD = sys::ImPlotFlags__ImPlotFlags_NoChild; @@ -51,67 +46,68 @@ bitflags! { const Y_AXIS_2 = sys::ImPlotFlags__ImPlotFlags_YAxis2; /// Enable a 3nd y axis const Y_AXIS_3 = sys::ImPlotFlags__ImPlotFlags_YAxis3; - /// Default selection of flags - const DEFAULT = sys::ImPlotFlags__ImPlotFlags_Default; + /// The user will be able to draw query rects with middle-mouse + const QUERY = sys::ImPlotFlags__ImPlotFlags_Query; + /// The default mouse cursor will be replaced with a crosshair when hovered + const CROSSHAIRS = sys::ImPlotFlags__ImPlotFlags_Crosshairs; + /// Plot data outside the plot area will be culled from rendering + const ANTIALIASED = sys::ImPlotFlags__ImPlotFlags_AntiAliased; } } bitflags! { - /// Axis flags. Documentation copied from implot.h for convenience. + /// Axis flags. Documentation copied from implot.h for convenience. ImPlot itself also + /// has `Lock`, which combines `LOCK_MIN` and `LOCK_MAX`, and `NoDecorations`, which combines + /// `NO_GRID_LINES`, `NO_TICK_MARKS` and `NO_TICK_LABELS`. #[repr(transparent)] pub struct AxisFlags: u32 { - /// Grid lines will be displayed - const GRID_LINES = sys::ImPlotAxisFlags__ImPlotAxisFlags_GridLines; - /// Tick marks will be displayed for each grid line - const TICK_MARKS = sys::ImPlotAxisFlags__ImPlotAxisFlags_TickMarks; - /// Text labels will be displayed for each grid line - const TICK_LABELS = sys::ImPlotAxisFlags__ImPlotAxisFlags_TickLabels; + /// "Default" according to original docs + const NONE = sys::ImPlotAxisFlags__ImPlotAxisFlags_None; + /// Grid lines will not be displayed + const NO_GRID_LINES = sys::ImPlotAxisFlags__ImPlotAxisFlags_NoGridLines; + /// Tick marks will not be displayed + const NO_TICK_MARKS = sys::ImPlotAxisFlags__ImPlotAxisFlags_NoTickMarks; + /// Text labels will not be displayed + const NO_TICK_LABELS = sys::ImPlotAxisFlags__ImPlotAxisFlags_NoTickLabels; + /// A logartithmic (base 10) axis scale will be used (mutually exclusive with AxisFlags::TIME) + const LOG_SCALE = sys::ImPlotAxisFlags__ImPlotAxisFlags_LogScale; + /// Axis will display date/time formatted labels (mutually exclusive with AxisFlags::LOG_SCALE) + const TIME = sys::ImPlotAxisFlags__ImPlotAxisFlags_Time; /// The axis will be inverted const INVERT = sys::ImPlotAxisFlags__ImPlotAxisFlags_Invert; /// The axis minimum value will be locked when panning/zooming const LOCK_MIN = sys::ImPlotAxisFlags__ImPlotAxisFlags_LockMin; /// The axis maximum value will be locked when panning/zooming const LOCK_MAX = sys::ImPlotAxisFlags__ImPlotAxisFlags_LockMax; - /// Grid divisions will adapt to the current pixel size the axis - const ADAPTIVE = sys::ImPlotAxisFlags__ImPlotAxisFlags_Adaptive; - /// A logartithmic (base 10) axis scale will be used - const LOG_SCALE = sys::ImPlotAxisFlags__ImPlotAxisFlags_LogScale; - /// Scientific notation will be used for tick labels if displayed (WIP, not very good yet) - const SCIENTIFIC = sys::ImPlotAxisFlags__ImPlotAxisFlags_Scientific; - /// Default set of flags - const DEFAULT = sys::ImPlotAxisFlags__ImPlotAxisFlags_Default; - /// Same as defaults, but without grid lines - const AUXILIARY = sys::ImPlotAxisFlags__ImPlotAxisFlags_Auxiliary; } } -bitflags! { - /// Axis flags. Documentation copied from implot.h for convenience. - #[repr(transparent)] - pub struct Marker: u32 { - /// no marker - const NONE = sys::ImPlotMarker__ImPlotMarker_None; - /// a circle marker will be rendered at each point - const CIRCLE = sys::ImPlotMarker__ImPlotMarker_Circle; - /// a square maker will be rendered at each point - const SQUARE = sys::ImPlotMarker__ImPlotMarker_Square; - /// a diamond marker will be rendered at each point - const DIAMOND = sys::ImPlotMarker__ImPlotMarker_Diamond; - /// an upward-pointing triangle marker will up rendered at each point - const UP = sys::ImPlotMarker__ImPlotMarker_Up; - /// an downward-pointing triangle marker will up rendered at each point - const DOWN = sys::ImPlotMarker__ImPlotMarker_Down; - /// an leftward-pointing triangle marker will up rendered at each point - const LEFT = sys::ImPlotMarker__ImPlotMarker_Left; - /// an rightward-pointing triangle marker will up rendered at each point - const RIGHT = sys::ImPlotMarker__ImPlotMarker_Right; - /// a cross marker will be rendered at each point (not filled) - const CROSS = sys::ImPlotMarker__ImPlotMarker_Cross; - /// a plus marker will be rendered at each point (not filled) - const PLUS = sys::ImPlotMarker__ImPlotMarker_Plus; - /// a asterisk marker will be rendered at each point (not filled) - const ASTERISK = sys::ImPlotMarker__ImPlotMarker_Asterisk; - } +/// Markers, documentation copied from implot.h for convenience. +#[repr(i32)] +#[derive(Copy, Clone, Debug)] +pub enum Marker { + /// no marker + None = sys::ImPlotMarker__ImPlotMarker_None, + /// a circle marker will be rendered at each point + Circle = sys::ImPlotMarker__ImPlotMarker_Circle, + /// a square maker will be rendered at each point + Square = sys::ImPlotMarker__ImPlotMarker_Square, + /// a diamond marker will be rendered at each point + Diamond = sys::ImPlotMarker__ImPlotMarker_Diamond, + /// an upward-pointing triangle marker will up rendered at each point + Up = sys::ImPlotMarker__ImPlotMarker_Up, + /// an downward-pointing triangle marker will up rendered at each point + Down = sys::ImPlotMarker__ImPlotMarker_Down, + /// an leftward-pointing triangle marker will up rendered at each point + Left = sys::ImPlotMarker__ImPlotMarker_Left, + /// an rightward-pointing triangle marker will up rendered at each point + Right = sys::ImPlotMarker__ImPlotMarker_Right, + /// a cross marker will be rendered at each point (not filled) + Cross = sys::ImPlotMarker__ImPlotMarker_Cross, + /// a plus marker will be rendered at each point (not filled) + Plus = sys::ImPlotMarker__ImPlotMarker_Plus, + /// a asterisk marker will be rendered at each point (not filled) + Asterisk = sys::ImPlotMarker__ImPlotMarker_Asterisk, } /// Colorable plot elements. These are called "ImPlotCol" in ImPlot itself, but I found that @@ -136,16 +132,36 @@ pub enum PlotColorElement { PlotBg = sys::ImPlotCol__ImPlotCol_PlotBg, /// Plot area border color (defaults to text color) PlotBorder = sys::ImPlotCol__ImPlotCol_PlotBorder, - /// X-axis grid/label color (defaults to 25% text color) + /// Legend background color (defaults to ImGuiCol_PopupBg) + LegendBackground = sys::ImPlotCol__ImPlotCol_LegendBg, + /// Legend border color (defaults to ImPlotCol_PlotBorder) + LegendBorder = sys::ImPlotCol__ImPlotCol_LegendBorder, + /// Legend text color (defaults to ImPlotCol_InlayText) + LegendText = sys::ImPlotCol__ImPlotCol_LegendText, + /// Plot title text color (defaults to ImGuiCol_Text) + TitleText = sys::ImPlotCol__ImPlotCol_TitleText, + /// Color of text appearing inside of plots (defaults to ImGuiCol_Text) + InlayText = sys::ImPlotCol__ImPlotCol_InlayText, + /// X-axis label and tick lables color (defaults to ImGuiCol_Text) XAxis = sys::ImPlotCol__ImPlotCol_XAxis, - /// Y-axis grid/label color (defaults to 25% text color) + /// X-axis grid color (defaults to 25% ImPlotCol_XAxis) + XAxisGrid = sys::ImPlotCol__ImPlotCol_XAxisGrid, + /// Y-axis label and tick labels color (defaults to ImGuiCol_Text) YAxis = sys::ImPlotCol__ImPlotCol_YAxis, - /// 2nd y-axis grid/label color (defaults to 25% text color) + /// Y-axis grid color (defaults to 25% ImPlotCol_YAxis) + YAxisGrid = sys::ImPlotCol__ImPlotCol_YAxisGrid, + /// 2nd y-axis label and tick labels color (defaults to ImGuiCol_Text) YAxis2 = sys::ImPlotCol__ImPlotCol_YAxis2, - /// 3rd y-axis grid/label color (defaults to 25% text color) + /// 2nd y-axis grid/label color (defaults to 25% ImPlotCol_YAxis2) + YAxisGrid2 = sys::ImPlotCol__ImPlotCol_YAxisGrid2, + /// 3rd y-axis label and tick labels color (defaults to ImGuiCol_Text) YAxis3 = sys::ImPlotCol__ImPlotCol_YAxis3, + /// 3rd y-axis grid/label color (defaults to 25% ImPlotCol_YAxis3) + YAxisGrid3 = sys::ImPlotCol__ImPlotCol_YAxisGrid3, /// Box-selection color (defaults to yellow) Selection = sys::ImPlotCol__ImPlotCol_Selection, + /// crosshairs color (defaults to ImPlotCol_PlotBorder) + Crosshairs = sys::ImPlotCol__ImPlotCol_Crosshairs, /// Box-query color (defaults to green) Query = sys::ImPlotCol__ImPlotCol_Query, } @@ -156,6 +172,8 @@ pub enum PlotColorElement { pub enum Colormap { /// ImPlot default colormap (n=10). Called "Standard" here because Default is reserved. Standard = sys::ImPlotColormap__ImPlotColormap_Default, + /// a.k.a. seaborn deep (n=10) + Deep = sys::ImPlotColormap__ImPlotColormap_Deep, /// a.k.a. matplotlib "Set1" (n=9) Dark = sys::ImPlotColormap__ImPlotColormap_Dark, /// a.k.a. matplotlib "Pastel1" (n=9) @@ -187,6 +205,8 @@ pub enum StyleVar { MarkerSize = sys::ImPlotStyleVar__ImPlotStyleVar_MarkerSize, /// f32, outline weight of markers in pixels MarkerWeight = sys::ImPlotStyleVar__ImPlotStyleVar_MarkerWeight, + /// f32, alpha modifier applied to all plot item fills + FillAlpha = sys::ImPlotStyleVar__ImPlotStyleVar_FillAlpha, /// f32, error bar whisker width in pixels ErrorBarSize = sys::ImPlotStyleVar__ImPlotStyleVar_ErrorBarSize, /// f32, error bar whisker weight in pixels @@ -195,6 +215,64 @@ pub enum StyleVar { DigitalBitHeight = sys::ImPlotStyleVar__ImPlotStyleVar_DigitalBitHeight, /// f32, digital channels bit padding gap in pixels DigitalBitGap = sys::ImPlotStyleVar__ImPlotStyleVar_DigitalBitGap, + /// f32, thickness of border around plot area + PlotBorderSize = sys::ImPlotStyleVar__ImPlotStyleVar_PlotBorderSize, + /// f32, alpha multiplier applied to minor axis grid lines + MinorAlpha = sys::ImPlotStyleVar__ImPlotStyleVar_MinorAlpha, + /// ImVec2, major tick lengths for X and Y axes + MajorTickLen = sys::ImPlotStyleVar__ImPlotStyleVar_MajorTickLen, + /// ImVec2, minor tick lengths for X and Y axes + MinorTickLen = sys::ImPlotStyleVar__ImPlotStyleVar_MinorTickLen, + /// ImVec2, line thickness of major ticks + MajorTickSize = sys::ImPlotStyleVar__ImPlotStyleVar_MajorTickSize, + /// ImVec2, line thickness of minor ticks + MinorTickSize = sys::ImPlotStyleVar__ImPlotStyleVar_MinorTickSize, + /// ImVec2, line thickness of major grid lines + MajorGridSize = sys::ImPlotStyleVar__ImPlotStyleVar_MajorGridSize, + /// ImVec2, line thickness of minor grid lines + MinorGridSize = sys::ImPlotStyleVar__ImPlotStyleVar_MinorGridSize, + /// ImVec2, padding between widget frame and plot area and/or labels + PlotPadding = sys::ImPlotStyleVar__ImPlotStyleVar_PlotPadding, + /// ImVec2, padding between axes labels, tick labels, and plot edge + LabelPadding = sys::ImPlotStyleVar__ImPlotStyleVar_LabelPadding, + /// ImVec2, legend padding from top-left of plot + LegendPadding = sys::ImPlotStyleVar__ImPlotStyleVar_LegendPadding, + /// ImVec2, padding between plot edge and interior info text + InfoPadding = sys::ImPlotStyleVar__ImPlotStyleVar_InfoPadding, + /// ImVec2, minimum size plot frame can be when shrunk + PlotMinSize = sys::ImPlotStyleVar__ImPlotStyleVar_PlotMinSize, +} + +// --- Context ----------------------------------------------------------------------------------- +// TODO(4bb4) Do this properly. +// The context should have to be created, and ideally it should be difficult to impossible +// to do things without having a context. implot-rs makes it so that there is a context and +// that context has a "frame()" function that returns a Ui, and that Ui is then used to create +// widgets. Windows are built with a build() function that takes a reference to that Ui as an +// argument, but also have a begin() function that take a context and put it in their token. +// +// I think I'll mirror that here. Adding some simple start and end functions for initial testing +// though. +pub struct Context { + raw: *mut sys::ImPlotContext, +} + +impl Context { + pub fn create() -> Self { + let ctx = unsafe { sys::ImPlot_CreateContext() }; + unsafe { + sys::ImPlot_SetCurrentContext(ctx); + } + Self { raw: ctx } + } +} + +impl Drop for Context { + fn drop(&mut self) { + unsafe { + sys::ImPlot_DestroyContext(self.raw); + } + } } // --- Main plot structure ----------------------------------------------------------------------- @@ -287,11 +365,11 @@ impl Plot { y_tick_positions: None, y_tick_labels: None, show_y_default_ticks: false, - plot_flags: PlotFlags::DEFAULT.bits() as sys::ImPlotFlags, - x_flags: AxisFlags::DEFAULT.bits() as sys::ImPlotAxisFlags, - y_flags: AxisFlags::DEFAULT.bits() as sys::ImPlotAxisFlags, - y2_flags: AxisFlags::DEFAULT.bits() as sys::ImPlotAxisFlags, - y3_flags: AxisFlags::DEFAULT.bits() as sys::ImPlotAxisFlags, + plot_flags: PlotFlags::NONE.bits() as sys::ImPlotFlags, + x_flags: AxisFlags::NONE.bits() as sys::ImPlotAxisFlags, + y_flags: AxisFlags::NONE.bits() as sys::ImPlotAxisFlags, + y2_flags: AxisFlags::NONE.bits() as sys::ImPlotAxisFlags, + y3_flags: AxisFlags::NONE.bits() as sys::ImPlotAxisFlags, } } @@ -860,23 +938,26 @@ pub fn push_style_var_f32(element: &StyleVar, value: f32) -> StyleVarToken { StyleVarToken { was_popped: false } } -/// Push an u32 style variable to the stack. The only u32 style variable is Marker +/// Push an u32 style variable to the stack. The only i32 style variable is Marker /// at the moment, for that, use something like /// ```no_run -/// # use implot::{push_style_var_u32, StyleVar, Marker}; -/// let markerchoice = push_style_var_u32(&StyleVar::Marker, Marker::CROSS.bits()); +/// # use implot::{push_style_var_i32, StyleVar, Marker}; +/// let markerchoice = push_style_var_i32(&StyleVar::Marker, Marker::Cross as i32); /// // plot things /// markerchoice.pop() /// ``` -pub fn push_style_var_u32(element: &StyleVar, value: u32) -> StyleVarToken { - // It is a bit funky that we take an i32 here, but the enum that gets created - // by bindgen contains u32 values, so we do the same but convert them to the - // internal i32 values here. Since this could overflow if a too large u32 value - // was passed, we do a safe conversion here, panicking if it fails. - let value_i32 = - i32::try_from(value).expect("Invalid style variable passed, has to fit in an i32"); +pub fn push_style_var_i32(element: &StyleVar, value: i32) -> StyleVarToken { unsafe { - sys::ImPlot_PushStyleVarInt(*element as sys::ImPlotStyleVar, value_i32); + sys::ImPlot_PushStyleVarInt(*element as sys::ImPlotStyleVar, value); + } + StyleVarToken { was_popped: false } +} + +/// Push an ImVec2 style variable to the stack. The returned token is used for removing +/// the variable from the stack again. +pub fn push_style_var_imvec2(element: &StyleVar, value: ImVec2) -> StyleVarToken { + unsafe { + sys::ImPlot_PushStyleVarVec2(*element as sys::ImPlotStyleVar, value); } StyleVarToken { was_popped: false } } @@ -918,21 +999,41 @@ pub fn is_plot_queried() -> bool { /// pertains to whatever Y axis was most recently selected. TODO(4bb4) add y axis selection pub fn get_plot_mouse_position() -> ImPlotPoint { let y_axis_selection = 0; - unsafe { sys::ImPlot_GetPlotMousePos(y_axis_selection) } + let mut point = ImPlotPoint { x: 0.0, y: 0.0 }; // doesn't seem to have default() + unsafe { + sys::ImPlot_GetPlotMousePos(&mut point as *mut ImPlotPoint, y_axis_selection); + } + point } /// Returns the current or most recent plot axis range. Currently pertains to whatever Y axis was /// most recently selected. TODO(4bb4) add y axis selection pub fn get_plot_limits() -> ImPlotLimits { let y_axis_selection = 0; - unsafe { sys::ImPlot_GetPlotLimits(y_axis_selection) } + // ImPlotLimits doesn't seem to have default() + 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 } /// Returns the query limits of the current or most recent plot. Currently pertains to whatever Y /// axis was most recently selected. TODO(4bb4) add y axis selection pub fn get_plot_query() -> ImPlotLimits { let y_axis_selection = 0; - unsafe { sys::ImPlot_GetPlotQuery(y_axis_selection) } + // ImPlotLimits doesn't seem to have default() + 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 } // --- Demo window -------------------------------------------------------------------------------