mirror of
https://github.com/eliasstepanik/imgui-rs.git
synced 2026-01-17 16:38:28 +00:00
Looks like sliders *do* need a default range
This commit is contained in:
parent
e5c6eb97f3
commit
2922dabc8f
@ -119,36 +119,47 @@ pub enum DataType {
|
||||
/// representation in memory as the primitive value described by the associated `KIND` constant.
|
||||
pub unsafe trait DataTypeKind: Copy {
|
||||
const KIND: DataType;
|
||||
const SLIDER_RANGE: RangeInclusive<Self>;
|
||||
}
|
||||
unsafe impl DataTypeKind for i8 {
|
||||
const KIND: DataType = DataType::I8;
|
||||
const SLIDER_RANGE: RangeInclusive<i8> = i8::MIN..=i8::MAX;
|
||||
}
|
||||
unsafe impl DataTypeKind for u8 {
|
||||
const KIND: DataType = DataType::U8;
|
||||
const SLIDER_RANGE: RangeInclusive<u8> = u8::MIN..=u8::MAX;
|
||||
}
|
||||
unsafe impl DataTypeKind for i16 {
|
||||
const KIND: DataType = DataType::I16;
|
||||
const SLIDER_RANGE: RangeInclusive<i16> = i16::MIN..=i16::MAX;
|
||||
}
|
||||
unsafe impl DataTypeKind for u16 {
|
||||
const KIND: DataType = DataType::U16;
|
||||
const SLIDER_RANGE: RangeInclusive<u16> = u16::MIN..=u16::MAX;
|
||||
}
|
||||
unsafe impl DataTypeKind for i32 {
|
||||
const KIND: DataType = DataType::I32;
|
||||
const SLIDER_RANGE: RangeInclusive<i32> = (i32::MIN / 2)..=(i32::MAX / 2);
|
||||
}
|
||||
unsafe impl DataTypeKind for u32 {
|
||||
const KIND: DataType = DataType::U32;
|
||||
const SLIDER_RANGE: RangeInclusive<u32> = (u32::MIN / 2)..=(u32::MAX / 2);
|
||||
}
|
||||
unsafe impl DataTypeKind for i64 {
|
||||
const KIND: DataType = DataType::I64;
|
||||
const SLIDER_RANGE: RangeInclusive<i64> = (i64::MIN / 2)..=(i64::MAX / 2);
|
||||
}
|
||||
unsafe impl DataTypeKind for u64 {
|
||||
const KIND: DataType = DataType::U64;
|
||||
const SLIDER_RANGE: RangeInclusive<u64> = (u64::MIN / 2)..=(u64::MAX / 2);
|
||||
}
|
||||
unsafe impl DataTypeKind for f32 {
|
||||
const KIND: DataType = DataType::F32;
|
||||
const SLIDER_RANGE: RangeInclusive<f32> = (f32::MIN / 2.0)..=(f32::MAX / 2.0);
|
||||
}
|
||||
unsafe impl DataTypeKind for f64 {
|
||||
const KIND: DataType = DataType::F64;
|
||||
const SLIDER_RANGE: RangeInclusive<f64> = (f64::MIN / 2.0)..=(f64::MAX / 2.0);
|
||||
}
|
||||
|
||||
pub trait InclusiveRangeBounds<T: Copy> {
|
||||
|
||||
@ -29,8 +29,8 @@ bitflags!(
|
||||
#[must_use]
|
||||
pub struct Slider<'a, T: DataTypeKind> {
|
||||
label: &'a ImStr,
|
||||
min: Option<T>,
|
||||
max: Option<T>,
|
||||
min: T,
|
||||
max: T,
|
||||
display_format: Option<&'a ImStr>,
|
||||
flags: SliderFlags,
|
||||
}
|
||||
@ -40,8 +40,8 @@ impl<'a, T: DataTypeKind> Slider<'a, T> {
|
||||
pub fn new(label: &ImStr) -> Slider<T> {
|
||||
Slider {
|
||||
label,
|
||||
min: None,
|
||||
max: None,
|
||||
min: *T::SLIDER_RANGE.start(),
|
||||
max: *T::SLIDER_RANGE.end(),
|
||||
display_format: None,
|
||||
flags: SliderFlags::empty(),
|
||||
}
|
||||
@ -49,8 +49,8 @@ impl<'a, T: DataTypeKind> Slider<'a, T> {
|
||||
/// Sets the range (inclusive)
|
||||
#[inline]
|
||||
pub fn range<R: InclusiveRangeBounds<T>>(mut self, range: R) -> Self {
|
||||
self.min = range.start_bound().copied();
|
||||
self.max = range.end_bound().copied();
|
||||
self.min = *range.start_bound().unwrap_or(T::SLIDER_RANGE.start());
|
||||
self.max = *range.end_bound().unwrap_or(T::SLIDER_RANGE.end());
|
||||
self
|
||||
}
|
||||
/// Sets the display format using *a C-style printf string*
|
||||
@ -74,14 +74,8 @@ impl<'a, T: DataTypeKind> Slider<'a, T> {
|
||||
self.label.as_ptr(),
|
||||
T::KIND as i32,
|
||||
value as *mut T as *mut c_void,
|
||||
self.min
|
||||
.as_ref()
|
||||
.map(|min| min as *const T)
|
||||
.unwrap_or(ptr::null()) as *const c_void,
|
||||
self.max
|
||||
.as_ref()
|
||||
.map(|max| max as *const T)
|
||||
.unwrap_or(ptr::null()) as *const c_void,
|
||||
&self.min as *const T as *const c_void,
|
||||
&self.max as *const T as *const c_void,
|
||||
self.display_format
|
||||
.map(ImStr::as_ptr)
|
||||
.unwrap_or(ptr::null()),
|
||||
@ -99,14 +93,8 @@ impl<'a, T: DataTypeKind> Slider<'a, T> {
|
||||
T::KIND as i32,
|
||||
values.as_mut_ptr() as *mut c_void,
|
||||
values.len() as i32,
|
||||
self.min
|
||||
.as_ref()
|
||||
.map(|min| min as *const T)
|
||||
.unwrap_or(ptr::null()) as *const c_void,
|
||||
self.max
|
||||
.as_ref()
|
||||
.map(|max| max as *const T)
|
||||
.unwrap_or(ptr::null()) as *const c_void,
|
||||
&self.min as *const T as *const c_void,
|
||||
&self.max as *const T as *const c_void,
|
||||
self.display_format
|
||||
.map(ImStr::as_ptr)
|
||||
.unwrap_or(ptr::null()),
|
||||
@ -122,8 +110,8 @@ impl<'a, T: DataTypeKind> Slider<'a, T> {
|
||||
pub struct VerticalSlider<'a, T: DataTypeKind + Copy> {
|
||||
label: &'a ImStr,
|
||||
size: [f32; 2],
|
||||
min: Option<T>,
|
||||
max: Option<T>,
|
||||
min: T,
|
||||
max: T,
|
||||
display_format: Option<&'a ImStr>,
|
||||
flags: SliderFlags,
|
||||
}
|
||||
@ -134,8 +122,8 @@ impl<'a, T: DataTypeKind> VerticalSlider<'a, T> {
|
||||
VerticalSlider {
|
||||
label,
|
||||
size,
|
||||
min: None,
|
||||
max: None,
|
||||
min: *T::SLIDER_RANGE.start(),
|
||||
max: *T::SLIDER_RANGE.end(),
|
||||
display_format: None,
|
||||
flags: SliderFlags::empty(),
|
||||
}
|
||||
@ -143,8 +131,8 @@ impl<'a, T: DataTypeKind> VerticalSlider<'a, T> {
|
||||
/// Sets the range (inclusive)
|
||||
#[inline]
|
||||
pub fn range<R: InclusiveRangeBounds<T>>(mut self, range: R) -> Self {
|
||||
self.min = range.start_bound().copied();
|
||||
self.max = range.end_bound().copied();
|
||||
self.min = *range.start_bound().unwrap_or(T::SLIDER_RANGE.start());
|
||||
self.max = *range.end_bound().unwrap_or(T::SLIDER_RANGE.end());
|
||||
self
|
||||
}
|
||||
/// Sets the display format using *a C-style printf string*
|
||||
@ -169,14 +157,8 @@ impl<'a, T: DataTypeKind> VerticalSlider<'a, T> {
|
||||
self.size.into(),
|
||||
T::KIND as i32,
|
||||
value as *mut T as *mut c_void,
|
||||
self.min
|
||||
.as_ref()
|
||||
.map(|min| min as *const T)
|
||||
.unwrap_or(ptr::null()) as *const c_void,
|
||||
self.max
|
||||
.as_ref()
|
||||
.map(|max| max as *const T)
|
||||
.unwrap_or(ptr::null()) as *const c_void,
|
||||
&self.min as *const T as *const c_void,
|
||||
&self.max as *const T as *const c_void,
|
||||
self.display_format
|
||||
.map(ImStr::as_ptr)
|
||||
.unwrap_or(ptr::null()),
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user