2020-08-30 09:01:28 +00:00
|
|
|
// This is a somewhat messy example that currently just gets used to test out functionality as it
|
|
|
|
// is built. It will be taken apart into separate examples with clearer demo purposes later.
|
|
|
|
|
2020-08-01 16:28:17 +00:00
|
|
|
use imgui::*;
|
2020-08-23 19:26:27 +00:00
|
|
|
use implot::{
|
2020-08-30 09:01:28 +00:00
|
|
|
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,
|
2020-08-23 19:26:27 +00:00
|
|
|
};
|
|
|
|
use implot::{
|
2020-08-30 09:01:28 +00:00
|
|
|
AxisFlags, ImPlotLimits, ImPlotPoint, ImPlotRange, Marker, Plot, PlotColorElement, PlotFlags,
|
|
|
|
PlotLine, PlotText, StyleVar,
|
2020-08-23 19:26:27 +00:00
|
|
|
};
|
2020-08-01 16:28:17 +00:00
|
|
|
|
|
|
|
mod support;
|
|
|
|
|
|
|
|
fn main() {
|
|
|
|
let system = support::init(file!());
|
2020-08-08 12:42:22 +00:00
|
|
|
let mut showing_demo = false;
|
2020-08-01 16:28:17 +00:00
|
|
|
system.main_loop(move |_, ui| {
|
2020-08-08 12:42:22 +00:00
|
|
|
// Create the window from time imgui example, just... with an added plot
|
2020-08-01 16:28:17 +00:00
|
|
|
Window::new(im_str!("Hello world"))
|
2020-08-08 12:42:22 +00:00
|
|
|
.size([430.0, 450.0], Condition::FirstUseEver)
|
2020-08-01 16:28:17 +00:00
|
|
|
.build(ui, || {
|
2020-08-08 12:42:22 +00:00
|
|
|
ui.text(im_str!("Hello from implot-rs!"));
|
2020-08-01 16:28:17 +00:00
|
|
|
ui.separator();
|
|
|
|
let mouse_pos = ui.io().mouse_pos;
|
|
|
|
ui.text(format!(
|
|
|
|
"Mouse Position: ({:.1},{:.1})",
|
|
|
|
mouse_pos[0], mouse_pos[1]
|
|
|
|
));
|
2020-08-08 12:42:22 +00:00
|
|
|
ui.checkbox(im_str!("Show demo"), &mut showing_demo);
|
2020-08-01 16:28:17 +00:00
|
|
|
|
2020-08-23 19:26:27 +00:00
|
|
|
// Create some containers for exfiltrating data from the closure below
|
|
|
|
let mut hover_pos: Option<ImPlotPoint> = None;
|
|
|
|
let mut plot_limits: Option<ImPlotLimits> = None;
|
2020-08-30 09:01:28 +00:00
|
|
|
let mut query_limits: Option<ImPlotLimits> = None;
|
2020-08-23 19:26:27 +00:00
|
|
|
|
2020-08-08 12:42:22 +00:00
|
|
|
// Draw a plot
|
2020-08-30 09:01:28 +00:00
|
|
|
let style = push_style_color(&PlotColorElement::PlotBg, 1.0, 1.0, 1.0, 0.2);
|
2020-08-08 13:40:04 +00:00
|
|
|
Plot::new("Demo plot")
|
2020-08-08 12:42:22 +00:00
|
|
|
.size(400.0, 300.0)
|
|
|
|
.x_label("awesome x label")
|
|
|
|
.y_label("awesome y label")
|
2020-08-23 19:26:27 +00:00
|
|
|
.x_limits(&ImPlotRange { Min: 0.0, Max: 6.0 }, Condition::FirstUseEver)
|
|
|
|
.y_limits(
|
|
|
|
&ImPlotRange {
|
|
|
|
Min: -1.0,
|
|
|
|
Max: 3.0,
|
|
|
|
},
|
|
|
|
Condition::FirstUseEver,
|
|
|
|
)
|
2020-08-23 18:10:24 +00:00
|
|
|
.with_plot_flags(&(PlotFlags::DEFAULT))
|
2020-08-23 18:31:28 +00:00
|
|
|
.with_y_axis_flags(&(AxisFlags::DEFAULT | AxisFlags::INVERT))
|
2020-08-08 12:42:22 +00:00
|
|
|
.build(|| {
|
2020-08-23 18:31:28 +00:00
|
|
|
// Line plotting
|
2020-08-30 09:01:28 +00:00
|
|
|
let markerchoice =
|
|
|
|
push_style_var_u32(&StyleVar::Marker, Marker::CROSS.bits());
|
2020-08-08 13:40:04 +00:00
|
|
|
PlotLine::new("Left eye").plot(&vec![2.0, 2.0], &vec![2.0, 1.0]);
|
2020-08-30 09:01:28 +00:00
|
|
|
markerchoice.pop();
|
|
|
|
|
|
|
|
let lineweight = push_style_var_f32(&StyleVar::LineWeight, 5.0);
|
2020-08-08 13:40:04 +00:00
|
|
|
PlotLine::new("Right eye").plot(&vec![4.0, 4.0], &vec![2.0, 1.0]);
|
2020-08-30 09:01:28 +00:00
|
|
|
lineweight.pop();
|
|
|
|
|
2020-08-08 12:42:22 +00:00
|
|
|
let x_values = vec![1.0, 2.0, 4.0, 5.0];
|
|
|
|
let y_values = vec![1.0, 0.0, 0.0, 1.0];
|
2020-08-08 13:40:04 +00:00
|
|
|
PlotLine::new("Mouth").plot(&x_values, &y_values);
|
2020-08-23 18:31:28 +00:00
|
|
|
|
|
|
|
// Text
|
|
|
|
PlotText::new("Text!").plot(2.0, 2.0, false);
|
|
|
|
PlotText::new("Text with offset!")
|
|
|
|
.with_pixel_offset(10.0, 30.0)
|
|
|
|
.plot(2.0, 2.0, false);
|
|
|
|
PlotText::new("Vertical Text!").plot(0.1, 2.5, true);
|
2020-08-23 19:26:27 +00:00
|
|
|
if is_plot_hovered() {
|
|
|
|
hover_pos = Some(get_plot_mouse_position());
|
|
|
|
}
|
2020-08-30 09:01:28 +00:00
|
|
|
|
|
|
|
if is_plot_queried() {
|
|
|
|
query_limits = Some(get_plot_query());
|
|
|
|
}
|
2020-08-23 19:26:27 +00:00
|
|
|
plot_limits = Some(get_plot_limits());
|
2020-08-08 12:42:22 +00:00
|
|
|
});
|
2020-08-23 19:26:27 +00:00
|
|
|
|
|
|
|
// Print some previously-exfiltrated info. This is because calling
|
|
|
|
// things like is_plot_hovered or get_plot_mouse_position() outside
|
|
|
|
// of an actual Plot is not allowed.
|
|
|
|
if let Some(pos) = hover_pos {
|
|
|
|
ui.text(im_str!("hovered at {}, {}", pos.x, pos.y));
|
|
|
|
}
|
|
|
|
if let Some(limits) = plot_limits {
|
2020-08-30 09:01:28 +00:00
|
|
|
ui.text(im_str!("Plot limits are {:#?}", limits));
|
|
|
|
}
|
|
|
|
if let Some(query) = query_limits {
|
|
|
|
ui.text(im_str!("Query limits are {:#?}", query));
|
2020-08-23 19:26:27 +00:00
|
|
|
}
|
2020-08-30 09:01:28 +00:00
|
|
|
style.pop();
|
2020-08-01 16:28:17 +00:00
|
|
|
});
|
2020-08-08 12:42:22 +00:00
|
|
|
|
|
|
|
if showing_demo {
|
|
|
|
implot::show_demo_window(&mut showing_demo);
|
|
|
|
}
|
2020-08-01 16:28:17 +00:00
|
|
|
});
|
|
|
|
}
|