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.
This commit is contained in:
parent
e0ad0e892e
commit
f85c50657b
8 changed files with 988 additions and 244 deletions
|
@ -2,7 +2,7 @@
|
||||||
//! features of the libray, see the line_plots example.
|
//! features of the libray, see the line_plots example.
|
||||||
|
|
||||||
use imgui::{im_str, CollapsingHeader, Condition, Ui, Window};
|
use imgui::{im_str, CollapsingHeader, Condition, Ui, Window};
|
||||||
use implot::{Plot, PlotBars};
|
use implot::{Context, Plot, PlotBars};
|
||||||
|
|
||||||
mod support;
|
mod support;
|
||||||
|
|
||||||
|
@ -44,6 +44,7 @@ fn show_basic_horizontal_plot(ui: &Ui) {
|
||||||
fn main() {
|
fn main() {
|
||||||
let system = support::init(file!());
|
let system = support::init(file!());
|
||||||
let mut showing_demo = false;
|
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| {
|
system.main_loop(move |_, ui| {
|
||||||
Window::new(im_str!("Bar plots example"))
|
Window::new(im_str!("Bar plots example"))
|
||||||
.size([430.0, 450.0], Condition::FirstUseEver)
|
.size([430.0, 450.0], Condition::FirstUseEver)
|
||||||
|
|
|
@ -4,9 +4,9 @@
|
||||||
use imgui::{im_str, CollapsingHeader, Condition, Ui, Window};
|
use imgui::{im_str, CollapsingHeader, Condition, Ui, Window};
|
||||||
use implot::{
|
use implot::{
|
||||||
get_plot_limits, get_plot_mouse_position, get_plot_query, is_plot_hovered, is_plot_queried,
|
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,
|
push_style_color, push_style_var_f32, push_style_var_i32, set_colormap_from_preset,
|
||||||
set_colormap_from_vec, AxisFlags, Colormap, ImPlotLimits, ImPlotPoint, ImPlotRange, ImVec4,
|
set_colormap_from_vec, AxisFlags, Colormap, Context, ImPlotLimits, ImPlotPoint, ImPlotRange,
|
||||||
Marker, Plot, PlotColorElement, PlotFlags, PlotLine, StyleVar,
|
ImVec4, Marker, Plot, PlotColorElement, PlotFlags, PlotLine, StyleVar,
|
||||||
};
|
};
|
||||||
|
|
||||||
mod support;
|
mod support;
|
||||||
|
@ -46,11 +46,11 @@ fn show_configurable_plot(ui: &Ui) {
|
||||||
let y_min = 1.0;
|
let y_min = 1.0;
|
||||||
let y_max = 2.0;
|
let y_max = 2.0;
|
||||||
// - Plot flags, see the PlotFlags docs for more info
|
// - 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,
|
// - 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
|
// so they support a bunch of convenient operations, see https://docs.rs/bitflags
|
||||||
let x_axis_flags = AxisFlags::DEFAULT;
|
let x_axis_flags = AxisFlags::NONE;
|
||||||
let y_axis_flags = AxisFlags::DEFAULT;
|
let y_axis_flags = AxisFlags::NONE;
|
||||||
|
|
||||||
// - Unlabelled X axis ticks
|
// - Unlabelled X axis ticks
|
||||||
let x_ticks = vec![2.2, 2.5, 2.8];
|
let x_ticks = vec![2.2, 2.5, 2.8];
|
||||||
|
@ -154,12 +154,12 @@ fn show_style_plot(ui: &Ui) {
|
||||||
},
|
},
|
||||||
Condition::Always,
|
Condition::Always,
|
||||||
)
|
)
|
||||||
.with_plot_flags(&(PlotFlags::DEFAULT))
|
.with_plot_flags(&(PlotFlags::NONE))
|
||||||
.with_y_axis_flags(&(AxisFlags::DEFAULT))
|
.with_y_axis_flags(&(AxisFlags::NONE))
|
||||||
.build(|| {
|
.build(|| {
|
||||||
// Markers can be selected as shown here. The markers are internally represented
|
// Markers can be selected as shown here. The markers are internally represented
|
||||||
// as an u32, hence this calling style.
|
// 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]);
|
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.
|
// Calling pop() on the return value of the push above will undo the marker choice.
|
||||||
markerchoice.pop();
|
markerchoice.pop();
|
||||||
|
@ -232,6 +232,7 @@ fn show_colormaps_plot(ui: &Ui) {
|
||||||
fn main() {
|
fn main() {
|
||||||
let system = support::init(file!());
|
let system = support::init(file!());
|
||||||
let mut showing_demo = false;
|
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| {
|
system.main_loop(move |_, ui| {
|
||||||
Window::new(im_str!("Line plots example"))
|
Window::new(im_str!("Line plots example"))
|
||||||
.size([430.0, 450.0], Condition::FirstUseEver)
|
.size([430.0, 450.0], Condition::FirstUseEver)
|
||||||
|
|
|
@ -2,7 +2,9 @@
|
||||||
//! features of the libray, see the line_plots example.
|
//! features of the libray, see the line_plots example.
|
||||||
|
|
||||||
use imgui::{im_str, CollapsingHeader, Condition, Ui, Window};
|
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;
|
mod support;
|
||||||
|
|
||||||
|
@ -28,7 +30,7 @@ fn show_custom_markers_plot(ui: &Ui) {
|
||||||
"This header shows how markers can be used in scatter plots."
|
"This header shows how markers can be used in scatter plots."
|
||||||
));
|
));
|
||||||
let content_width = ui.window_content_region_width();
|
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
|
// The size call could also be omitted, though the defaults don't consider window
|
||||||
// width, which is why we're not doing so here.
|
// width, which is why we're not doing so here.
|
||||||
.size(content_width, 300.0)
|
.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
|
// Change to cross marker for one scatter plot call
|
||||||
let x_positions = vec![0.1, 0.2, 0.1, 0.5, 0.9];
|
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 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);
|
PlotScatter::new("legend label 1").plot(&x_positions, &y_positions);
|
||||||
markerchoice.pop();
|
markerchoice.pop();
|
||||||
|
|
||||||
// One can combine things like marker size and markor choice
|
// One can combine things like marker size and markor choice
|
||||||
let x_positions = vec![0.4, 0.1];
|
let x_positions = vec![0.4, 0.1];
|
||||||
let y_positions = vec![0.5, 0.3];
|
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);
|
let marker_size = push_style_var_f32(&StyleVar::MarkerSize, 12.0);
|
||||||
PlotScatter::new("legend label 2").plot(&x_positions, &y_positions);
|
PlotScatter::new("legend label 2").plot(&x_positions, &y_positions);
|
||||||
|
|
||||||
|
@ -57,6 +59,7 @@ fn show_custom_markers_plot(ui: &Ui) {
|
||||||
fn main() {
|
fn main() {
|
||||||
let system = support::init(file!());
|
let system = support::init(file!());
|
||||||
let mut showing_demo = false;
|
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| {
|
system.main_loop(move |_, ui| {
|
||||||
Window::new(im_str!("Scatter plots example"))
|
Window::new(im_str!("Scatter plots example"))
|
||||||
.size([430.0, 450.0], Condition::FirstUseEver)
|
.size([430.0, 450.0], Condition::FirstUseEver)
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
//! features of the libray, see the line_plots example.
|
//! features of the libray, see the line_plots example.
|
||||||
|
|
||||||
use imgui::{im_str, CollapsingHeader, Condition, Ui, Window};
|
use imgui::{im_str, CollapsingHeader, Condition, Ui, Window};
|
||||||
use implot::{Plot, PlotText};
|
use implot::{Context, Plot, PlotText};
|
||||||
|
|
||||||
mod support;
|
mod support;
|
||||||
|
|
||||||
|
@ -33,6 +33,7 @@ fn show_basic_plot(ui: &Ui) {
|
||||||
fn main() {
|
fn main() {
|
||||||
let system = support::init(file!());
|
let system = support::init(file!());
|
||||||
let mut showing_demo = false;
|
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| {
|
system.main_loop(move |_, ui| {
|
||||||
Window::new(im_str!("Text plots example"))
|
Window::new(im_str!("Text plots example"))
|
||||||
.size([430.0, 450.0], Condition::FirstUseEver)
|
.size([430.0, 450.0], Condition::FirstUseEver)
|
||||||
|
|
|
@ -5,12 +5,15 @@
|
||||||
// for now, but expected to diverge from that over time.
|
// for now, but expected to diverge from that over time.
|
||||||
use std::{env, fs, io, path::Path};
|
use std::{env, fs, io, path::Path};
|
||||||
|
|
||||||
const CPP_FILES: [&str; 3] = [
|
const CPP_FILES: &[&str] = &[
|
||||||
"third-party/cimplot/cimplot.cpp",
|
"third-party/cimplot/cimplot.cpp",
|
||||||
"third-party/cimplot/implot/implot.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
|
"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<()> {
|
fn assert_file_exists(path: &str) -> io::Result<()> {
|
||||||
match fs::metadata(path) {
|
match fs::metadata(path) {
|
||||||
Ok(_) => Ok(()),
|
Ok(_) => Ok(()),
|
||||||
|
@ -46,10 +49,13 @@ fn main() -> io::Result<()> {
|
||||||
let imgui_include_path = Path::new(&cimgui_include_path).join("imgui");
|
let imgui_include_path = Path::new(&cimgui_include_path).join("imgui");
|
||||||
build.include(&cimgui_include_path);
|
build.include(&cimgui_include_path);
|
||||||
build.include(&imgui_include_path);
|
build.include(&imgui_include_path);
|
||||||
|
for path in IMPLOT_INCLUDE_DIRECTORIES {
|
||||||
|
build.include(path);
|
||||||
|
}
|
||||||
|
|
||||||
// Taken from the imgui-sys build as well
|
// Taken from the imgui-sys build as well
|
||||||
build.flag_if_supported("-Wno-return-type-c-linkage");
|
build.flag_if_supported("-Wno-return-type-c-linkage");
|
||||||
for path in &CPP_FILES {
|
for path in CPP_FILES {
|
||||||
assert_file_exists(path)?;
|
assert_file_exists(path)?;
|
||||||
build.file(path);
|
build.file(path);
|
||||||
}
|
}
|
||||||
|
|
903
implot-sys/src/bindings.rs
generated
903
implot-sys/src/bindings.rs
generated
File diff suppressed because it is too large
Load diff
2
implot-sys/third-party/cimplot
vendored
2
implot-sys/third-party/cimplot
vendored
|
@ -1 +1 @@
|
||||||
Subproject commit 929f61d27b8b4e3c899b2a386679a7f4a82826ce
|
Subproject commit 54ed676f42b7d96d6622f1c90df7d884246cc944
|
259
src/lib.rs
259
src/lib.rs
|
@ -9,11 +9,10 @@
|
||||||
//!
|
//!
|
||||||
pub extern crate implot_sys as sys;
|
pub extern crate implot_sys as sys;
|
||||||
use bitflags::bitflags;
|
use bitflags::bitflags;
|
||||||
use std::convert::TryFrom;
|
|
||||||
pub use sys::imgui::Condition;
|
pub use sys::imgui::Condition;
|
||||||
use sys::imgui::{im_str, ImString};
|
use sys::imgui::{im_str, ImString};
|
||||||
// TODO(4bb4) facade-wrap these
|
// 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_X: f32 = 400.0;
|
||||||
const DEFAULT_PLOT_SIZE_Y: 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.
|
// as enumerations in the traditional sense are plain enums.
|
||||||
|
|
||||||
bitflags! {
|
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)]
|
#[repr(transparent)]
|
||||||
pub struct PlotFlags: u32 {
|
pub struct PlotFlags: u32 {
|
||||||
/// The mouse position, in plot coordinates, will be displayed in the bottom-right
|
/// "Default" according to original docs
|
||||||
const MOUSE_POSITION = sys::ImPlotFlags__ImPlotFlags_MousePos;
|
const NONE = sys::ImPlotFlags__ImPlotFlags_None;
|
||||||
/// A legend will be displayed in the top-left
|
/// Plot items will not be highlighted when their legend entry is hovered
|
||||||
const LEGEND = sys::ImPlotFlags__ImPlotFlags_Legend;
|
const NO_LEGEND = sys::ImPlotFlags__ImPlotFlags_NoLegend;
|
||||||
/// Plot items will be highlighted when their legend entry is hovered
|
/// The user will not be able to open context menus with double-right click
|
||||||
const HIGHLIGHT = sys::ImPlotFlags__ImPlotFlags_Highlight;
|
const NO_MENUS = sys::ImPlotFlags__ImPlotFlags_NoMenus;
|
||||||
/// The user will be able to box-select with right-mouse
|
/// The user will not be able to box-select with right-mouse
|
||||||
const BOX_SELECT = sys::ImPlotFlags__ImPlotFlags_BoxSelect;
|
const NO_BOX_SELECT = sys::ImPlotFlags__ImPlotFlags_NoBoxSelect;
|
||||||
/// The user will be able to draw query rects with middle-mouse
|
/// The mouse position, in plot coordinates, will not be displayed
|
||||||
const QUERY = sys::ImPlotFlags__ImPlotFlags_Query;
|
const NO_MOUSE_POSITION = sys::ImPlotFlags__ImPlotFlags_NoMousePos;
|
||||||
/// The user will be able to open a context menu with double-right click
|
/// Plot items will not be highlighted when their legend entry is hovered
|
||||||
const CONTEXT_MENU = sys::ImPlotFlags__ImPlotFlags_ContextMenu;
|
const NO_HIGHLIGHT = sys::ImPlotFlags__ImPlotFlags_NoHighlight;
|
||||||
/// 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;
|
|
||||||
/// A child window region will not be used to capture mouse scroll (can boost performance
|
/// A child window region will not be used to capture mouse scroll (can boost performance
|
||||||
/// for single ImGui window applications)
|
/// for single ImGui window applications)
|
||||||
const NO_CHILD = sys::ImPlotFlags__ImPlotFlags_NoChild;
|
const NO_CHILD = sys::ImPlotFlags__ImPlotFlags_NoChild;
|
||||||
|
@ -51,67 +46,68 @@ bitflags! {
|
||||||
const Y_AXIS_2 = sys::ImPlotFlags__ImPlotFlags_YAxis2;
|
const Y_AXIS_2 = sys::ImPlotFlags__ImPlotFlags_YAxis2;
|
||||||
/// Enable a 3nd y axis
|
/// Enable a 3nd y axis
|
||||||
const Y_AXIS_3 = sys::ImPlotFlags__ImPlotFlags_YAxis3;
|
const Y_AXIS_3 = sys::ImPlotFlags__ImPlotFlags_YAxis3;
|
||||||
/// Default selection of flags
|
/// The user will be able to draw query rects with middle-mouse
|
||||||
const DEFAULT = sys::ImPlotFlags__ImPlotFlags_Default;
|
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! {
|
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)]
|
#[repr(transparent)]
|
||||||
pub struct AxisFlags: u32 {
|
pub struct AxisFlags: u32 {
|
||||||
/// Grid lines will be displayed
|
/// "Default" according to original docs
|
||||||
const GRID_LINES = sys::ImPlotAxisFlags__ImPlotAxisFlags_GridLines;
|
const NONE = sys::ImPlotAxisFlags__ImPlotAxisFlags_None;
|
||||||
/// Tick marks will be displayed for each grid line
|
/// Grid lines will not be displayed
|
||||||
const TICK_MARKS = sys::ImPlotAxisFlags__ImPlotAxisFlags_TickMarks;
|
const NO_GRID_LINES = sys::ImPlotAxisFlags__ImPlotAxisFlags_NoGridLines;
|
||||||
/// Text labels will be displayed for each grid line
|
/// Tick marks will not be displayed
|
||||||
const TICK_LABELS = sys::ImPlotAxisFlags__ImPlotAxisFlags_TickLabels;
|
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
|
/// The axis will be inverted
|
||||||
const INVERT = sys::ImPlotAxisFlags__ImPlotAxisFlags_Invert;
|
const INVERT = sys::ImPlotAxisFlags__ImPlotAxisFlags_Invert;
|
||||||
/// The axis minimum value will be locked when panning/zooming
|
/// The axis minimum value will be locked when panning/zooming
|
||||||
const LOCK_MIN = sys::ImPlotAxisFlags__ImPlotAxisFlags_LockMin;
|
const LOCK_MIN = sys::ImPlotAxisFlags__ImPlotAxisFlags_LockMin;
|
||||||
/// The axis maximum value will be locked when panning/zooming
|
/// The axis maximum value will be locked when panning/zooming
|
||||||
const LOCK_MAX = sys::ImPlotAxisFlags__ImPlotAxisFlags_LockMax;
|
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! {
|
/// Markers, documentation copied from implot.h for convenience.
|
||||||
/// Axis flags. Documentation copied from implot.h for convenience.
|
#[repr(i32)]
|
||||||
#[repr(transparent)]
|
#[derive(Copy, Clone, Debug)]
|
||||||
pub struct Marker: u32 {
|
pub enum Marker {
|
||||||
/// no marker
|
/// no marker
|
||||||
const NONE = sys::ImPlotMarker__ImPlotMarker_None;
|
None = sys::ImPlotMarker__ImPlotMarker_None,
|
||||||
/// a circle marker will be rendered at each point
|
/// a circle marker will be rendered at each point
|
||||||
const CIRCLE = sys::ImPlotMarker__ImPlotMarker_Circle;
|
Circle = sys::ImPlotMarker__ImPlotMarker_Circle,
|
||||||
/// a square maker will be rendered at each point
|
/// a square maker will be rendered at each point
|
||||||
const SQUARE = sys::ImPlotMarker__ImPlotMarker_Square;
|
Square = sys::ImPlotMarker__ImPlotMarker_Square,
|
||||||
/// a diamond marker will be rendered at each point
|
/// a diamond marker will be rendered at each point
|
||||||
const DIAMOND = sys::ImPlotMarker__ImPlotMarker_Diamond;
|
Diamond = sys::ImPlotMarker__ImPlotMarker_Diamond,
|
||||||
/// an upward-pointing triangle marker will up rendered at each point
|
/// an upward-pointing triangle marker will up rendered at each point
|
||||||
const UP = sys::ImPlotMarker__ImPlotMarker_Up;
|
Up = sys::ImPlotMarker__ImPlotMarker_Up,
|
||||||
/// an downward-pointing triangle marker will up rendered at each point
|
/// an downward-pointing triangle marker will up rendered at each point
|
||||||
const DOWN = sys::ImPlotMarker__ImPlotMarker_Down;
|
Down = sys::ImPlotMarker__ImPlotMarker_Down,
|
||||||
/// an leftward-pointing triangle marker will up rendered at each point
|
/// an leftward-pointing triangle marker will up rendered at each point
|
||||||
const LEFT = sys::ImPlotMarker__ImPlotMarker_Left;
|
Left = sys::ImPlotMarker__ImPlotMarker_Left,
|
||||||
/// an rightward-pointing triangle marker will up rendered at each point
|
/// an rightward-pointing triangle marker will up rendered at each point
|
||||||
const RIGHT = sys::ImPlotMarker__ImPlotMarker_Right;
|
Right = sys::ImPlotMarker__ImPlotMarker_Right,
|
||||||
/// a cross marker will be rendered at each point (not filled)
|
/// a cross marker will be rendered at each point (not filled)
|
||||||
const CROSS = sys::ImPlotMarker__ImPlotMarker_Cross;
|
Cross = sys::ImPlotMarker__ImPlotMarker_Cross,
|
||||||
/// a plus marker will be rendered at each point (not filled)
|
/// a plus marker will be rendered at each point (not filled)
|
||||||
const PLUS = sys::ImPlotMarker__ImPlotMarker_Plus;
|
Plus = sys::ImPlotMarker__ImPlotMarker_Plus,
|
||||||
/// a asterisk marker will be rendered at each point (not filled)
|
/// a asterisk marker will be rendered at each point (not filled)
|
||||||
const ASTERISK = sys::ImPlotMarker__ImPlotMarker_Asterisk;
|
Asterisk = sys::ImPlotMarker__ImPlotMarker_Asterisk,
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Colorable plot elements. These are called "ImPlotCol" in ImPlot itself, but I found that
|
/// 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,
|
PlotBg = sys::ImPlotCol__ImPlotCol_PlotBg,
|
||||||
/// Plot area border color (defaults to text color)
|
/// Plot area border color (defaults to text color)
|
||||||
PlotBorder = sys::ImPlotCol__ImPlotCol_PlotBorder,
|
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,
|
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,
|
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,
|
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,
|
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)
|
/// Box-selection color (defaults to yellow)
|
||||||
Selection = sys::ImPlotCol__ImPlotCol_Selection,
|
Selection = sys::ImPlotCol__ImPlotCol_Selection,
|
||||||
|
/// crosshairs color (defaults to ImPlotCol_PlotBorder)
|
||||||
|
Crosshairs = sys::ImPlotCol__ImPlotCol_Crosshairs,
|
||||||
/// Box-query color (defaults to green)
|
/// Box-query color (defaults to green)
|
||||||
Query = sys::ImPlotCol__ImPlotCol_Query,
|
Query = sys::ImPlotCol__ImPlotCol_Query,
|
||||||
}
|
}
|
||||||
|
@ -156,6 +172,8 @@ pub enum PlotColorElement {
|
||||||
pub enum Colormap {
|
pub enum Colormap {
|
||||||
/// ImPlot default colormap (n=10). Called "Standard" here because Default is reserved.
|
/// ImPlot default colormap (n=10). Called "Standard" here because Default is reserved.
|
||||||
Standard = sys::ImPlotColormap__ImPlotColormap_Default,
|
Standard = sys::ImPlotColormap__ImPlotColormap_Default,
|
||||||
|
/// a.k.a. seaborn deep (n=10)
|
||||||
|
Deep = sys::ImPlotColormap__ImPlotColormap_Deep,
|
||||||
/// a.k.a. matplotlib "Set1" (n=9)
|
/// a.k.a. matplotlib "Set1" (n=9)
|
||||||
Dark = sys::ImPlotColormap__ImPlotColormap_Dark,
|
Dark = sys::ImPlotColormap__ImPlotColormap_Dark,
|
||||||
/// a.k.a. matplotlib "Pastel1" (n=9)
|
/// a.k.a. matplotlib "Pastel1" (n=9)
|
||||||
|
@ -187,6 +205,8 @@ pub enum StyleVar {
|
||||||
MarkerSize = sys::ImPlotStyleVar__ImPlotStyleVar_MarkerSize,
|
MarkerSize = sys::ImPlotStyleVar__ImPlotStyleVar_MarkerSize,
|
||||||
/// f32, outline weight of markers in pixels
|
/// f32, outline weight of markers in pixels
|
||||||
MarkerWeight = sys::ImPlotStyleVar__ImPlotStyleVar_MarkerWeight,
|
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
|
/// f32, error bar whisker width in pixels
|
||||||
ErrorBarSize = sys::ImPlotStyleVar__ImPlotStyleVar_ErrorBarSize,
|
ErrorBarSize = sys::ImPlotStyleVar__ImPlotStyleVar_ErrorBarSize,
|
||||||
/// f32, error bar whisker weight in pixels
|
/// f32, error bar whisker weight in pixels
|
||||||
|
@ -195,6 +215,64 @@ pub enum StyleVar {
|
||||||
DigitalBitHeight = sys::ImPlotStyleVar__ImPlotStyleVar_DigitalBitHeight,
|
DigitalBitHeight = sys::ImPlotStyleVar__ImPlotStyleVar_DigitalBitHeight,
|
||||||
/// f32, digital channels bit padding gap in pixels
|
/// f32, digital channels bit padding gap in pixels
|
||||||
DigitalBitGap = sys::ImPlotStyleVar__ImPlotStyleVar_DigitalBitGap,
|
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 -----------------------------------------------------------------------
|
// --- Main plot structure -----------------------------------------------------------------------
|
||||||
|
@ -287,11 +365,11 @@ impl Plot {
|
||||||
y_tick_positions: None,
|
y_tick_positions: None,
|
||||||
y_tick_labels: None,
|
y_tick_labels: None,
|
||||||
show_y_default_ticks: false,
|
show_y_default_ticks: false,
|
||||||
plot_flags: PlotFlags::DEFAULT.bits() as sys::ImPlotFlags,
|
plot_flags: PlotFlags::NONE.bits() as sys::ImPlotFlags,
|
||||||
x_flags: AxisFlags::DEFAULT.bits() as sys::ImPlotAxisFlags,
|
x_flags: AxisFlags::NONE.bits() as sys::ImPlotAxisFlags,
|
||||||
y_flags: AxisFlags::DEFAULT.bits() as sys::ImPlotAxisFlags,
|
y_flags: AxisFlags::NONE.bits() as sys::ImPlotAxisFlags,
|
||||||
y2_flags: AxisFlags::DEFAULT.bits() as sys::ImPlotAxisFlags,
|
y2_flags: AxisFlags::NONE.bits() as sys::ImPlotAxisFlags,
|
||||||
y3_flags: AxisFlags::DEFAULT.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 }
|
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
|
/// at the moment, for that, use something like
|
||||||
/// ```no_run
|
/// ```no_run
|
||||||
/// # use implot::{push_style_var_u32, StyleVar, Marker};
|
/// # use implot::{push_style_var_i32, StyleVar, Marker};
|
||||||
/// let markerchoice = push_style_var_u32(&StyleVar::Marker, Marker::CROSS.bits());
|
/// let markerchoice = push_style_var_i32(&StyleVar::Marker, Marker::Cross as i32);
|
||||||
/// // plot things
|
/// // plot things
|
||||||
/// markerchoice.pop()
|
/// markerchoice.pop()
|
||||||
/// ```
|
/// ```
|
||||||
pub fn push_style_var_u32(element: &StyleVar, value: u32) -> StyleVarToken {
|
pub fn push_style_var_i32(element: &StyleVar, value: i32) -> 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");
|
|
||||||
unsafe {
|
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 }
|
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
|
/// pertains to whatever Y axis was most recently selected. TODO(4bb4) add y axis selection
|
||||||
pub fn get_plot_mouse_position() -> ImPlotPoint {
|
pub fn get_plot_mouse_position() -> ImPlotPoint {
|
||||||
let y_axis_selection = 0;
|
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
|
/// 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
|
/// most recently selected. TODO(4bb4) add y axis selection
|
||||||
pub fn get_plot_limits() -> ImPlotLimits {
|
pub fn get_plot_limits() -> ImPlotLimits {
|
||||||
let y_axis_selection = 0;
|
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
|
/// 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
|
/// axis was most recently selected. TODO(4bb4) add y axis selection
|
||||||
pub fn get_plot_query() -> ImPlotLimits {
|
pub fn get_plot_query() -> ImPlotLimits {
|
||||||
let y_axis_selection = 0;
|
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 -------------------------------------------------------------------------------
|
// --- Demo window -------------------------------------------------------------------------------
|
||||||
|
|
Loading…
Reference in a new issue