implot-rs/implot-examples/examples-shared/src/lib.rs

79 lines
2.5 KiB
Rust
Raw Normal View History

pub mod bar_plots;
pub mod heatmaps;
pub mod line_plots;
pub mod scatter_plots;
2020-11-08 18:41:51 +00:00
pub mod stairs_plots;
mod stem_plots;
pub mod text_plots;
2021-10-03 10:26:08 +00:00
use imgui::{Condition, Ui, Window};
use implot::PlotUi;
/// State of the demo code
pub struct DemoState {
/// State of the line plots demo
line_plots: line_plots::LinePlotDemoState,
}
impl DemoState {
/// Create a new demo code state object with default values in it.
pub fn new() -> Self {
Self {
line_plots: line_plots::LinePlotDemoState::new(),
}
}
/// Show all the demos
pub fn show_demos(&mut self, ui: &Ui, plot_ui: &PlotUi) {
// Most of the demos are currently still stateless, so the code here mostly just calls into
// the modules. The line plots demo is stateful though. Things will be refactored soon to
// make all the individual demos stateful to unify things more.
2021-10-03 10:26:08 +00:00
Window::new("implot-rs demo")
.size([430.0, 450.0], Condition::FirstUseEver)
.build(ui, || {
2021-10-03 10:26:08 +00:00
ui.text("Hello from implot-rs!");
ui.text_wrapped(
"The headers here demo the plotting features of the library.\
2020-11-22 14:55:48 +00:00
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\
2021-10-03 10:26:08 +00:00
interact with ImPlot plots.",
);
2020-11-22 14:55:48 +00:00
ui.separator();
2021-10-03 10:26:08 +00:00
ui.text("Bar plots:");
bar_plots::show_demo_headers(ui, plot_ui);
2020-11-22 14:55:48 +00:00
ui.separator();
2021-10-03 10:26:08 +00:00
ui.text("Line plots:");
// The line plots demo is stateful
self.line_plots.show_demo_headers(ui, plot_ui);
2020-11-22 14:55:48 +00:00
ui.separator();
2021-10-03 10:26:08 +00:00
ui.text("Scatter plots:");
scatter_plots::show_demo_headers(ui, plot_ui);
2020-11-22 14:55:48 +00:00
ui.separator();
2021-10-03 10:26:08 +00:00
ui.text("Text plots:");
text_plots::show_demo_headers(ui, plot_ui);
2020-11-22 14:55:48 +00:00
ui.separator();
2021-10-03 10:26:08 +00:00
ui.text("Stairs plots:");
stairs_plots::show_demo_headers(ui, plot_ui);
2020-11-22 14:55:48 +00:00
ui.separator();
2021-10-03 10:26:08 +00:00
ui.text("Heatmaps:");
heatmaps::show_demo_headers(ui, plot_ui);
ui.separator();
2021-10-03 10:26:08 +00:00
ui.text("Stem plots:");
stem_plots::show_demo_headers(ui, plot_ui);
});
}
}
2021-10-03 10:26:08 +00:00
impl Default for DemoState {
fn default() -> Self {
Self::new()
}
}