Restructured example code

This commit is contained in:
4bb4 2020-11-22 15:55:48 +01:00
parent 4cd199071c
commit 6233ef3f45
9 changed files with 104 additions and 141 deletions

View file

@ -1,7 +1,7 @@
//! This example demonstrates how bar plots are to be used. For more general //! This example demonstrates how bar plots are to be used. For more general
//! 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, Ui};
use implot::{Plot, PlotBars, PlotUi}; use implot::{Plot, PlotBars, PlotUi};
pub fn show_basic_vertical_plot(ui: &Ui, plot_ui: &PlotUi) { pub fn show_basic_vertical_plot(ui: &Ui, plot_ui: &PlotUi) {
@ -39,25 +39,11 @@ pub fn show_basic_horizontal_plot(ui: &Ui, plot_ui: &PlotUi) {
}); });
} }
pub fn show_demo_window(ui: &Ui, plot_ui: &PlotUi) { pub fn show_demo_headers(ui: &Ui, plot_ui: &PlotUi) {
Window::new(im_str!("Bar plots example")) if CollapsingHeader::new(im_str!("Bar plots: Basic vertical")).build(&ui) {
.size([430.0, 450.0], Condition::FirstUseEver)
.build(ui, || {
ui.text(im_str!("Hello from implot-rs!"));
ui.text_wrapped(im_str!(
"The headers here demo the bar plotting features of the library. \
Have a look at the example source code to see how they are implemented.\n\
Check out the demo from ImPlot itself first \
for instructions on how to interact with ImPlot plots."
));
// Show individual examples in collapsed headers
if CollapsingHeader::new(im_str!("Basic vertical plot")).build(&ui) {
show_basic_vertical_plot(&ui, &plot_ui); show_basic_vertical_plot(&ui, &plot_ui);
} }
if CollapsingHeader::new(im_str!("Bar plots: Basic horizontal")).build(&ui) {
if CollapsingHeader::new(im_str!("Basic horizontal plot")).build(&ui) {
show_basic_horizontal_plot(&ui, &plot_ui); show_basic_horizontal_plot(&ui, &plot_ui);
} }
});
} }

View file

@ -1,8 +1,8 @@
//! This example demonstrates how heatmaps are to be used. For more general //! This example demonstrates how heatmaps are to be used. For more general
//! 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, Ui};
use implot::{Plot, PlotHeatmap, PlotUi}; use implot::{ImPlotPoint, Plot, PlotHeatmap, PlotUi};
pub fn show_basic_heatmap(ui: &Ui, plot_ui: &PlotUi) { pub fn show_basic_heatmap(ui: &Ui, plot_ui: &PlotUi) {
ui.text(im_str!("This header shows a simple heatmap")); ui.text(im_str!("This header shows a simple heatmap"));
@ -16,25 +16,16 @@ pub fn show_basic_heatmap(ui: &Ui, plot_ui: &PlotUi) {
PlotHeatmap::new("my favourite heatmap") PlotHeatmap::new("my favourite heatmap")
// If you omit the with_scale call, the range will be computed based on the values // If you omit the with_scale call, the range will be computed based on the values
.with_scale(0.0, 10.0) .with_scale(0.0, 10.0)
.with_drawing_area(
ImPlotPoint { x: -1.0, y: -1.0 },
ImPlotPoint { x: 1.0, y: 1.0 },
)
.plot(&values, 10, 10); .plot(&values, 10, 10);
}); });
} }
pub fn show_demo_window(ui: &Ui, plot_ui: &PlotUi) { pub fn show_demo_headers(ui: &Ui, plot_ui: &PlotUi) {
Window::new(im_str!("Heatmaps example")) if CollapsingHeader::new(im_str!("Heatmap: Basic")).build(&ui) {
.size([430.0, 450.0], Condition::FirstUseEver)
.build(ui, || {
ui.text(im_str!("Hello from implot-rs!"));
ui.text_wrapped(im_str!(
"The headers here demo the heatmap plotting features of the library. \
Have a look at the example source code to see how they are implemented.\n\
Check out the demo from ImPlot itself first \
for instructions on how to interact with ImPlot plots."
));
// Show individual examples in collapsed headers
if CollapsingHeader::new(im_str!("Basic vertical plot")).build(&ui) {
show_basic_heatmap(&ui, &plot_ui); show_basic_heatmap(&ui, &plot_ui);
} }
});
} }

