Slider: add largest_finite for log-sliders that include infinity
This commit is contained in:
parent
5906bf7a87
commit
be8d7b4eef
1 changed files with 18 additions and 1 deletions
|
@ -33,6 +33,10 @@ struct SliderSpec {
|
||||||
/// For logarithmic sliders, the smallest positive value we are interested in.
|
/// For logarithmic sliders, the smallest positive value we are interested in.
|
||||||
/// 1 for integer sliders, maybe 1e-6 for others.
|
/// 1 for integer sliders, maybe 1e-6 for others.
|
||||||
smallest_positive: f64,
|
smallest_positive: f64,
|
||||||
|
/// For logarithmic sliders, the largest positive value we are interested in
|
||||||
|
/// before the slider switches to `INFINITY`, if that is the higher end.
|
||||||
|
/// Default: INFINITY.
|
||||||
|
largest_finite: f64,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Control a number by a horizontal slider.
|
/// Control a number by a horizontal slider.
|
||||||
|
@ -68,6 +72,7 @@ impl<'a> Slider<'a> {
|
||||||
spec: SliderSpec {
|
spec: SliderSpec {
|
||||||
logarithmic: false,
|
logarithmic: false,
|
||||||
smallest_positive: 1e-6,
|
smallest_positive: 1e-6,
|
||||||
|
largest_finite: f64::INFINITY,
|
||||||
},
|
},
|
||||||
clamp_to_range: false,
|
clamp_to_range: false,
|
||||||
smart_aim: true,
|
smart_aim: true,
|
||||||
|
@ -164,6 +169,14 @@ impl<'a> Slider<'a> {
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// For logarithmic sliders, the largest positive value we are interested in
|
||||||
|
/// before the slider switches to `INFINITY`, if that is the higher end.
|
||||||
|
/// Default: INFINITY.
|
||||||
|
pub fn largest_finite(mut self, largest_finite: f64) -> Self {
|
||||||
|
self.spec.largest_finite = largest_finite;
|
||||||
|
self
|
||||||
|
}
|
||||||
|
|
||||||
/// If set to `true`, all incoming and outgoing values will be clamped to the slider range.
|
/// If set to `true`, all incoming and outgoing values will be clamped to the slider range.
|
||||||
/// Default: `false`.
|
/// Default: `false`.
|
||||||
pub fn clamp_to_range(mut self, clamp_to_range: bool) -> Self {
|
pub fn clamp_to_range(mut self, clamp_to_range: bool) -> Self {
|
||||||
|
@ -545,7 +558,11 @@ fn range_log10(min: f64, max: f64, spec: &SliderSpec) -> (f64, f64) {
|
||||||
(max.log10() - INF_RANGE_MAGNITUDE, max.log10())
|
(max.log10() - INF_RANGE_MAGNITUDE, max.log10())
|
||||||
}
|
}
|
||||||
} else if max == INFINITY {
|
} else if max == INFINITY {
|
||||||
(min.log10(), min.log10() + INF_RANGE_MAGNITUDE)
|
if min < spec.largest_finite {
|
||||||
|
(min.log10(), spec.largest_finite.log10())
|
||||||
|
} else {
|
||||||
|
(min.log10(), min.log10() + INF_RANGE_MAGNITUDE)
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
(min.log10(), max.log10())
|
(min.log10(), max.log10())
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue