Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add new ParamSliderStyle::FromMidPoint #187

Merged
merged 1 commit into from
Dec 23, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading