diff --git a/src/internal.rs b/src/internal.rs index 358fd50..c890484 100644 --- a/src/internal.rs +++ b/src/internal.rs @@ -119,47 +119,58 @@ 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; + const SLIDER_MIN: Self; + const SLIDER_MAX: Self; } unsafe impl DataTypeKind for i8 { const KIND: DataType = DataType::I8; - const SLIDER_RANGE: RangeInclusive = i8::MIN..=i8::MAX; + const SLIDER_MIN: Self = Self::MIN; + const SLIDER_MAX: Self = Self::MAX; } unsafe impl DataTypeKind for u8 { const KIND: DataType = DataType::U8; - const SLIDER_RANGE: RangeInclusive = u8::MIN..=u8::MAX; + const SLIDER_MIN: Self = Self::MIN; + const SLIDER_MAX: Self = Self::MAX; } unsafe impl DataTypeKind for i16 { const KIND: DataType = DataType::I16; - const SLIDER_RANGE: RangeInclusive = i16::MIN..=i16::MAX; + const SLIDER_MIN: Self = Self::MIN; + const SLIDER_MAX: Self = Self::MAX; } unsafe impl DataTypeKind for u16 { const KIND: DataType = DataType::U16; - const SLIDER_RANGE: RangeInclusive = u16::MIN..=u16::MAX; + const SLIDER_MIN: Self = Self::MIN; + const SLIDER_MAX: Self = Self::MAX; } unsafe impl DataTypeKind for i32 { const KIND: DataType = DataType::I32; - const SLIDER_RANGE: RangeInclusive = (i32::MIN / 2)..=(i32::MAX / 2); + const SLIDER_MIN: Self = Self::MIN; + const SLIDER_MAX: Self = Self::MAX; } unsafe impl DataTypeKind for u32 { const KIND: DataType = DataType::U32; - const SLIDER_RANGE: RangeInclusive = (u32::MIN / 2)..=(u32::MAX / 2); + const SLIDER_MIN: Self = Self::MIN; + const SLIDER_MAX: Self = Self::MAX; } unsafe impl DataTypeKind for i64 { const KIND: DataType = DataType::I64; - const SLIDER_RANGE: RangeInclusive = (i64::MIN / 2)..=(i64::MAX / 2); + const SLIDER_MIN: Self = Self::MIN; + const SLIDER_MAX: Self = Self::MAX; } unsafe impl DataTypeKind for u64 { const KIND: DataType = DataType::U64; - const SLIDER_RANGE: RangeInclusive = (u64::MIN / 2)..=(u64::MAX / 2); + const SLIDER_MIN: Self = Self::MIN; + const SLIDER_MAX: Self = Self::MAX; } unsafe impl DataTypeKind for f32 { const KIND: DataType = DataType::F32; - const SLIDER_RANGE: RangeInclusive = (f32::MIN / 2.0)..=(f32::MAX / 2.0); + const SLIDER_MIN: Self = Self::MIN; + const SLIDER_MAX: Self = Self::MAX; } unsafe impl DataTypeKind for f64 { const KIND: DataType = DataType::F64; - const SLIDER_RANGE: RangeInclusive = (f64::MIN / 2.0)..=(f64::MAX / 2.0); + const SLIDER_MIN: Self = Self::MIN; + const SLIDER_MAX: Self = Self::MAX; } pub trait InclusiveRangeBounds { diff --git a/src/widget/slider.rs b/src/widget/slider.rs index 1c01b71..eb5e814 100644 --- a/src/widget/slider.rs +++ b/src/widget/slider.rs @@ -40,8 +40,8 @@ impl<'a, T: DataTypeKind> Slider<'a, T> { pub fn new(label: &ImStr) -> Slider { Slider { label, - min: *T::SLIDER_RANGE.start(), - max: *T::SLIDER_RANGE.end(), + min: T::SLIDER_MIN, + max: T::SLIDER_MAX, 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>(mut self, range: R) -> Self { - self.min = *range.start_bound().unwrap_or(T::SLIDER_RANGE.start()); - self.max = *range.end_bound().unwrap_or(T::SLIDER_RANGE.end()); + self.min = range.start_bound().copied().unwrap_or(T::SLIDER_MIN); + self.max = range.end_bound().copied().unwrap_or(T::SLIDER_MAX); self } /// Sets the display format using *a C-style printf string* @@ -122,8 +122,8 @@ impl<'a, T: DataTypeKind> VerticalSlider<'a, T> { VerticalSlider { label, size, - min: *T::SLIDER_RANGE.start(), - max: *T::SLIDER_RANGE.end(), + min: T::SLIDER_MIN, + max: T::SLIDER_MAX, display_format: None, flags: SliderFlags::empty(), } @@ -131,8 +131,8 @@ impl<'a, T: DataTypeKind> VerticalSlider<'a, T> { /// Sets the range (inclusive) #[inline] pub fn range>(mut self, range: R) -> Self { - self.min = *range.start_bound().unwrap_or(T::SLIDER_RANGE.start()); - self.max = *range.end_bound().unwrap_or(T::SLIDER_RANGE.end()); + self.min = range.start_bound().copied().unwrap_or(T::SLIDER_MIN); + self.max = range.end_bound().copied().unwrap_or(T::SLIDER_MAX); self } /// Sets the display format using *a C-style printf string*