Reworked glium demo to use the shared example code

This commit is contained in:
4bb4 2020-10-30 12:42:14 +01:00
parent 8c623a7a79
commit 40f0cc8564
12 changed files with 118 additions and 569 deletions

View file

@ -1,7 +1,7 @@
//! This example demonstrates how bar plots are to be used. For more general
//! features of the libray, see the line_plots example.
use imgui::{im_str, Ui};
use imgui::{im_str, CollapsingHeader, Condition, Ui, Window};
use implot::{Plot, PlotBars, PlotUi};
pub fn show_basic_vertical_plot(ui: &Ui, plot_ui: &PlotUi) {
@ -38,3 +38,26 @@ pub fn show_basic_horizontal_plot(ui: &Ui, plot_ui: &PlotUi) {
.plot(&axis_positions, &values);
});
}
pub fn show_demo_window(ui: &Ui, plot_ui: &PlotUi) {
Window::new(im_str!("Bar 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 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);
}
if CollapsingHeader::new(im_str!("Basic horizontal plot")).build(&ui) {
show_basic_horizontal_plot(&ui, &plot_ui);
}
});
}

View file

@ -2,3 +2,13 @@ pub mod bar_plots;
pub mod line_plots;
pub mod scatter_plots;
pub mod text_plots;
use imgui::Ui;
use implot::PlotUi;
pub fn show_demos(ui: &Ui, plot_ui: &PlotUi) {
bar_plots::show_demo_window(ui, plot_ui);
line_plots::show_demo_window(ui, plot_ui);
scatter_plots::show_demo_window(ui, plot_ui);
text_plots::show_demo_window(ui, plot_ui);
}

View file

@ -1,7 +1,7 @@
//! This example demonstrates how line plots are to be used, along with some querying features
//! that will be applicable to all kinds of plots.
use imgui::{im_str, Condition, Ui};
use imgui::{im_str, CollapsingHeader, Condition, Ui, Window};
use implot::{
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_i32, set_colormap_from_preset,
@ -268,3 +268,37 @@ pub fn show_colormaps_plot(ui: &Ui, plot_ui: &PlotUi) {
// We can reset to the default by just setting the "Standard" preset.
set_colormap_from_preset(Colormap::Standard, 0);
}
pub fn show_demo_window(ui: &Ui, plot_ui: &PlotUi) {
Window::new(im_str!("Line 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 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);
}
if CollapsingHeader::new(im_str!("Configurable lineplot")).build(&ui) {
show_configurable_plot(&ui, &plot_ui);
}
if CollapsingHeader::new(im_str!("Querying a plot")).build(&ui) {
show_query_features_plot(&ui, &plot_ui);
}
if CollapsingHeader::new(im_str!("Styling a plot")).build(&ui) {
show_style_plot(&ui, &plot_ui);
}
if CollapsingHeader::new(im_str!("Colormap selection")).build(&ui) {
show_colormaps_plot(&ui, &plot_ui);
}
if CollapsingHeader::new(im_str!("Multiple Y Axes")).build(&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
//! features of the libray, see the line_plots example.
use imgui::{im_str, Ui};
use imgui::{im_str, CollapsingHeader, Condition, Ui, Window};
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) {
@ -51,3 +51,26 @@ pub fn show_custom_markers_plot(ui: &Ui, plot_ui: &PlotUi) {
marker_choice.pop();
});
}
pub fn show_demo_window(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) {
show_basic_plot(&ui, &plot_ui);
}
if CollapsingHeader::new(im_str!("Custom markers")).build(&ui) {
show_custom_markers_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
//! features of the libray, see the line_plots example.
use imgui::{im_str, Ui};
use imgui::{im_str, CollapsingHeader, Condition, Ui, Window};
use implot::{Plot, PlotText, PlotUi};
pub fn show_basic_plot(ui: &Ui, plot_ui: &PlotUi) {
@ -27,3 +27,22 @@ pub fn show_basic_plot(ui: &Ui, plot_ui: &PlotUi) {
PlotText::new("vertical displayed text").plot(x_position, y_position, vertical);
});
}
pub fn show_demo_window(ui: &Ui, plot_ui: &PlotUi) {
Window::new(im_str!("Text 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 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);
}
});
}