1
0
Fork 0

Add a ParamSlider display style highlighting step

This might work better for some types of discrete parameters.
This commit is contained in:
Robbert van der Helm 2022-03-19 19:29:19 +01:00
parent 4c5d61057e
commit 9e8b498676

View file

@ -44,6 +44,9 @@ pub enum ParamSliderStyle {
Centered,
/// Always fill the bar starting from the left.
FromLeft,
/// Show the current step instead of filling a portion fothe bar, useful for discrete
/// parameters.
CurrentStep,
}
enum ParamSliderEvent {
@ -171,20 +174,34 @@ impl ParamSlider {
.height(Stretch(1.0))
.bind(normalized_param_value_lens, move |handle, value| {
let current_value = *value.get(handle.cx);
let (start_t, mut delta) = if draw_fill_from_default {
let (start_t, delta) = match style {
ParamSliderStyle::Centered
if draw_fill_from_default =>
{
let delta = (default_value - current_value).abs();
(
default_value.min(current_value),
(default_value - current_value).abs(),
)
} else {
(0.0, current_value)
};
// Don't draw the filled portion at all if it could have been a
// rounding error since those slivers just look weird
if delta < 1e-3 {
delta = 0.0;
if delta >= 1e-3 { delta } else { 0.0 },
)
}
ParamSliderStyle::Centered
| ParamSliderStyle::FromLeft => (0.0, current_value),
ParamSliderStyle::CurrentStep => {
let previous_step = unsafe {
param_ptr
.previous_normalized_step(current_value)
};
let next_step = unsafe {
param_ptr.next_normalized_step(current_value)
};
(
(previous_step + current_value) / 2.0,
(next_step + current_value) / 2.0,
)
}
};
handle
.left(Percentage(start_t * 100.0))