From 3c30e3f91971c5b6289c47f596016de46c06b5ca Mon Sep 17 00:00:00 2001 From: 4bb4 <67376761+4bb4@users.noreply.github.com> Date: Sun, 14 Mar 2021 20:53:07 +0100 Subject: [PATCH 1/2] Fixed conversions --- implot-examples/implot-glium-demo/Cargo.lock | 5 ++--- src/plot.rs | 8 ++++++-- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/implot-examples/implot-glium-demo/Cargo.lock b/implot-examples/implot-glium-demo/Cargo.lock index 99c4605..adf198c 100644 --- a/implot-examples/implot-glium-demo/Cargo.lock +++ b/implot-examples/implot-glium-demo/Cargo.lock @@ -650,12 +650,11 @@ dependencies = [ [[package]] name = "implot" -version = "0.3.0" +version = "0.4.0" dependencies = [ "bitflags", "imgui", "implot-sys", - "lazy_static", "parking_lot", "rustversion", ] @@ -678,7 +677,7 @@ dependencies = [ [[package]] name = "implot-sys" -version = "0.3.0" +version = "0.4.0" dependencies = [ "cc", "imgui-sys", diff --git a/src/plot.rs b/src/plot.rs index 4dd748d..3e28aea 100644 --- a/src/plot.rs +++ b/src/plot.rs @@ -85,7 +85,7 @@ bitflags! { /// let plotting_context = implot::Context::create(); /// let plot_ui = plotting_context.get_plot_ui(); /// implot::Plot::new("my title") -/// .size(300.0, 200.0) // other things such as .x_label("some_label") can be added too +/// .size([300.0, 200.0]) // other things such as .x_label("some_label") can be added too /// .build(&plot_ui, || { /// // Do things such as plotting lines /// }); @@ -419,11 +419,15 @@ impl Plot { self.maybe_set_tick_labels(); let should_render = unsafe { + let size_vec: ImVec2 = ImVec2 { + x: self.size[0], + y: self.size[1], + }; sys::ImPlot_BeginPlot( self.title.as_ptr(), self.x_label.as_ptr(), self.y_label.as_ptr(), - self.size.into(), + size_vec, self.plot_flags, self.x_flags, self.y_flags[0], From 5779f7e6d67b681ca309de72593a9b967322455c Mon Sep 17 00:00:00 2001 From: 4bb4 <67376761+4bb4@users.noreply.github.com> Date: Wed, 17 Mar 2021 19:17:14 +0100 Subject: [PATCH 2/2] Automated the work from #16 --- .../examples-shared/src/line_plots.rs | 20 + implot-examples/implot-wgpu-demo/Cargo.lock | 5 +- implot-sys-bindgen/Cargo.toml | 2 +- implot-sys-bindgen/src/main.rs | 34 +- implot-sys/src/bindings.rs | 957 +----------------- implot-sys/src/lib.rs | 9 + 6 files changed, 69 insertions(+), 958 deletions(-) diff --git a/implot-examples/examples-shared/src/line_plots.rs b/implot-examples/examples-shared/src/line_plots.rs index c8db9d9..c3342e7 100644 --- a/implot-examples/examples-shared/src/line_plots.rs +++ b/implot-examples/examples-shared/src/line_plots.rs @@ -331,6 +331,23 @@ pub fn show_colormaps_plot(ui: &Ui, plot_ui: &PlotUi) { set_colormap_from_preset(Colormap::Standard, 0); } +pub fn show_conversions_plot(ui: &Ui, plot_ui: &PlotUi) { + ui.text(im_str!( + "This header demonstrates (in code) how to convert various ranges into ImRange" + )); + let content_width = ui.window_content_region_width(); + Plot::new("Simple line plot, conversion 1") + .size([content_width, 300.0]) + .x_limits(&ImVec2 { x: 0.0, y: 1.0 }.into(), Condition::Always) + .y_limits(&[0.0, 1.0].into(), YAxisChoice::First, Condition::Always) + .build(plot_ui, || { + // If this is called outside a plot build callback, the program will panic. + let x_positions = vec![0.1, 0.9]; + let y_positions = vec![0.1, 0.9]; + PlotLine::new("legend label").plot(&x_positions, &y_positions); + }); +} + pub fn show_demo_headers(ui: &Ui, plot_ui: &PlotUi) { if CollapsingHeader::new(im_str!("Line plot: Basic")).build(&ui) { show_basic_plot(&ui, &plot_ui); @@ -353,4 +370,7 @@ pub fn show_demo_headers(ui: &Ui, plot_ui: &PlotUi) { if CollapsingHeader::new(im_str!("Line plot: \"Axis equal\"")).build(&ui) { show_axis_equal_plot(&ui, &plot_ui); } + if CollapsingHeader::new(im_str!("Line plot: Range conversions")).build(&ui) { + show_conversions_plot(&ui, &plot_ui); + } } diff --git a/implot-examples/implot-wgpu-demo/Cargo.lock b/implot-examples/implot-wgpu-demo/Cargo.lock index 010d085..069929d 100644 --- a/implot-examples/implot-wgpu-demo/Cargo.lock +++ b/implot-examples/implot-wgpu-demo/Cargo.lock @@ -660,19 +660,18 @@ dependencies = [ [[package]] name = "implot" -version = "0.3.0" +version = "0.4.0" dependencies = [ "bitflags", "imgui", "implot-sys", - "lazy_static", "parking_lot", "rustversion", ] [[package]] name = "implot-sys" -version = "0.3.0" +version = "0.4.0" dependencies = [ "cc", "imgui-sys", diff --git a/implot-sys-bindgen/Cargo.toml b/implot-sys-bindgen/Cargo.toml index 71280fc..8bc1db3 100644 --- a/implot-sys-bindgen/Cargo.toml +++ b/implot-sys-bindgen/Cargo.toml @@ -5,5 +5,5 @@ authors = ["Sandro Merkli"] edition = "2018" [dependencies] -bindgen = "0.55.1" +bindgen = "0.57" imgui-sys = { version = "=0.6.0" } diff --git a/implot-sys-bindgen/src/main.rs b/implot-sys-bindgen/src/main.rs index 66d702a..9e52ba7 100644 --- a/implot-sys-bindgen/src/main.rs +++ b/implot-sys-bindgen/src/main.rs @@ -1,5 +1,5 @@ use bindgen::{Builder, CargoCallbacks}; -use std::{env, path::PathBuf}; +use std::{env, io::Write, path::PathBuf}; // All this crate does is run bindgen on cimplot and store the result // in the src folder of the implot-sys crate. We add those bindings @@ -34,13 +34,39 @@ fn main() { ) .parse_callbacks(Box::new(CargoCallbacks)) .clang_arg("-DCIMGUI_DEFINE_ENUMS_AND_STRUCTS=1") + // Reuse the imgui types that implot requires from imgui_sys so we don't define + // our own new types. + .raw_line("pub use imgui_sys::{ImVec2, ImVec4, ImGuiCond, ImTextureID};") + .raw_line("pub use imgui_sys::{ImGuiContext, ImGuiKeyModFlags, ImDrawList};") + .raw_line("pub use imgui_sys::{ImGuiMouseButton, ImGuiDragDropFlags};") + .whitelist_recursively(false) .whitelist_function("ImPlot.*") .whitelist_type("ImPlot.*") + // We do want to create bindings for the scalar typedefs + .whitelist_type("Im[U|S][0-9]{1,2}") + // Remove some functions that would take a variable-argument list + .blacklist_function("ImPlot_AnnotateVVec4") + .blacklist_function("ImPlot_AnnotateVStr") + .blacklist_function("ImPlot_AnnotateClampedVVec4") + .blacklist_function("ImPlot_AnnotateClampedVStr") .generate() .expect("Unable to generate bindings"); + // The above type re-export shenanigans make bindgen unable to derive Copy, Clone and Debug on + // some types, but they would work - we hence manually re-add them here. + let mut bindings_string = bindings.to_string(); + ["ImPlotInputMap", "ImPlotStyle"].iter().for_each(|name| { + bindings_string = bindings_string.replace( + &format!("pub struct {}", name), + &format!("#[derive(Clone, Copy, Debug)]\npub struct {}", name), + ); + }); + + // Finally we write the bindings to a file. let out_path = sys_crate_path.join("src"); - bindings - .write_to_file(&out_path.join("bindings.rs")) - .expect("Couldn't write bindings!"); + let mut out_file = + std::fs::File::create(&out_path.join("bindings.rs")).expect("Could not open bindings file"); + out_file + .write_all(&bindings_string.into_bytes()[..]) + .expect("Couldn't write bindings"); } diff --git a/implot-sys/src/bindings.rs b/implot-sys/src/bindings.rs index 8adbdfc..102f59f 100644 --- a/implot-sys/src/bindings.rs +++ b/implot-sys/src/bindings.rs @@ -1,24 +1,9 @@ -/* automatically generated by rust-bindgen 0.55.1 */ +/* automatically generated by rust-bindgen 0.57.0 */ + +pub use imgui_sys::{ImVec2, ImVec4, ImGuiCond, ImTextureID}; +pub use imgui_sys::{ImGuiContext, ImGuiKeyModFlags, ImDrawList}; +pub use imgui_sys::{ImGuiMouseButton, ImGuiDragDropFlags}; -pub type va_list = __builtin_va_list; -pub type __int64_t = ::std::os::raw::c_long; -pub type __uint64_t = ::std::os::raw::c_ulong; -#[repr(C)] -#[derive(Debug, Copy, Clone)] -pub struct ImGuiContext { - _unused: [u8; 0], -} -#[repr(C)] -#[derive(Debug, Copy, Clone)] -pub struct ImDrawListSharedData { - _unused: [u8; 0], -} -pub type ImGuiCond = ::std::os::raw::c_int; -pub type ImGuiMouseButton = ::std::os::raw::c_int; -pub type ImDrawListFlags = ::std::os::raw::c_int; -pub type ImGuiDragDropFlags = ::std::os::raw::c_int; -pub type ImGuiKeyModFlags = ::std::os::raw::c_int; -pub type ImTextureID = *mut ::std::os::raw::c_void; pub type ImS8 = ::std::os::raw::c_schar; pub type ImU8 = ::std::os::raw::c_uchar; pub type ImS16 = ::std::os::raw::c_short; @@ -27,834 +12,6 @@ pub type ImS32 = ::std::os::raw::c_int; pub type ImU32 = ::std::os::raw::c_uint; pub type ImS64 = i64; pub type ImU64 = u64; -pub type ImDrawCallback = ::std::option::Option< - unsafe extern "C" fn(parent_list: *const ImDrawList, cmd: *const ImDrawCmd), ->; -pub type ImDrawIdx = ::std::os::raw::c_ushort; -#[repr(C)] -#[derive(Debug, Copy, Clone)] -pub struct ImVector_ImDrawChannel { - pub Size: ::std::os::raw::c_int, - pub Capacity: ::std::os::raw::c_int, - pub Data: *mut ImDrawChannel, -} -#[test] -fn bindgen_test_layout_ImVector_ImDrawChannel() { - assert_eq!( - ::std::mem::size_of::(), - 16usize, - concat!("Size of: ", stringify!(ImVector_ImDrawChannel)) - ); - assert_eq!( - ::std::mem::align_of::(), - 8usize, - concat!("Alignment of ", stringify!(ImVector_ImDrawChannel)) - ); - assert_eq!( - unsafe { &(*(::std::ptr::null::())).Size as *const _ as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(ImVector_ImDrawChannel), - "::", - stringify!(Size) - ) - ); - assert_eq!( - unsafe { &(*(::std::ptr::null::())).Capacity as *const _ as usize }, - 4usize, - concat!( - "Offset of field: ", - stringify!(ImVector_ImDrawChannel), - "::", - stringify!(Capacity) - ) - ); - assert_eq!( - unsafe { &(*(::std::ptr::null::())).Data as *const _ as usize }, - 8usize, - concat!( - "Offset of field: ", - stringify!(ImVector_ImDrawChannel), - "::", - stringify!(Data) - ) - ); -} -#[repr(C)] -#[derive(Debug, Copy, Clone)] -pub struct ImVector_ImDrawCmd { - pub Size: ::std::os::raw::c_int, - pub Capacity: ::std::os::raw::c_int, - pub Data: *mut ImDrawCmd, -} -#[test] -fn bindgen_test_layout_ImVector_ImDrawCmd() { - assert_eq!( - ::std::mem::size_of::(), - 16usize, - concat!("Size of: ", stringify!(ImVector_ImDrawCmd)) - ); - assert_eq!( - ::std::mem::align_of::(), - 8usize, - concat!("Alignment of ", stringify!(ImVector_ImDrawCmd)) - ); - assert_eq!( - unsafe { &(*(::std::ptr::null::())).Size as *const _ as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(ImVector_ImDrawCmd), - "::", - stringify!(Size) - ) - ); - assert_eq!( - unsafe { &(*(::std::ptr::null::())).Capacity as *const _ as usize }, - 4usize, - concat!( - "Offset of field: ", - stringify!(ImVector_ImDrawCmd), - "::", - stringify!(Capacity) - ) - ); - assert_eq!( - unsafe { &(*(::std::ptr::null::())).Data as *const _ as usize }, - 8usize, - concat!( - "Offset of field: ", - stringify!(ImVector_ImDrawCmd), - "::", - stringify!(Data) - ) - ); -} -#[repr(C)] -#[derive(Debug, Copy, Clone)] -pub struct ImVector_ImDrawIdx { - pub Size: ::std::os::raw::c_int, - pub Capacity: ::std::os::raw::c_int, - pub Data: *mut ImDrawIdx, -} -#[test] -fn bindgen_test_layout_ImVector_ImDrawIdx() { - assert_eq!( - ::std::mem::size_of::(), - 16usize, - concat!("Size of: ", stringify!(ImVector_ImDrawIdx)) - ); - assert_eq!( - ::std::mem::align_of::(), - 8usize, - concat!("Alignment of ", stringify!(ImVector_ImDrawIdx)) - ); - assert_eq!( - unsafe { &(*(::std::ptr::null::())).Size as *const _ as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(ImVector_ImDrawIdx), - "::", - stringify!(Size) - ) - ); - assert_eq!( - unsafe { &(*(::std::ptr::null::())).Capacity as *const _ as usize }, - 4usize, - concat!( - "Offset of field: ", - stringify!(ImVector_ImDrawIdx), - "::", - stringify!(Capacity) - ) - ); - assert_eq!( - unsafe { &(*(::std::ptr::null::())).Data as *const _ as usize }, - 8usize, - concat!( - "Offset of field: ", - stringify!(ImVector_ImDrawIdx), - "::", - stringify!(Data) - ) - ); -} -#[repr(C)] -#[derive(Debug, Copy, Clone)] -pub struct ImVector_ImDrawVert { - pub Size: ::std::os::raw::c_int, - pub Capacity: ::std::os::raw::c_int, - pub Data: *mut ImDrawVert, -} -#[test] -fn bindgen_test_layout_ImVector_ImDrawVert() { - assert_eq!( - ::std::mem::size_of::(), - 16usize, - concat!("Size of: ", stringify!(ImVector_ImDrawVert)) - ); - assert_eq!( - ::std::mem::align_of::(), - 8usize, - concat!("Alignment of ", stringify!(ImVector_ImDrawVert)) - ); - assert_eq!( - unsafe { &(*(::std::ptr::null::())).Size as *const _ as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(ImVector_ImDrawVert), - "::", - stringify!(Size) - ) - ); - assert_eq!( - unsafe { &(*(::std::ptr::null::())).Capacity as *const _ as usize }, - 4usize, - concat!( - "Offset of field: ", - stringify!(ImVector_ImDrawVert), - "::", - stringify!(Capacity) - ) - ); - assert_eq!( - unsafe { &(*(::std::ptr::null::())).Data as *const _ as usize }, - 8usize, - concat!( - "Offset of field: ", - stringify!(ImVector_ImDrawVert), - "::", - stringify!(Data) - ) - ); -} -#[repr(C)] -#[derive(Debug, Copy, Clone)] -pub struct ImVector_ImTextureID { - pub Size: ::std::os::raw::c_int, - pub Capacity: ::std::os::raw::c_int, - pub Data: *mut ImTextureID, -} -#[test] -fn bindgen_test_layout_ImVector_ImTextureID() { - assert_eq!( - ::std::mem::size_of::(), - 16usize, - concat!("Size of: ", stringify!(ImVector_ImTextureID)) - ); - assert_eq!( - ::std::mem::align_of::(), - 8usize, - concat!("Alignment of ", stringify!(ImVector_ImTextureID)) - ); - assert_eq!( - unsafe { &(*(::std::ptr::null::())).Size as *const _ as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(ImVector_ImTextureID), - "::", - stringify!(Size) - ) - ); - assert_eq!( - unsafe { &(*(::std::ptr::null::())).Capacity as *const _ as usize }, - 4usize, - concat!( - "Offset of field: ", - stringify!(ImVector_ImTextureID), - "::", - stringify!(Capacity) - ) - ); - assert_eq!( - unsafe { &(*(::std::ptr::null::())).Data as *const _ as usize }, - 8usize, - concat!( - "Offset of field: ", - stringify!(ImVector_ImTextureID), - "::", - stringify!(Data) - ) - ); -} -#[repr(C)] -#[derive(Debug, Copy, Clone)] -pub struct ImVector_ImVec2 { - pub Size: ::std::os::raw::c_int, - pub Capacity: ::std::os::raw::c_int, - pub Data: *mut ImVec2, -} -#[test] -fn bindgen_test_layout_ImVector_ImVec2() { - assert_eq!( - ::std::mem::size_of::(), - 16usize, - concat!("Size of: ", stringify!(ImVector_ImVec2)) - ); - assert_eq!( - ::std::mem::align_of::(), - 8usize, - concat!("Alignment of ", stringify!(ImVector_ImVec2)) - ); - assert_eq!( - unsafe { &(*(::std::ptr::null::())).Size as *const _ as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(ImVector_ImVec2), - "::", - stringify!(Size) - ) - ); - assert_eq!( - unsafe { &(*(::std::ptr::null::())).Capacity as *const _ as usize }, - 4usize, - concat!( - "Offset of field: ", - stringify!(ImVector_ImVec2), - "::", - stringify!(Capacity) - ) - ); - assert_eq!( - unsafe { &(*(::std::ptr::null::())).Data as *const _ as usize }, - 8usize, - concat!( - "Offset of field: ", - stringify!(ImVector_ImVec2), - "::", - stringify!(Data) - ) - ); -} -#[repr(C)] -#[derive(Debug, Copy, Clone)] -pub struct ImVector_ImVec4 { - pub Size: ::std::os::raw::c_int, - pub Capacity: ::std::os::raw::c_int, - pub Data: *mut ImVec4, -} -#[test] -fn bindgen_test_layout_ImVector_ImVec4() { - assert_eq!( - ::std::mem::size_of::(), - 16usize, - concat!("Size of: ", stringify!(ImVector_ImVec4)) - ); - assert_eq!( - ::std::mem::align_of::(), - 8usize, - concat!("Alignment of ", stringify!(ImVector_ImVec4)) - ); - assert_eq!( - unsafe { &(*(::std::ptr::null::())).Size as *const _ as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(ImVector_ImVec4), - "::", - stringify!(Size) - ) - ); - assert_eq!( - unsafe { &(*(::std::ptr::null::())).Capacity as *const _ as usize }, - 4usize, - concat!( - "Offset of field: ", - stringify!(ImVector_ImVec4), - "::", - stringify!(Capacity) - ) - ); - assert_eq!( - unsafe { &(*(::std::ptr::null::())).Data as *const _ as usize }, - 8usize, - concat!( - "Offset of field: ", - stringify!(ImVector_ImVec4), - "::", - stringify!(Data) - ) - ); -} -#[repr(C)] -#[derive(Debug, Copy, Clone)] -pub struct ImVec2 { - pub x: f32, - pub y: f32, -} -#[test] -fn bindgen_test_layout_ImVec2() { - assert_eq!( - ::std::mem::size_of::(), - 8usize, - concat!("Size of: ", stringify!(ImVec2)) - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(ImVec2)) - ); - assert_eq!( - unsafe { &(*(::std::ptr::null::())).x as *const _ as usize }, - 0usize, - concat!("Offset of field: ", stringify!(ImVec2), "::", stringify!(x)) - ); - assert_eq!( - unsafe { &(*(::std::ptr::null::())).y as *const _ as usize }, - 4usize, - concat!("Offset of field: ", stringify!(ImVec2), "::", stringify!(y)) - ); -} -#[repr(C)] -#[derive(Debug, Copy, Clone)] -pub struct ImVec4 { - pub x: f32, - pub y: f32, - pub z: f32, - pub w: f32, -} -#[test] -fn bindgen_test_layout_ImVec4() { - assert_eq!( - ::std::mem::size_of::(), - 16usize, - concat!("Size of: ", stringify!(ImVec4)) - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(ImVec4)) - ); - assert_eq!( - unsafe { &(*(::std::ptr::null::())).x as *const _ as usize }, - 0usize, - concat!("Offset of field: ", stringify!(ImVec4), "::", stringify!(x)) - ); - assert_eq!( - unsafe { &(*(::std::ptr::null::())).y as *const _ as usize }, - 4usize, - concat!("Offset of field: ", stringify!(ImVec4), "::", stringify!(y)) - ); - assert_eq!( - unsafe { &(*(::std::ptr::null::())).z as *const _ as usize }, - 8usize, - concat!("Offset of field: ", stringify!(ImVec4), "::", stringify!(z)) - ); - assert_eq!( - unsafe { &(*(::std::ptr::null::())).w as *const _ as usize }, - 12usize, - concat!("Offset of field: ", stringify!(ImVec4), "::", stringify!(w)) - ); -} -#[repr(C)] -#[derive(Debug, Copy, Clone)] -pub struct ImDrawCmd { - pub ClipRect: ImVec4, - pub TextureId: ImTextureID, - pub VtxOffset: ::std::os::raw::c_uint, - pub IdxOffset: ::std::os::raw::c_uint, - pub ElemCount: ::std::os::raw::c_uint, - pub UserCallback: ImDrawCallback, - pub UserCallbackData: *mut ::std::os::raw::c_void, -} -#[test] -fn bindgen_test_layout_ImDrawCmd() { - assert_eq!( - ::std::mem::size_of::(), - 56usize, - concat!("Size of: ", stringify!(ImDrawCmd)) - ); - assert_eq!( - ::std::mem::align_of::(), - 8usize, - concat!("Alignment of ", stringify!(ImDrawCmd)) - ); - assert_eq!( - unsafe { &(*(::std::ptr::null::())).ClipRect as *const _ as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(ImDrawCmd), - "::", - stringify!(ClipRect) - ) - ); - assert_eq!( - unsafe { &(*(::std::ptr::null::())).TextureId as *const _ as usize }, - 16usize, - concat!( - "Offset of field: ", - stringify!(ImDrawCmd), - "::", - stringify!(TextureId) - ) - ); - assert_eq!( - unsafe { &(*(::std::ptr::null::())).VtxOffset as *const _ as usize }, - 24usize, - concat!( - "Offset of field: ", - stringify!(ImDrawCmd), - "::", - stringify!(VtxOffset) - ) - ); - assert_eq!( - unsafe { &(*(::std::ptr::null::())).IdxOffset as *const _ as usize }, - 28usize, - concat!( - "Offset of field: ", - stringify!(ImDrawCmd), - "::", - stringify!(IdxOffset) - ) - ); - assert_eq!( - unsafe { &(*(::std::ptr::null::())).ElemCount as *const _ as usize }, - 32usize, - concat!( - "Offset of field: ", - stringify!(ImDrawCmd), - "::", - stringify!(ElemCount) - ) - ); - assert_eq!( - unsafe { &(*(::std::ptr::null::())).UserCallback as *const _ as usize }, - 40usize, - concat!( - "Offset of field: ", - stringify!(ImDrawCmd), - "::", - stringify!(UserCallback) - ) - ); - assert_eq!( - unsafe { &(*(::std::ptr::null::())).UserCallbackData as *const _ as usize }, - 48usize, - concat!( - "Offset of field: ", - stringify!(ImDrawCmd), - "::", - stringify!(UserCallbackData) - ) - ); -} -#[repr(C)] -#[derive(Debug, Copy, Clone)] -pub struct ImDrawVert { - pub pos: ImVec2, - pub uv: ImVec2, - pub col: ImU32, -} -#[test] -fn bindgen_test_layout_ImDrawVert() { - assert_eq!( - ::std::mem::size_of::(), - 20usize, - concat!("Size of: ", stringify!(ImDrawVert)) - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(ImDrawVert)) - ); - assert_eq!( - unsafe { &(*(::std::ptr::null::())).pos as *const _ as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(ImDrawVert), - "::", - stringify!(pos) - ) - ); - assert_eq!( - unsafe { &(*(::std::ptr::null::())).uv as *const _ as usize }, - 8usize, - concat!( - "Offset of field: ", - stringify!(ImDrawVert), - "::", - stringify!(uv) - ) - ); - assert_eq!( - unsafe { &(*(::std::ptr::null::())).col as *const _ as usize }, - 16usize, - concat!( - "Offset of field: ", - stringify!(ImDrawVert), - "::", - stringify!(col) - ) - ); -} -#[repr(C)] -#[derive(Debug, Copy, Clone)] -pub struct ImDrawChannel { - pub _CmdBuffer: ImVector_ImDrawCmd, - pub _IdxBuffer: ImVector_ImDrawIdx, -} -#[test] -fn bindgen_test_layout_ImDrawChannel() { - assert_eq!( - ::std::mem::size_of::(), - 32usize, - concat!("Size of: ", stringify!(ImDrawChannel)) - ); - assert_eq!( - ::std::mem::align_of::(), - 8usize, - concat!("Alignment of ", stringify!(ImDrawChannel)) - ); - assert_eq!( - unsafe { &(*(::std::ptr::null::()))._CmdBuffer as *const _ as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(ImDrawChannel), - "::", - stringify!(_CmdBuffer) - ) - ); - assert_eq!( - unsafe { &(*(::std::ptr::null::()))._IdxBuffer as *const _ as usize }, - 16usize, - concat!( - "Offset of field: ", - stringify!(ImDrawChannel), - "::", - stringify!(_IdxBuffer) - ) - ); -} -#[repr(C)] -#[derive(Debug, Copy, Clone)] -pub struct ImDrawListSplitter { - pub _Current: ::std::os::raw::c_int, - pub _Count: ::std::os::raw::c_int, - pub _Channels: ImVector_ImDrawChannel, -} -#[test] -fn bindgen_test_layout_ImDrawListSplitter() { - assert_eq!( - ::std::mem::size_of::(), - 24usize, - concat!("Size of: ", stringify!(ImDrawListSplitter)) - ); - assert_eq!( - ::std::mem::align_of::(), - 8usize, - concat!("Alignment of ", stringify!(ImDrawListSplitter)) - ); - assert_eq!( - unsafe { &(*(::std::ptr::null::()))._Current as *const _ as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(ImDrawListSplitter), - "::", - stringify!(_Current) - ) - ); - assert_eq!( - unsafe { &(*(::std::ptr::null::()))._Count as *const _ as usize }, - 4usize, - concat!( - "Offset of field: ", - stringify!(ImDrawListSplitter), - "::", - stringify!(_Count) - ) - ); - assert_eq!( - unsafe { &(*(::std::ptr::null::()))._Channels as *const _ as usize }, - 8usize, - concat!( - "Offset of field: ", - stringify!(ImDrawListSplitter), - "::", - stringify!(_Channels) - ) - ); -} -#[repr(C)] -#[derive(Debug, Copy, Clone)] -pub struct ImDrawList { - pub CmdBuffer: ImVector_ImDrawCmd, - pub IdxBuffer: ImVector_ImDrawIdx, - pub VtxBuffer: ImVector_ImDrawVert, - pub Flags: ImDrawListFlags, - pub _Data: *const ImDrawListSharedData, - pub _OwnerName: *const ::std::os::raw::c_char, - pub _VtxCurrentIdx: ::std::os::raw::c_uint, - pub _VtxWritePtr: *mut ImDrawVert, - pub _IdxWritePtr: *mut ImDrawIdx, - pub _ClipRectStack: ImVector_ImVec4, - pub _TextureIdStack: ImVector_ImTextureID, - pub _Path: ImVector_ImVec2, - pub _CmdHeader: ImDrawCmd, - pub _Splitter: ImDrawListSplitter, -} -#[test] -fn bindgen_test_layout_ImDrawList() { - assert_eq!( - ::std::mem::size_of::(), - 224usize, - concat!("Size of: ", stringify!(ImDrawList)) - ); - assert_eq!( - ::std::mem::align_of::(), - 8usize, - concat!("Alignment of ", stringify!(ImDrawList)) - ); - assert_eq!( - unsafe { &(*(::std::ptr::null::())).CmdBuffer as *const _ as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(ImDrawList), - "::", - stringify!(CmdBuffer) - ) - ); - assert_eq!( - unsafe { &(*(::std::ptr::null::())).IdxBuffer as *const _ as usize }, - 16usize, - concat!( - "Offset of field: ", - stringify!(ImDrawList), - "::", - stringify!(IdxBuffer) - ) - ); - assert_eq!( - unsafe { &(*(::std::ptr::null::())).VtxBuffer as *const _ as usize }, - 32usize, - concat!( - "Offset of field: ", - stringify!(ImDrawList), - "::", - stringify!(VtxBuffer) - ) - ); - assert_eq!( - unsafe { &(*(::std::ptr::null::())).Flags as *const _ as usize }, - 48usize, - concat!( - "Offset of field: ", - stringify!(ImDrawList), - "::", - stringify!(Flags) - ) - ); - assert_eq!( - unsafe { &(*(::std::ptr::null::()))._Data as *const _ as usize }, - 56usize, - concat!( - "Offset of field: ", - stringify!(ImDrawList), - "::", - stringify!(_Data) - ) - ); - assert_eq!( - unsafe { &(*(::std::ptr::null::()))._OwnerName as *const _ as usize }, - 64usize, - concat!( - "Offset of field: ", - stringify!(ImDrawList), - "::", - stringify!(_OwnerName) - ) - ); - assert_eq!( - unsafe { &(*(::std::ptr::null::()))._VtxCurrentIdx as *const _ as usize }, - 72usize, - concat!( - "Offset of field: ", - stringify!(ImDrawList), - "::", - stringify!(_VtxCurrentIdx) - ) - ); - assert_eq!( - unsafe { &(*(::std::ptr::null::()))._VtxWritePtr as *const _ as usize }, - 80usize, - concat!( - "Offset of field: ", - stringify!(ImDrawList), - "::", - stringify!(_VtxWritePtr) - ) - ); - assert_eq!( - unsafe { &(*(::std::ptr::null::()))._IdxWritePtr as *const _ as usize }, - 88usize, - concat!( - "Offset of field: ", - stringify!(ImDrawList), - "::", - stringify!(_IdxWritePtr) - ) - ); - assert_eq!( - unsafe { &(*(::std::ptr::null::()))._ClipRectStack as *const _ as usize }, - 96usize, - concat!( - "Offset of field: ", - stringify!(ImDrawList), - "::", - stringify!(_ClipRectStack) - ) - ); - assert_eq!( - unsafe { &(*(::std::ptr::null::()))._TextureIdStack as *const _ as usize }, - 112usize, - concat!( - "Offset of field: ", - stringify!(ImDrawList), - "::", - stringify!(_TextureIdStack) - ) - ); - assert_eq!( - unsafe { &(*(::std::ptr::null::()))._Path as *const _ as usize }, - 128usize, - concat!( - "Offset of field: ", - stringify!(ImDrawList), - "::", - stringify!(_Path) - ) - ); - assert_eq!( - unsafe { &(*(::std::ptr::null::()))._CmdHeader as *const _ as usize }, - 144usize, - concat!( - "Offset of field: ", - stringify!(ImDrawList), - "::", - stringify!(_CmdHeader) - ) - ); - assert_eq!( - unsafe { &(*(::std::ptr::null::()))._Splitter as *const _ as usize }, - 200usize, - concat!( - "Offset of field: ", - stringify!(ImDrawList), - "::", - stringify!(_Splitter) - ) - ); -} #[repr(C)] #[derive(Debug, Copy, Clone)] pub struct ImPlotContext { @@ -1113,7 +270,7 @@ fn bindgen_test_layout_ImPlotLimits() { ); } #[repr(C)] -#[derive(Debug, Copy, Clone)] +#[derive(Clone, Copy, Debug)] pub struct ImPlotStyle { pub LineWeight: f32, pub Marker: ::std::os::raw::c_int, @@ -1482,7 +639,7 @@ fn bindgen_test_layout_ImPlotStyle() { ); } #[repr(C)] -#[derive(Debug, Copy, Clone)] +#[derive(Clone, Copy, Debug)] pub struct ImPlotInputMap { pub PanButton: ImGuiMouseButton, pub PanMod: ImGuiKeyModFlags, @@ -4328,25 +3485,6 @@ extern "C" { ... ); } -extern "C" { - pub fn ImPlot_AnnotateVStr( - x: f64, - y: f64, - pix_offset: ImVec2, - fmt: *const ::std::os::raw::c_char, - args: *mut __va_list_tag, - ); -} -extern "C" { - pub fn ImPlot_AnnotateVVec4( - x: f64, - y: f64, - pix_offset: ImVec2, - color: ImVec4, - fmt: *const ::std::os::raw::c_char, - args: *mut __va_list_tag, - ); -} extern "C" { pub fn ImPlot_AnnotateClampedStr( x: f64, @@ -4366,25 +3504,6 @@ extern "C" { ... ); } -extern "C" { - pub fn ImPlot_AnnotateClampedVStr( - x: f64, - y: f64, - pix_offset: ImVec2, - fmt: *const ::std::os::raw::c_char, - args: *mut __va_list_tag, - ); -} -extern "C" { - pub fn ImPlot_AnnotateClampedVVec4( - x: f64, - y: f64, - pix_offset: ImVec2, - color: ImVec4, - fmt: *const ::std::os::raw::c_char, - args: *mut __va_list_tag, - ); -} extern "C" { pub fn ImPlot_DragLineX( id: *const ::std::os::raw::c_char, @@ -4666,65 +3785,3 @@ extern "C" { offset: ::std::os::raw::c_int, ); } -pub type __builtin_va_list = [__va_list_tag; 1usize]; -#[repr(C)] -#[derive(Debug, Copy, Clone)] -pub struct __va_list_tag { - pub gp_offset: ::std::os::raw::c_uint, - pub fp_offset: ::std::os::raw::c_uint, - pub overflow_arg_area: *mut ::std::os::raw::c_void, - pub reg_save_area: *mut ::std::os::raw::c_void, -} -#[test] -fn bindgen_test_layout___va_list_tag() { - assert_eq!( - ::std::mem::size_of::<__va_list_tag>(), - 24usize, - concat!("Size of: ", stringify!(__va_list_tag)) - ); - assert_eq!( - ::std::mem::align_of::<__va_list_tag>(), - 8usize, - concat!("Alignment of ", stringify!(__va_list_tag)) - ); - assert_eq!( - unsafe { &(*(::std::ptr::null::<__va_list_tag>())).gp_offset as *const _ as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(__va_list_tag), - "::", - stringify!(gp_offset) - ) - ); - assert_eq!( - unsafe { &(*(::std::ptr::null::<__va_list_tag>())).fp_offset as *const _ as usize }, - 4usize, - concat!( - "Offset of field: ", - stringify!(__va_list_tag), - "::", - stringify!(fp_offset) - ) - ); - assert_eq!( - unsafe { &(*(::std::ptr::null::<__va_list_tag>())).overflow_arg_area as *const _ as usize }, - 8usize, - concat!( - "Offset of field: ", - stringify!(__va_list_tag), - "::", - stringify!(overflow_arg_area) - ) - ); - assert_eq!( - unsafe { &(*(::std::ptr::null::<__va_list_tag>())).reg_save_area as *const _ as usize }, - 16usize, - concat!( - "Offset of field: ", - stringify!(__va_list_tag), - "::", - stringify!(reg_save_area) - ) - ); -} diff --git a/implot-sys/src/lib.rs b/implot-sys/src/lib.rs index ecb5db7..cbca664 100644 --- a/implot-sys/src/lib.rs +++ b/implot-sys/src/lib.rs @@ -36,6 +36,15 @@ impl From<(f64, f64)> for ImPlotRange { } } +impl From for ImPlotRange { + fn from(from: ImVec2) -> Self { + ImPlotRange { + Min: from.x as f64, + Max: from.y as f64, + } + } +} + #[cfg(test)] mod tests { use super::*;