Merge pull request #491 from dbr/sliderdoc

Add example to Slider.range() doc
This commit is contained in:
Jonathan Spira 2021-09-02 18:11:49 -04:00 committed by GitHub
commit 8b899381f3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -48,6 +48,28 @@ impl<'a, T: DataTypeKind> Slider<'a, T> {
}
}
/// Sets the range (inclusive)
///
/// The argument uses the standard Rust [`std::ops::Range`] syntax.
///
/// For example, to set both the min and max values:
///
/// ```rust
/// # use imgui::im_str;
/// imgui::Slider::new(im_str!("Example"))
/// .range(1 ..= 10)
/// // Remember to call .build(&ui)
/// ;
/// ```
///
/// To set only the max value, using the default minimum value:
///
/// ```rust
/// # use imgui::im_str;
/// imgui::Slider::new(im_str!("Example"))
/// .range(..= 10)
/// // Remember to call .build(&ui)
/// ;
/// ```
#[inline]
pub fn range<R: InclusiveRangeBounds<T>>(mut self, range: R) -> Self {
self.min = range.start_bound().copied().unwrap_or(T::SLIDER_MIN);