From 0119c5016977e69185fb44408cb2435e7aac7096 Mon Sep 17 00:00:00 2001 From: orhanbalci Date: Fri, 3 Jun 2016 21:36:47 +0300 Subject: [PATCH 1/2] plotlines api added --- src/lib.rs | 10 +++++++ src/plotlines.rs | 75 ++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 85 insertions(+) create mode 100644 src/plotlines.rs diff --git a/src/lib.rs b/src/lib.rs index 91a0597..fed01aa 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -46,6 +46,7 @@ pub use sliders::{SliderFloat, SliderInt}; pub use trees::{TreeNode}; pub use widgets::{CollapsingHeader}; pub use window::{Window}; +pub use plotlines::{PlotLines}; mod input; mod menus; @@ -53,6 +54,7 @@ mod sliders; mod trees; mod widgets; mod window; +mod plotlines; #[cfg(feature = "glium")] pub mod glium_renderer; @@ -564,3 +566,11 @@ impl<'ui> Ui<'ui> { } } } + +impl<'ui> Ui<'ui> { + pub fn plot_lines<'p>(&self, + label: ImStr<'p>, + values: &'p[f32])->PlotLines<'p>{ + PlotLines::new(label, values) + } +} diff --git a/src/plotlines.rs b/src/plotlines.rs new file mode 100644 index 0000000..9cc365e --- /dev/null +++ b/src/plotlines.rs @@ -0,0 +1,75 @@ +use imgui_sys; +use super::{ImStr}; +use imgui_sys::ImVec2; +use std::{f32, mem, ptr}; +use libc::c_float; +#[must_use] +pub struct PlotLines<'p> { + label: ImStr<'p>, + values: &'p [f32], + values_ofset: i32, + overlay_text: Option>, + scale_min: f32, + scale_max: f32, + graph_size: ImVec2, + stride: i32, +} + +impl<'p> PlotLines<'p> { + pub fn new(label: ImStr<'p>, values: &'p [f32]) -> Self { + PlotLines { + label: label, + values: values, + values_ofset: 0i32, + overlay_text: None, + scale_min: f32::MAX, + scale_max: f32::MAX, + graph_size: ImVec2::new(0.0f32, 0.0f32), + stride: mem::size_of::() as i32, + } + } + + #[inline] + pub fn values_ofset(self, values_ofset: i32) -> Self { + PlotLines { values_ofset: values_ofset, ..self } + } + + #[inline] + pub fn overlay_text(self, overlay_text: ImStr<'p>) -> Self { + PlotLines { overlay_text: Some(overlay_text), ..self } + } + + #[inline] + pub fn scale_min(self, scale_min: f32) -> Self { + PlotLines { scale_min: scale_min, ..self } + } + + #[inline] + pub fn scale_max(self, scale_max: f32) -> Self { + PlotLines { scale_max: scale_max, ..self } + } + + #[inline] + pub fn graph_size(self, graph_size: ImVec2) -> Self { + PlotLines { graph_size: graph_size, ..self } + } + + #[inline] + pub fn stride(self, stride: i32) -> Self { + PlotLines { stride: stride, ..self } + } + + pub fn build(self) { + unsafe { + imgui_sys::igPlotLines(self.label.as_ptr(), + self.values.as_ptr() as *const c_float, + self.values.len() as i32, + self.values_ofset, + self.overlay_text.map(|x| x.as_ptr()).unwrap_or(ptr::null()), + self.scale_min, + self.scale_max, + self.graph_size, + self.stride); + } + } +} From 2f2fc759c2a7b699872fa2dbac9be74fa0360279 Mon Sep 17 00:00:00 2001 From: orhanbalci Date: Wed, 8 Jun 2016 22:05:10 +0300 Subject: [PATCH 2/2] typo fixed ofset -> offset stride parameter removed from struct values_offset type updated to usize --- src/plotlines.rs | 19 ++++++------------- 1 file changed, 6 insertions(+), 13 deletions(-) diff --git a/src/plotlines.rs b/src/plotlines.rs index 9cc365e..bef6277 100644 --- a/src/plotlines.rs +++ b/src/plotlines.rs @@ -7,12 +7,11 @@ use libc::c_float; pub struct PlotLines<'p> { label: ImStr<'p>, values: &'p [f32], - values_ofset: i32, + values_offset: usize, overlay_text: Option>, scale_min: f32, scale_max: f32, graph_size: ImVec2, - stride: i32, } impl<'p> PlotLines<'p> { @@ -20,18 +19,17 @@ impl<'p> PlotLines<'p> { PlotLines { label: label, values: values, - values_ofset: 0i32, + values_offset: 0usize, overlay_text: None, scale_min: f32::MAX, scale_max: f32::MAX, graph_size: ImVec2::new(0.0f32, 0.0f32), - stride: mem::size_of::() as i32, } } #[inline] - pub fn values_ofset(self, values_ofset: i32) -> Self { - PlotLines { values_ofset: values_ofset, ..self } + pub fn values_offset(self, values_offset: usize) -> Self { + PlotLines { values_offset: values_offset, ..self } } #[inline] @@ -54,22 +52,17 @@ impl<'p> PlotLines<'p> { PlotLines { graph_size: graph_size, ..self } } - #[inline] - pub fn stride(self, stride: i32) -> Self { - PlotLines { stride: stride, ..self } - } - pub fn build(self) { unsafe { imgui_sys::igPlotLines(self.label.as_ptr(), self.values.as_ptr() as *const c_float, self.values.len() as i32, - self.values_ofset, + self.values_offset as i32, self.overlay_text.map(|x| x.as_ptr()).unwrap_or(ptr::null()), self.scale_min, self.scale_max, self.graph_size, - self.stride); + mem::size_of::() as i32); } } }