Make DragValue::from_get_set public

Closes https://github.com/emilk/egui/issues/188
This commit is contained in:
Emil Ernerfeldt 2021-02-23 20:16:43 +01:00
parent 5f6a468812
commit 049a7b0382

View file

@ -52,18 +52,6 @@ pub struct DragValue<'a> {
}
impl<'a> DragValue<'a> {
pub(crate) fn from_get_set(get_set_value: impl 'a + FnMut(Option<f64>) -> f64) -> Self {
Self {
get_set_value: Box::new(get_set_value),
speed: 1.0,
prefix: Default::default(),
suffix: Default::default(),
clamp_range: f64::NEG_INFINITY..=f64::INFINITY,
min_decimals: 0,
max_decimals: None,
}
}
pub fn f32(value: &'a mut f32) -> Self {
Self::from_get_set(move |v: Option<f64>| {
if let Some(v) = v {
@ -102,6 +90,18 @@ impl<'a> DragValue<'a> {
.max_decimals(0)
}
pub fn from_get_set(get_set_value: impl 'a + FnMut(Option<f64>) -> f64) -> Self {
Self {
get_set_value: Box::new(get_set_value),
speed: 1.0,
prefix: Default::default(),
suffix: Default::default(),
clamp_range: f64::NEG_INFINITY..=f64::INFINITY,
min_decimals: 0,
max_decimals: None,
}
}
/// How much the value changes when dragged one point (logical pixel).
pub fn speed(mut self, speed: impl Into<f64>) -> Self {
self.speed = speed.into();