Skip to content

Commit

Permalink
add new ParamSliderStyle::FromMidPoint
Browse files Browse the repository at this point in the history
  • Loading branch information
magnetophon authored and robbert-vdh committed Dec 23, 2024
1 parent 40269e1 commit 55c41bf
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions nih_plug_vizia/src/widgets/param_slider.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,11 @@ pub enum ParamSliderStyle {
Centered,
/// Always fill the bar starting from the left.
FromLeft,
/// Fill the bar from the mid point, regardless of where the default value lies
FromMidPoint,
/// Show the current step instead of filling a portion of the bar, useful for discrete
/// parameters. Set `even` to `true` to distribute the ticks evenly instead of following the
/// parameter's distribution. This can be desireable because discrete parameters have smaller
/// parameter's distribution. This can be desirable because discrete parameters have smaller
/// ranges near the edges (they'll span only half the range, which can make the display look
/// odd).
CurrentStep { even: bool },
Expand Down Expand Up @@ -333,6 +335,16 @@ impl ParamSlider {
if delta >= 1e-3 { delta } else { 0.0 },
)
}
ParamSliderStyle::FromMidPoint => {
let delta = (0.5 - current_value).abs();

// Don't draw the filled portion at all if it could have been a
// rounding error since those slivers just look weird
(
0.5_f32.min(current_value),
if delta >= 1e-3 { delta } else { 0.0 },
)
}
ParamSliderStyle::Centered | ParamSliderStyle::FromLeft => (0.0, current_value),
ParamSliderStyle::CurrentStep { even: true }
| ParamSliderStyle::CurrentStepLabeled { even: true }
Expand Down Expand Up @@ -369,7 +381,9 @@ impl ParamSlider {
ParamSliderStyle::CurrentStep { .. } | ParamSliderStyle::CurrentStepLabeled { .. } => {
(0.0, 0.0)
}
ParamSliderStyle::Centered | ParamSliderStyle::FromLeft => {
ParamSliderStyle::Centered
| ParamSliderStyle::FromMidPoint
| ParamSliderStyle::FromLeft => {
let modulation_start = param.unmodulated_normalized_value();

(
Expand Down

0 comments on commit 55c41bf

Please sign in to comment.