View file

@ -5,14 +5,43 @@ pub mod scatter_plots;
pub mod stairs_plots; pub mod stairs_plots;
pub mod text_plots; pub mod text_plots;
use imgui::Ui; use imgui::{im_str, Condition, Ui, Window};
use implot::PlotUi; use implot::PlotUi;
pub fn show_demos(ui: &Ui, plot_ui: &PlotUi) { pub fn show_demos(ui: &Ui, plot_ui: &PlotUi) {
bar_plots::show_demo_window(ui, plot_ui); Window::new(im_str!("implot-rs demo"))
line_plots::show_demo_window(ui, plot_ui); .size([430.0, 450.0], Condition::FirstUseEver)
scatter_plots::show_demo_window(ui, plot_ui); .build(ui, || {
text_plots::show_demo_window(ui, plot_ui); ui.text(im_str!("Hello from implot-rs!"));
stairs_plots::show_demo_window(ui, plot_ui); ui.text_wrapped(im_str!(
heatmaps::show_demo_window(ui, plot_ui); "The headers here demo the plotting features of the library.\
Have a look at the example source code to see how they are implemented.\n\
Check out the demo from ImPlot itself first for instructions on how to\
interact with ImPlot plots."
));
ui.separator();
ui.text(im_str!("Bar plots:"));
bar_plots::show_demo_headers(ui, plot_ui);
ui.separator();
ui.text(im_str!("Line plots:"));
line_plots::show_demo_headers(ui, plot_ui);
ui.separator();
ui.text(im_str!("Scatter plots:"));
scatter_plots::show_demo_headers(ui, plot_ui);
ui.separator();
ui.text(im_str!("Text plots:"));
text_plots::show_demo_headers(ui, plot_ui);
ui.separator();
ui.text(im_str!("Stairs plots:"));
stairs_plots::show_demo_headers(ui, plot_ui);
ui.separator();
ui.text(im_str!("Heatmaps:"));
heatmaps::show_demo_headers(ui, plot_ui);
});
} }

View file

@ -1,7 +1,7 @@
//! This example demonstrates how line plots are to be used, along with some querying features //! This example demonstrates how line plots are to be used, along with some querying features
//! that will be applicable to all kinds of plots. //! that will be applicable to all kinds of plots.
use imgui::{im_str, CollapsingHeader, Condition, Ui, Window}; use imgui::{im_str, CollapsingHeader, Condition, Ui};
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,
pixels_to_plot_vec2, plot_to_pixels_vec2, push_style_color, push_style_var_f32, pixels_to_plot_vec2, plot_to_pixels_vec2, push_style_color, push_style_var_f32,
@ -302,36 +302,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_demo_window(ui: &Ui, plot_ui: &PlotUi) { pub fn show_demo_headers(ui: &Ui, plot_ui: &PlotUi) {
Window::new(im_str!("Line plots example")) if CollapsingHeader::new(im_str!("Line plot: Basic")).build(&ui) {
.size([430.0, 450.0], Condition::FirstUseEver)
.build(ui, || {
ui.text(im_str!("Hello from implot-rs!"));
ui.text_wrapped(im_str!(
"The headers here demo the line plotting features of the library. \
Have a look at the example source code to see how they are implemented.\n\
Check out the demo from ImPlot itself first \
for instructions on how to interact with ImPlot plots."
));
// Show individual examples in collapsed headers
if CollapsingHeader::new(im_str!("Basic lineplot")).build(&ui) {
show_basic_plot(&ui, &plot_ui); show_basic_plot(&ui, &plot_ui);
} }
if CollapsingHeader::new(im_str!("Configurable lineplot")).build(&ui) { if CollapsingHeader::new(im_str!("Line plot: Configured")).build(&ui) {
show_configurable_plot(&ui, &plot_ui); show_configurable_plot(&ui, &plot_ui);
} }
if CollapsingHeader::new(im_str!("Querying a plot")).build(&ui) { if CollapsingHeader::new(im_str!("Line Plot: Plot queries")).build(&ui) {
show_query_features_plot(&ui, &plot_ui); show_query_features_plot(&ui, &plot_ui);
} }
if CollapsingHeader::new(im_str!("Styling a plot")).build(&ui) { if CollapsingHeader::new(im_str!("Line plot: Plot styling")).build(&ui) {
show_style_plot(&ui, &plot_ui); show_style_plot(&ui, &plot_ui);
} }
if CollapsingHeader::new(im_str!("Colormap selection")).build(&ui) { if CollapsingHeader::new(im_str!("Line plot: Colormaps")).build(&ui) {
show_colormaps_plot(&ui, &plot_ui); show_colormaps_plot(&ui, &plot_ui);
} }
if CollapsingHeader::new(im_str!("Multiple Y Axes")).build(&ui) { if CollapsingHeader::new(im_str!("Line plot: Multiple Y Axes")).build(&ui) {
show_two_yaxis_plot(&ui, &plot_ui); show_two_yaxis_plot(&ui, &plot_ui);
} }
});
} }

View file

@ -1,7 +1,7 @@
//! This example demonstrates how scatter plots are to be used. For more general //! This example demonstrates how scatter plots are to be used. For more general
//! 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, Ui};
use implot::{push_style_var_f32, push_style_var_i32, Marker, Plot, PlotScatter, PlotUi, StyleVar}; use implot::{push_style_var_f32, push_style_var_i32, Marker, Plot, PlotScatter, PlotUi, StyleVar};
pub fn show_basic_plot(ui: &Ui, plot_ui: &PlotUi) { pub fn show_basic_plot(ui: &Ui, plot_ui: &PlotUi) {
@ -52,19 +52,7 @@ pub fn show_custom_markers_plot(ui: &Ui, plot_ui: &PlotUi) {
}); });
} }
pub fn show_demo_window(ui: &Ui, plot_ui: &PlotUi) { pub fn show_demo_headers(ui: &Ui, plot_ui: &PlotUi) {
Window::new(im_str!("Scatter plots example"))
.size([430.0, 450.0], Condition::FirstUseEver)
.build(ui, || {
ui.text(im_str!("Hello from implot-rs!"));
ui.text_wrapped(im_str!(
"The headers here demo the scatter plotting features of the library. \
Have a look at the example source code to see how they are implemented.\n\
Check out the demo from ImPlot itself first \
for instructions on how to interact with ImPlot plots."
));
// Show individual examples in collapsed headers
if CollapsingHeader::new(im_str!("Basic scatter plot")).build(&ui) { if CollapsingHeader::new(im_str!("Basic scatter plot")).build(&ui) {
show_basic_plot(&ui, &plot_ui); show_basic_plot(&ui, &plot_ui);
} }
@ -72,5 +60,4 @@ pub fn show_demo_window(ui: &Ui, plot_ui: &PlotUi) {
if CollapsingHeader::new(im_str!("Custom markers")).build(&ui) { if CollapsingHeader::new(im_str!("Custom markers")).build(&ui) {
show_custom_markers_plot(&ui, &plot_ui); show_custom_markers_plot(&ui, &plot_ui);
} }
});
} }

View file

@ -1,7 +1,7 @@
//! This example demonstrates how stairs plots are to be used. They are almost the same as line //! This example demonstrates how stairs plots are to be used. They are almost the same as line
//! plots, so head over to the line plots example for more info. //! plots, so head over to the line plots example for more info.
//! //!
use imgui::{im_str, CollapsingHeader, Condition, Ui, Window}; use imgui::{im_str, CollapsingHeader, Ui};
use implot::{Plot, PlotStairs, PlotUi}; use implot::{Plot, PlotStairs, PlotUi};
pub fn show_basic_plot(ui: &Ui, plot_ui: &PlotUi) { pub fn show_basic_plot(ui: &Ui, plot_ui: &PlotUi) {
@ -21,20 +21,8 @@ pub fn show_basic_plot(ui: &Ui, plot_ui: &PlotUi) {
}); });
} }
pub fn show_demo_window(ui: &Ui, plot_ui: &PlotUi) { pub fn show_demo_headers(ui: &Ui, plot_ui: &PlotUi) {
Window::new(im_str!("Stairs plots example")) if CollapsingHeader::new(im_str!("Stairs plot: Basic")).build(&ui) {
.size([430.0, 450.0], Condition::FirstUseEver)
.build(ui, || {
ui.text(im_str!("Hello from implot-rs!"));
ui.text_wrapped(im_str!(
"The headers here demo the stairs plotting features of the library. \
Have a look at the example source code to see how they are implemented.\n\
Check out the demo from ImPlot itself first \
for instructions on how to interact with ImPlot plots."
));
if CollapsingHeader::new(im_str!("Basic stairs plot")).build(&ui) {
show_basic_plot(&ui, &plot_ui); show_basic_plot(&ui, &plot_ui);
} }
});
} }

View file

@ -1,7 +1,7 @@
//! This example demonstrates how the text plotting features are to be used. For more general //! This example demonstrates how the text plotting features are to be used. For more general
//! 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, Ui};
use implot::{Plot, PlotText, PlotUi}; use implot::{Plot, PlotText, PlotUi};
pub fn show_basic_plot(ui: &Ui, plot_ui: &PlotUi) { pub fn show_basic_plot(ui: &Ui, plot_ui: &PlotUi) {
@ -28,21 +28,8 @@ pub fn show_basic_plot(ui: &Ui, plot_ui: &PlotUi) {
}); });
} }
pub fn show_demo_window(ui: &Ui, plot_ui: &PlotUi) { pub fn show_demo_headers(ui: &Ui, plot_ui: &PlotUi) {
Window::new(im_str!("Text plots example")) if CollapsingHeader::new(im_str!("Text plot: Basic")).build(&ui) {
.size([430.0, 450.0], Condition::FirstUseEver)
.build(ui, || {
ui.text(im_str!("Hello from implot-rs!"));
ui.text_wrapped(im_str!(
"The headers here demo the text plotting features of the library. \
Have a look at the example source code to see how they are implemented.\n\
Check out the demo from ImPlot itself first \
for instructions on how to interact with ImPlot plots."
));
// Show individual examples in collapsed headers
if CollapsingHeader::new(im_str!("Basic text plot")).build(&ui) {
show_basic_plot(&ui, &plot_ui); show_basic_plot(&ui, &plot_ui);
} }
});
} }

View file

@ -2,7 +2,7 @@ use examples_shared;
use imgui::{im_str, Condition, Window}; use imgui::{im_str, Condition, Window};
use implot::Context; use implot::Context;
// the actual implot samples are in there TODO(4bb4) move to using examples-shared instead // The actual backend-specific code is in this.
mod support; mod support;
fn main() { fn main() {
@ -33,7 +33,11 @@ fn main() {
// TODO(4bb4) ... move windows by default so this is less confusing // TODO(4bb4) ... move windows by default so this is less confusing
ui.text_wrapped(im_str!( ui.text_wrapped(im_str!(
"Note that the windows are stacked, so move this one out of the way to see\ "Note that the windows are stacked, so move this one out of the way to see\
the ones beneath it." the ones beneath it. If you see something in the C++ demo window, but not\
in the Rust ImPlot demo window, that means the bindings are likely not \
implemented yet. Feel free to open an issue if you are missing something \
in particular.
"
)); ));
}); });
}); });

View file

@ -2,7 +2,7 @@ use examples_shared;
use imgui::{im_str, Condition, Window}; use imgui::{im_str, Condition, Window};
use implot::Context; use implot::Context;
// the actual implot samples are in there TODO(4bb4) move to using examples-shared instead // The actual backend-specific code is in this.
mod support; mod support;
fn main() { fn main() {
@ -33,7 +33,11 @@ fn main() {
// TODO(4bb4) ... move windows by default so this is less confusing // TODO(4bb4) ... move windows by default so this is less confusing
ui.text_wrapped(im_str!( ui.text_wrapped(im_str!(
"Note that the windows are stacked, so move this one out of the way to see\ "Note that the windows are stacked, so move this one out of the way to see\
the ones beneath it." the ones beneath it. If you see something in the C++ demo window, but not\
in the Rust ImPlot demo window, that means the bindings are likely not \
implemented yet. Feel free to open an issue if you are missing something \
in particular.
"
)); ));
}); });
}); });