Merge pull request #47 from mulimoen/more_sliders

Add multi-sliders
This commit is contained in:
Joonas Javanainen 2017-04-25 22:22:27 +03:00 committed by GitHub
commit 01a698cd65
2 changed files with 150 additions and 1 deletions

View File

@ -42,7 +42,8 @@ pub use menus::{Menu, MenuItem};
pub use plothistogram::PlotHistogram;
pub use plotlines::PlotLines;
pub use progressbar::ProgressBar;
pub use sliders::{SliderFloat, SliderInt};
pub use sliders::{SliderFloat, SliderFloat2, SliderFloat3, SliderFloat4, SliderInt, SliderInt2,
SliderInt3, SliderInt4};
pub use trees::{CollapsingHeader, TreeNode};
pub use window::Window;
@ -582,6 +583,30 @@ impl<'ui> Ui<'ui> {
-> SliderFloat<'ui, 'p> {
SliderFloat::new(label, value, min, max)
}
pub fn slider_float2<'p>(&self,
label: ImStr<'p>,
value: &'p mut [f32; 2],
min: f32,
max: f32)
-> SliderFloat2<'ui, 'p> {
SliderFloat2::new(label, value, min, max)
}
pub fn slider_float3<'p>(&self,
label: ImStr<'p>,
value: &'p mut [f32; 3],
min: f32,
max: f32)
-> SliderFloat3<'ui, 'p> {
SliderFloat3::new(label, value, min, max)
}
pub fn slider_float4<'p>(&self,
label: ImStr<'p>,
value: &'p mut [f32; 4],
min: f32,
max: f32)
-> SliderFloat4<'ui, 'p> {
SliderFloat4::new(label, value, min, max)
}
pub fn slider_int<'p>(&self,
label: ImStr<'p>,
value: &'p mut i32,
@ -590,6 +615,30 @@ impl<'ui> Ui<'ui> {
-> SliderInt<'ui, 'p> {
SliderInt::new(label, value, min, max)
}
pub fn slider_int2<'p>(&self,
label: ImStr<'p>,
value: &'p mut [i32; 2],
min: i32,
max: i32)
-> SliderInt2<'ui, 'p> {
SliderInt2::new(label, value, min, max)
}
pub fn slider_int3<'p>(&self,
label: ImStr<'p>,
value: &'p mut [i32; 3],
min: i32,
max: i32)
-> SliderInt3<'ui, 'p> {
SliderInt3::new(label, value, min, max)
}
pub fn slider_int4<'p>(&self,
label: ImStr<'p>,
value: &'p mut [i32; 4],
min: i32,
max: i32)
-> SliderInt4<'ui, 'p> {
SliderInt4::new(label, value, min, max)
}
}
// Widgets: Trees

View File

@ -42,6 +42,52 @@ impl<'ui, 'p> SliderInt<'ui, 'p> {
}
}
macro_rules! impl_slider_intn {
($SliderIntN:ident, $N:expr, $igSliderIntN:ident) => {
#[must_use]
pub struct $SliderIntN<'ui, 'p> {
label: ImStr<'p>,
value: &'p mut [i32; $N],
min: i32,
max: i32,
display_format: ImStr<'p>,
_phantom: PhantomData<&'ui Ui<'ui>>,
}
impl<'ui, 'p> $SliderIntN<'ui, 'p> {
pub fn new(label: ImStr<'p>, value: &'p mut [i32; $N], min: i32, max: i32) -> Self {
$SliderIntN {
label: label,
value: value,
min: min,
max: max,
display_format: unsafe { ImStr::from_bytes_unchecked(b"%.0f\0") },
_phantom: PhantomData,
}
}
#[inline]
pub fn display_format(mut self, display_format: ImStr<'p>) -> Self {
self.display_format = display_format;
self
}
pub fn build(self) -> bool {
unsafe {
imgui_sys::$igSliderIntN(
self.label.as_ptr(),
self.value.as_mut_ptr(),
self.min,
self.max,
self.display_format.as_ptr())
}
}
}
}
}
impl_slider_intn!(SliderInt2, 2, igSliderInt2);
impl_slider_intn!(SliderInt3, 3, igSliderInt3);
impl_slider_intn!(SliderInt4, 4, igSliderInt4);
#[must_use]
pub struct SliderFloat<'ui, 'p> {
label: ImStr<'p>,
@ -86,3 +132,57 @@ impl<'ui, 'p> SliderFloat<'ui, 'p> {
}
}
}
macro_rules! impl_slider_floatn {
($SliderFloatN:ident, $N:expr, $igSliderFloatN:ident) => {
#[must_use]
pub struct $SliderFloatN<'ui, 'p> {
label: ImStr<'p>,
value: &'p mut [f32; $N],
min: f32,
max: f32,
display_format: ImStr<'p>,
power: f32,
_phantom: PhantomData<&'ui Ui<'ui>>,
}
impl<'ui, 'p> $SliderFloatN<'ui, 'p> {
pub fn new(label: ImStr<'p>, value: &'p mut [f32; $N], min: f32, max: f32) -> Self {
$SliderFloatN {
label: label,
value: value,
min: min,
max: max,
display_format: unsafe { ImStr::from_bytes_unchecked(b"%.3f\0") },
power: 1.0,
_phantom: PhantomData,
}
}
#[inline]
pub fn display_format(mut self, display_format: ImStr<'p>) -> Self {
self.display_format = display_format;
self
}
#[inline]
pub fn power(mut self, power: f32) -> Self {
self.power = power;
self
}
pub fn build(self) -> bool {
unsafe {
imgui_sys::$igSliderFloatN(
self.label.as_ptr(),
self.value.as_mut_ptr(),
self.min,
self.max,
self.display_format.as_ptr(),
self.power)
}
}
}
}
}
impl_slider_floatn!(SliderFloat2, 2, igSliderFloat2);
impl_slider_floatn!(SliderFloat3, 3, igSliderFloat3);
impl_slider_floatn!(SliderFloat4, 4, igSliderFloat4);