mirror of
https://github.com/eliasstepanik/imgui-rs.git
synced 2026-01-19 09:28:27 +00:00
Since we consume self anyway, this style is much more readable and might have better performance in non-optimized builds.
89 lines
2.4 KiB
Rust
89 lines
2.4 KiB
Rust
use imgui_sys;
|
|
use std::marker::PhantomData;
|
|
|
|
use super::{ImStr, Ui};
|
|
|
|
// TODO: Consider using Range, even though it is half-open
|
|
|
|
#[must_use]
|
|
pub struct SliderInt<'ui, 'p> {
|
|
label: ImStr<'p>,
|
|
value: &'p mut i32,
|
|
min: i32,
|
|
max: i32,
|
|
display_format: ImStr<'p>,
|
|
_phantom: PhantomData<&'ui Ui<'ui>>,
|
|
}
|
|
|
|
impl<'ui, 'p> SliderInt<'ui, 'p> {
|
|
pub fn new(label: ImStr<'p>, value: &'p mut i32, min: i32, max: i32) -> Self {
|
|
SliderInt {
|
|
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::igSliderInt(self.label.as_ptr(),
|
|
self.value,
|
|
self.min,
|
|
self.max,
|
|
self.display_format.as_ptr())
|
|
}
|
|
}
|
|
}
|
|
|
|
#[must_use]
|
|
pub struct SliderFloat<'ui, 'p> {
|
|
label: ImStr<'p>,
|
|
value: &'p mut f32,
|
|
min: f32,
|
|
max: f32,
|
|
display_format: ImStr<'p>,
|
|
power: f32,
|
|
_phantom: PhantomData<&'ui Ui<'ui>>,
|
|
}
|
|
|
|
impl<'ui, 'p> SliderFloat<'ui, 'p> {
|
|
pub fn new(label: ImStr<'p>, value: &'p mut f32, min: f32, max: f32) -> Self {
|
|
SliderFloat {
|
|
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::igSliderFloat(self.label.as_ptr(),
|
|
self.value,
|
|
self.min,
|
|
self.max,
|
|
self.display_format.as_ptr(),
|
|
self.power)
|
|
}
|
|
}
|
|
}
|