Refactored Plot building, various example updates

This commit is contained in:
4bb4 2020-08-08 14:42:22 +02:00
parent 7d09c30892
commit b832924fad
5 changed files with 114 additions and 42 deletions

View file

@ -1,11 +1,11 @@
[package]
name = "imgui-examples"
name = "implot-examples"
version = "0.0.0"
edition = "2018"
authors = ["Joonas Javanainen <joonas.javanainen@gmail.com>", "imgui-rs contributors"]
description = "imgui crate examples using Glium backend"
homepage = "https://github.com/Gekkio/imgui-rs"
repository = "https://github.com/Gekkio/imgui-rs"
authors = ["Sandro Merkli", "implot-rs contributors"]
description = "implot examples, with backend code from the imgui examples in imgui-examples"
homepage = "https://github.com/4bb4/implot-rs"
repository = "https://github.com/4bb4/implot-rs"
license = "MIT/Apache-2.0"
publish = false

View file

@ -5,30 +5,38 @@ mod support;
fn main() {
let system = support::init(file!());
let mut showing_demo = false;
system.main_loop(move |_, ui| {
// Create the window from time imgui example, just... with an added plot
Window::new(im_str!("Hello world"))
.size([300.0, 110.0], Condition::FirstUseEver)
.size([430.0, 450.0], Condition::FirstUseEver)
.build(ui, || {
ui.text(im_str!("Hello world!"));
ui.text(im_str!("こんにちは世界!"));
ui.text(im_str!("This...is...imgui-rs!"));
ui.text(im_str!("Hello from implot-rs!"));
ui.separator();
let mouse_pos = ui.io().mouse_pos;
ui.text(format!(
"Mouse Position: ({:.1},{:.1})",
mouse_pos[0], mouse_pos[1]
));
ui.checkbox(im_str!("Show demo"), &mut showing_demo);
// Demo some implot stuff :D
let x_values = vec![1.0, 2.0, 4.0, 5.0];
let y_values = vec![1.0, 0.0, 0.0, 1.0];
let plot = implot::Plot::new();
if plot.begin() {
implot::plot_line(&vec![2.0, 2.0], &vec![2.0, 1.0], "Left eye");
implot::plot_line(&vec![4.0, 4.0], &vec![2.0, 1.0], "Right eye");
implot::plot_line(&x_values, &y_values, "Mouth");
plot.end();
}
// Draw a plot
implot::Plot::new("Demo plot")
.size(400.0, 300.0)
.x_label("awesome x label")
.y_label("awesome y label")
.build(|| {
implot::plot_line(&vec![2.0, 2.0], &vec![2.0, 1.0], "Left eye");
implot::plot_line(&vec![4.0, 4.0], &vec![2.0, 1.0], "Right eye");
let x_values = vec![1.0, 2.0, 4.0, 5.0];
let y_values = vec![1.0, 0.0, 0.0, 1.0];
implot::plot_line(&x_values, &y_values, "Mouth");
});
});
if showing_demo {
implot::show_demo_window(&mut showing_demo);
}
});
}

View file

@ -8,7 +8,7 @@ use glium::glutin::event::{Event, WindowEvent};
use glium::glutin::event_loop::{ControlFlow, EventLoop};
use glium::glutin::window::WindowBuilder;
use glium::{Display, Surface};
use imgui::{Context, FontConfig, FontGlyphRanges, FontSource, Ui};
use imgui::{Context, FontConfig, FontSource, Ui};
use imgui_glium_renderer::Renderer;
use imgui_winit_support::{HiDpiMode, WinitPlatform};
use std::time::Instant;