Merge branch 'improve_api_experiments'

This commit is contained in:
4bb4 2021-03-17 19:20:16 +01:00
commit f2a4c6a3d8
8 changed files with 77 additions and 963 deletions

View file

@ -331,6 +331,23 @@ pub fn show_colormaps_plot(ui: &Ui, plot_ui: &PlotUi) {
set_colormap_from_preset(Colormap::Standard, 0); 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) { pub fn show_demo_headers(ui: &Ui, plot_ui: &PlotUi) {
if CollapsingHeader::new(im_str!("Line plot: Basic")).build(&ui) { if CollapsingHeader::new(im_str!("Line plot: Basic")).build(&ui) {
show_basic_plot(&ui, &plot_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) { if CollapsingHeader::new(im_str!("Line plot: \"Axis equal\"")).build(&ui) {
show_axis_equal_plot(&ui, &plot_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);
}
} }

View file

@ -650,12 +650,11 @@ dependencies = [
[[package]] [[package]]
name = "implot" name = "implot"
version = "0.3.0" version = "0.4.0"
dependencies = [ dependencies = [
"bitflags", "bitflags",
"imgui", "imgui",
"implot-sys", "implot-sys",
"lazy_static",
"parking_lot", "parking_lot",
"rustversion", "rustversion",
] ]
@ -678,7 +677,7 @@ dependencies = [
[[package]] [[package]]
name = "implot-sys" name = "implot-sys"
version = "0.3.0" version = "0.4.0"
dependencies = [ dependencies = [
"cc", "cc",
"imgui-sys", "imgui-sys",

View file

@ -660,19 +660,18 @@ dependencies = [
[[package]] [[package]]
name = "implot" name = "implot"
version = "0.3.0" version = "0.4.0"
dependencies = [ dependencies = [
"bitflags", "bitflags",
"imgui", "imgui",
"implot-sys", "implot-sys",
"lazy_static",
"parking_lot", "parking_lot",
"rustversion", "rustversion",
] ]
[[package]] [[package]]
name = "implot-sys" name = "implot-sys"
version = "0.3.0" version = "0.4.0"
dependencies = [ dependencies = [
"cc", "cc",
"imgui-sys", "imgui-sys",

View file

@ -5,5 +5,5 @@ authors = ["Sandro Merkli"]
edition = "2018" edition = "2018"
[dependencies] [dependencies]
bindgen = "0.55.1" bindgen = "0.57"
imgui-sys = { version = "=0.6.0" } imgui-sys = { version = "=0.6.0" }

View file

@ -1,5 +1,5 @@
use bindgen::{Builder, CargoCallbacks}; 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 // 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 // in the src folder of the implot-sys crate. We add those bindings
@ -34,13 +34,39 @@ fn main() {
) )
.parse_callbacks(Box::new(CargoCallbacks)) .parse_callbacks(Box::new(CargoCallbacks))
.clang_arg("-DCIMGUI_DEFINE_ENUMS_AND_STRUCTS=1") .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_function("ImPlot.*")
.whitelist_type("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() .generate()
.expect("Unable to generate bindings"); .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"); let out_path = sys_crate_path.join("src");
bindings let mut out_file =
.write_to_file(&out_path.join("bindings.rs")) std::fs::File::create(&out_path.join("bindings.rs")).expect("Could not open bindings file");
.expect("Couldn't write bindings!"); out_file
.write_all(&bindings_string.into_bytes()[..])
.expect("Couldn't write bindings");
} }

View file

@ -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 ImS8 = ::std::os::raw::c_schar;
pub type ImU8 = ::std::os::raw::c_uchar; pub type ImU8 = ::std::os::raw::c_uchar;
pub type ImS16 = ::std::os::raw::c_short; 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 ImU32 = ::std::os::raw::c_uint;
pub type ImS64 = i64; pub type ImS64 = i64;
pub type ImU64 = u64; 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::<ImVector_ImDrawChannel>(),
16usize,
concat!("Size of: ", stringify!(ImVector_ImDrawChannel))
);
assert_eq!(
::std::mem::align_of::<ImVector_ImDrawChannel>(),
8usize,
concat!("Alignment of ", stringify!(ImVector_ImDrawChannel))
);
assert_eq!(
unsafe { &(*(::std::ptr::null::<ImVector_ImDrawChannel>())).Size as *const _ as usize },
0usize,
concat!(
"Offset of field: ",
stringify!(ImVector_ImDrawChannel),
"::",
stringify!(Size)
)
);
assert_eq!(
unsafe { &(*(::std::ptr::null::<ImVector_ImDrawChannel>())).Capacity as *const _ as usize },
4usize,
concat!(
"Offset of field: ",
stringify!(ImVector_ImDrawChannel),
"::",
stringify!(Capacity)
)
);
assert_eq!(
unsafe { &(*(::std::ptr::null::<ImVector_ImDrawChannel>())).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::<ImVector_ImDrawCmd>(),
16usize,
concat!("Size of: ", stringify!(ImVector_ImDrawCmd))
);
assert_eq!(
::std::mem::align_of::<ImVector_ImDrawCmd>(),
8usize,
concat!("Alignment of ", stringify!(ImVector_ImDrawCmd))
);
assert_eq!(
unsafe { &(*(::std::ptr::null::<ImVector_ImDrawCmd>())).Size as *const _ as usize },
0usize,
concat!(
"Offset of field: ",
stringify!(ImVector_ImDrawCmd),
"::",
stringify!(Size)
)
);
assert_eq!(
unsafe { &(*(::std::ptr::null::<ImVector_ImDrawCmd>())).Capacity as *const _ as usize },
4usize,
concat!(
"Offset of field: ",
stringify!(ImVector_ImDrawCmd),
"::",
stringify!(Capacity)
)
);
assert_eq!(
unsafe { &(*(::std::ptr::null::<ImVector_ImDrawCmd>())).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::<ImVector_ImDrawIdx>(),
16usize,
concat!("Size of: ", stringify!(ImVector_ImDrawIdx))
);
assert_eq!(
::std::mem::align_of::<ImVector_ImDrawIdx>(),
8usize,
concat!("Alignment of ", stringify!(ImVector_ImDrawIdx))
);
assert_eq!(
unsafe { &(*(::std::ptr::null::<ImVector_ImDrawIdx>())).Size as *const _ as usize },
0usize,
concat!(
"Offset of field: ",
stringify!(ImVector_ImDrawIdx),
"::",
stringify!(Size)
)
);
assert_eq!(
unsafe { &(*(::std::ptr::null::<ImVector_ImDrawIdx>())).Capacity as *const _ as usize },
4usize,
concat!(
"Offset of field: ",
stringify!(ImVector_ImDrawIdx),
"::",
stringify!(Capacity)
)
);
assert_eq!(
unsafe { &(*(::std::ptr::null::<ImVector_ImDrawIdx>())).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::<ImVector_ImDrawVert>(),
16usize,
concat!("Size of: ", stringify!(ImVector_ImDrawVert))
);
assert_eq!(
::std::mem::align_of::<ImVector_ImDrawVert>(),
8usize,
concat!("Alignment of ", stringify!(ImVector_ImDrawVert))
);
assert_eq!(
unsafe { &(*(::std::ptr::null::<ImVector_ImDrawVert>())).Size as *const _ as usize },
0usize,
concat!(
"Offset of field: ",
stringify!(ImVector_ImDrawVert),
"::",
stringify!(Size)
)
);
assert_eq!(
unsafe { &(*(::std::ptr::null::<ImVector_ImDrawVert>())).Capacity as *const _ as usize },
4usize,
concat!(
"Offset of field: ",
stringify!(ImVector_ImDrawVert),
"::",
stringify!(Capacity)
)
);
assert_eq!(
unsafe { &(*(::std::ptr::null::<ImVector_ImDrawVert>())).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::<ImVector_ImTextureID>(),
16usize,
concat!("Size of: ", stringify!(ImVector_ImTextureID))
);
assert_eq!(
::std::mem::align_of::<ImVector_ImTextureID>(),
8usize,
concat!("Alignment of ", stringify!(ImVector_ImTextureID))
);
assert_eq!(
unsafe { &(*(::std::ptr::null::<ImVector_ImTextureID>())).Size as *const _ as usize },
0usize,
concat!(
"Offset of field: ",
stringify!(ImVector_ImTextureID),
"::",
stringify!(Size)
)
);
assert_eq!(
unsafe { &(*(::std::ptr::null::<ImVector_ImTextureID>())).Capacity as *const _ as usize },
4usize,
concat!(
"Offset of field: ",
stringify!(ImVector_ImTextureID),
"::",
stringify!(Capacity)
)
);
assert_eq!(
unsafe { &(*(::std::ptr::null::<ImVector_ImTextureID>())).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::<ImVector_ImVec2>(),
16usize,
concat!("Size of: ", stringify!(ImVector_ImVec2))
);
assert_eq!(
::std::mem::align_of::<ImVector_ImVec2>(),
8usize,
concat!("Alignment of ", stringify!(ImVector_ImVec2))
);
assert_eq!(
unsafe { &(*(::std::ptr::null::<ImVector_ImVec2>())).Size as *const _ as usize },
0usize,
concat!(
"Offset of field: ",
stringify!(ImVector_ImVec2),
"::",
stringify!(Size)
)
);
assert_eq!(
unsafe { &(*(::std::ptr::null::<ImVector_ImVec2>())).Capacity as *const _ as usize },
4usize,
concat!(
"Offset of field: ",
stringify!(ImVector_ImVec2),
"::",
stringify!(Capacity)
)
);
assert_eq!(
unsafe { &(*(::std::ptr::null::<ImVector_ImVec2>())).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::<ImVector_ImVec4>(),
16usize,
concat!("Size of: ", stringify!(ImVector_ImVec4))
);
assert_eq!(
::std::mem::align_of::<ImVector_ImVec4>(),
8usize,
concat!("Alignment of ", stringify!(ImVector_ImVec4))
);
assert_eq!(
unsafe { &(*(::std::ptr::null::<ImVector_ImVec4>())).Size as *const _ as usize },
0usize,
concat!(
"Offset of field: ",
stringify!(ImVector_ImVec4),
"::",
stringify!(Size)
)
);
assert_eq!(
unsafe { &(*(::std::ptr::null::<ImVector_ImVec4>())).Capacity as *const _ as usize },
4usize,
concat!(
"Offset of field: ",
stringify!(ImVector_ImVec4),
"::",
stringify!(Capacity)
)
);
assert_eq!(
unsafe { &(*(::std::ptr::null::<ImVector_ImVec4>())).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::<ImVec2>(),
8usize,
concat!("Size of: ", stringify!(ImVec2))
);
assert_eq!(
::std::mem::align_of::<ImVec2>(),
4usize,
concat!("Alignment of ", stringify!(ImVec2))
);
assert_eq!(
unsafe { &(*(::std::ptr::null::<ImVec2>())).x as *const _ as usize },
0usize,
concat!("Offset of field: ", stringify!(ImVec2), "::", stringify!(x))
);
assert_eq!(
unsafe { &(*(::std::ptr::null::<ImVec2>())).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::<ImVec4>(),
16usize,
concat!("Size of: ", stringify!(ImVec4))
);
assert_eq!(
::std::mem::align_of::<ImVec4>(),
4usize,
concat!("Alignment of ", stringify!(ImVec4))
);
assert_eq!(
unsafe { &(*(::std::ptr::null::<ImVec4>())).x as *const _ as usize },
0usize,
concat!("Offset of field: ", stringify!(ImVec4), "::", stringify!(x))
);
assert_eq!(
unsafe { &(*(::std::ptr::null::<ImVec4>())).y as *const _ as usize },
4usize,
concat!("Offset of field: ", stringify!(ImVec4), "::", stringify!(y))
);
assert_eq!(
unsafe { &(*(::std::ptr::null::<ImVec4>())).z as *const _ as usize },
8usize,
concat!("Offset of field: ", stringify!(ImVec4), "::", stringify!(z))
);
assert_eq!(
unsafe { &(*(::std::ptr::null::<ImVec4>())).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::<ImDrawCmd>(),
56usize,
concat!("Size of: ", stringify!(ImDrawCmd))
);
assert_eq!(
::std::mem::align_of::<ImDrawCmd>(),
8usize,
concat!("Alignment of ", stringify!(ImDrawCmd))
);
assert_eq!(
unsafe { &(*(::std::ptr::null::<ImDrawCmd>())).ClipRect as *const _ as usize },
0usize,
concat!(
"Offset of field: ",
stringify!(ImDrawCmd),
"::",
stringify!(ClipRect)
)
);
assert_eq!(
unsafe { &(*(::std::ptr::null::<ImDrawCmd>())).TextureId as *const _ as usize },
16usize,
concat!(
"Offset of field: ",
stringify!(ImDrawCmd),
"::",
stringify!(TextureId)
)
);
assert_eq!(
unsafe { &(*(::std::ptr::null::<ImDrawCmd>())).VtxOffset as *const _ as usize },
24usize,
concat!(
"Offset of field: ",
stringify!(ImDrawCmd),
"::",
stringify!(VtxOffset)
)
);
assert_eq!(
unsafe { &(*(::std::ptr::null::<ImDrawCmd>())).IdxOffset as *const _ as usize },
28usize,
concat!(
"Offset of field: ",
stringify!(ImDrawCmd),
"::",
stringify!(IdxOffset)
)
);
assert_eq!(
unsafe { &(*(::std::ptr::null::<ImDrawCmd>())).ElemCount as *const _ as usize },
32usize,
concat!(
"Offset of field: ",
stringify!(ImDrawCmd),
"::",
stringify!(ElemCount)
)
);
assert_eq!(
unsafe { &(*(::std::ptr::null::<ImDrawCmd>())).UserCallback as *const _ as usize },
40usize,
concat!(
"Offset of field: ",
stringify!(ImDrawCmd),
"::",
stringify!(UserCallback)
)
);
assert_eq!(
unsafe { &(*(::std::ptr::null::<ImDrawCmd>())).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::<ImDrawVert>(),
20usize,
concat!("Size of: ", stringify!(ImDrawVert))
);
assert_eq!(
::std::mem::align_of::<ImDrawVert>(),
4usize,
concat!("Alignment of ", stringify!(ImDrawVert))
);
assert_eq!(
unsafe { &(*(::std::ptr::null::<ImDrawVert>())).pos as *const _ as usize },
0usize,
concat!(
"Offset of field: ",
stringify!(ImDrawVert),
"::",
stringify!(pos)
)
);
assert_eq!(
unsafe { &(*(::std::ptr::null::<ImDrawVert>())).uv as *const _ as usize },
8usize,
concat!(
"Offset of field: ",
stringify!(ImDrawVert),
"::",
stringify!(uv)
)
);
assert_eq!(
unsafe { &(*(::std::ptr::null::<ImDrawVert>())).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::<ImDrawChannel>(),
32usize,
concat!("Size of: ", stringify!(ImDrawChannel))
);
assert_eq!(
::std::mem::align_of::<ImDrawChannel>(),
8usize,
concat!("Alignment of ", stringify!(ImDrawChannel))
);
assert_eq!(
unsafe { &(*(::std::ptr::null::<ImDrawChannel>()))._CmdBuffer as *const _ as usize },
0usize,
concat!(
"Offset of field: ",
stringify!(ImDrawChannel),
"::",
stringify!(_CmdBuffer)
)
);
assert_eq!(
unsafe { &(*(::std::ptr::null::<ImDrawChannel>()))._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::<ImDrawListSplitter>(),
24usize,
concat!("Size of: ", stringify!(ImDrawListSplitter))
);
assert_eq!(
::std::mem::align_of::<ImDrawListSplitter>(),
8usize,
concat!("Alignment of ", stringify!(ImDrawListSplitter))
);
assert_eq!(
unsafe { &(*(::std::ptr::null::<ImDrawListSplitter>()))._Current as *const _ as usize },
0usize,
concat!(
"Offset of field: ",
stringify!(ImDrawListSplitter),
"::",
stringify!(_Current)
)
);
assert_eq!(
unsafe { &(*(::std::ptr::null::<ImDrawListSplitter>()))._Count as *const _ as usize },
4usize,
concat!(
"Offset of field: ",
stringify!(ImDrawListSplitter),
"::",
stringify!(_Count)
)
);
assert_eq!(
unsafe { &(*(::std::ptr::null::<ImDrawListSplitter>()))._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::<ImDrawList>(),
224usize,
concat!("Size of: ", stringify!(ImDrawList))
);
assert_eq!(
::std::mem::align_of::<ImDrawList>(),
8usize,
concat!("Alignment of ", stringify!(ImDrawList))
);
assert_eq!(
unsafe { &(*(::std::ptr::null::<ImDrawList>())).CmdBuffer as *const _ as usize },
0usize,
concat!(
"Offset of field: ",
stringify!(ImDrawList),
"::",
stringify!(CmdBuffer)
)
);
assert_eq!(
unsafe { &(*(::std::ptr::null::<ImDrawList>())).IdxBuffer as *const _ as usize },
16usize,
concat!(
"Offset of field: ",
stringify!(ImDrawList),
"::",
stringify!(IdxBuffer)
)
);
assert_eq!(
unsafe { &(*(::std::ptr::null::<ImDrawList>())).VtxBuffer as *const _ as usize },
32usize,
concat!(
"Offset of field: ",
stringify!(ImDrawList),
"::",
stringify!(VtxBuffer)
)
);
assert_eq!(
unsafe { &(*(::std::ptr::null::<ImDrawList>())).Flags as *const _ as usize },
48usize,
concat!(
"Offset of field: ",
stringify!(ImDrawList),
"::",
stringify!(Flags)
)
);
assert_eq!(
unsafe { &(*(::std::ptr::null::<ImDrawList>()))._Data as *const _ as usize },
56usize,
concat!(
"Offset of field: ",
stringify!(ImDrawList),
"::",
stringify!(_Data)
)
);
assert_eq!(
unsafe { &(*(::std::ptr::null::<ImDrawList>()))._OwnerName as *const _ as usize },
64usize,
concat!(
"Offset of field: ",
stringify!(ImDrawList),
"::",
stringify!(_OwnerName)
)
);
assert_eq!(
unsafe { &(*(::std::ptr::null::<ImDrawList>()))._VtxCurrentIdx as *const _ as usize },
72usize,
concat!(
"Offset of field: ",
stringify!(ImDrawList),
"::",
stringify!(_VtxCurrentIdx)
)
);
assert_eq!(
unsafe { &(*(::std::ptr::null::<ImDrawList>()))._VtxWritePtr as *const _ as usize },
80usize,
concat!(
"Offset of field: ",
stringify!(ImDrawList),
"::",
stringify!(_VtxWritePtr)
)
);
assert_eq!(
unsafe { &(*(::std::ptr::null::<ImDrawList>()))._IdxWritePtr as *const _ as usize },
88usize,
concat!(
"Offset of field: ",
stringify!(ImDrawList),
"::",
stringify!(_IdxWritePtr)
)
);
assert_eq!(
unsafe { &(*(::std::ptr::null::<ImDrawList>()))._ClipRectStack as *const _ as usize },
96usize,
concat!(
"Offset of field: ",
stringify!(ImDrawList),
"::",
stringify!(_ClipRectStack)
)
);
assert_eq!(
unsafe { &(*(::std::ptr::null::<ImDrawList>()))._TextureIdStack as *const _ as usize },
112usize,
concat!(
"Offset of field: ",
stringify!(ImDrawList),
"::",
stringify!(_TextureIdStack)
)
);
assert_eq!(
unsafe { &(*(::std::ptr::null::<ImDrawList>()))._Path as *const _ as usize },
128usize,
concat!(
"Offset of field: ",
stringify!(ImDrawList),
"::",
stringify!(_Path)
)
);
assert_eq!(
unsafe { &(*(::std::ptr::null::<ImDrawList>()))._CmdHeader as *const _ as usize },
144usize,
concat!(
"Offset of field: ",
stringify!(ImDrawList),
"::",
stringify!(_CmdHeader)
)
);
assert_eq!(
unsafe { &(*(::std::ptr::null::<ImDrawList>()))._Splitter as *const _ as usize },
200usize,
concat!(
"Offset of field: ",
stringify!(ImDrawList),
"::",
stringify!(_Splitter)
)
);
}
#[repr(C)] #[repr(C)]
#[derive(Debug, Copy, Clone)] #[derive(Debug, Copy, Clone)]
pub struct ImPlotContext { pub struct ImPlotContext {
@ -1113,7 +270,7 @@ fn bindgen_test_layout_ImPlotLimits() {
); );
} }
#[repr(C)] #[repr(C)]
#[derive(Debug, Copy, Clone)] #[derive(Clone, Copy, Debug)]
pub struct ImPlotStyle { pub struct ImPlotStyle {
pub LineWeight: f32, pub LineWeight: f32,
pub Marker: ::std::os::raw::c_int, pub Marker: ::std::os::raw::c_int,
@ -1482,7 +639,7 @@ fn bindgen_test_layout_ImPlotStyle() {
); );
} }
#[repr(C)] #[repr(C)]
#[derive(Debug, Copy, Clone)] #[derive(Clone, Copy, Debug)]
pub struct ImPlotInputMap { pub struct ImPlotInputMap {
pub PanButton: ImGuiMouseButton, pub PanButton: ImGuiMouseButton,
pub PanMod: ImGuiKeyModFlags, 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" { extern "C" {
pub fn ImPlot_AnnotateClampedStr( pub fn ImPlot_AnnotateClampedStr(
x: f64, 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" { extern "C" {
pub fn ImPlot_DragLineX( pub fn ImPlot_DragLineX(
id: *const ::std::os::raw::c_char, id: *const ::std::os::raw::c_char,
@ -4666,65 +3785,3 @@ extern "C" {
offset: ::std::os::raw::c_int, 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)
)
);
}

View file

@ -36,6 +36,15 @@ impl From<(f64, f64)> for ImPlotRange {
} }
} }
impl From<ImVec2> for ImPlotRange {
fn from(from: ImVec2) -> Self {
ImPlotRange {
Min: from.x as f64,
Max: from.y as f64,
}
}
}
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use super::*; use super::*;

View file

@ -85,7 +85,7 @@ bitflags! {
/// let plotting_context = implot::Context::create(); /// let plotting_context = implot::Context::create();
/// let plot_ui = plotting_context.get_plot_ui(); /// let plot_ui = plotting_context.get_plot_ui();
/// implot::Plot::new("my title") /// 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, || { /// .build(&plot_ui, || {
/// // Do things such as plotting lines /// // Do things such as plotting lines
/// }); /// });
@ -419,11 +419,15 @@ impl Plot {
self.maybe_set_tick_labels(); self.maybe_set_tick_labels();
let should_render = unsafe { let should_render = unsafe {
let size_vec: ImVec2 = ImVec2 {
x: self.size[0],
y: self.size[1],
};
sys::ImPlot_BeginPlot( sys::ImPlot_BeginPlot(
self.title.as_ptr(), self.title.as_ptr(),
self.x_label.as_ptr(), self.x_label.as_ptr(),
self.y_label.as_ptr(), self.y_label.as_ptr(),
self.size.into(), size_vec,
self.plot_flags, self.plot_flags,
self.x_flags, self.x_flags,
self.y_flags[0], self.y_flags[0],