Skip to content

Commit 55c41bf

Browse files
magnetophonrobbert-vdh
authored andcommitted
add new ParamSliderStyle::FromMidPoint
1 parent 40269e1 commit 55c41bf

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

nih_plug_vizia/src/widgets/param_slider.rs

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,11 @@ pub enum ParamSliderStyle {
4949
Centered,
5050
/// Always fill the bar starting from the left.
5151
FromLeft,
52+
/// Fill the bar from the mid point, regardless of where the default value lies
53+
FromMidPoint,
5254
/// Show the current step instead of filling a portion of the bar, useful for discrete
5355
/// parameters. Set `even` to `true` to distribute the ticks evenly instead of following the
54-
/// parameter's distribution. This can be desireable because discrete parameters have smaller
56+
/// parameter's distribution. This can be desirable because discrete parameters have smaller
5557
/// ranges near the edges (they'll span only half the range, which can make the display look
5658
/// odd).
5759
CurrentStep { even: bool },
@@ -333,6 +335,16 @@ impl ParamSlider {
333335
if delta >= 1e-3 { delta } else { 0.0 },
334336
)
335337
}
338+
ParamSliderStyle::FromMidPoint => {
339+
let delta = (0.5 - current_value).abs();
340+
341+
// Don't draw the filled portion at all if it could have been a
342+
// rounding error since those slivers just look weird
343+
(
344+
0.5_f32.min(current_value),
345+
if delta >= 1e-3 { delta } else { 0.0 },
346+
)
347+
}
336348
ParamSliderStyle::Centered | ParamSliderStyle::FromLeft => (0.0, current_value),
337349
ParamSliderStyle::CurrentStep { even: true }
338350
| ParamSliderStyle::CurrentStepLabeled { even: true }
@@ -369,7 +381,9 @@ impl ParamSlider {
369381
ParamSliderStyle::CurrentStep { .. } | ParamSliderStyle::CurrentStepLabeled { .. } => {
370382
(0.0, 0.0)
371383
}
372-
ParamSliderStyle::Centered | ParamSliderStyle::FromLeft => {
384+
ParamSliderStyle::Centered
385+
| ParamSliderStyle::FromMidPoint
386+
| ParamSliderStyle::FromLeft => {
373387
let modulation_start = param.unmodulated_normalized_value();
374388

375389
(

0 commit comments

Comments
 (0)