Skip to content

fix: format slider values to decimal places#38

Closed
xWalfie-SMR wants to merge 1 commit intoRhythia:indevfrom
xWalfie-SMR:indev
Closed

fix: format slider values to decimal places#38
xWalfie-SMR wants to merge 1 commit intoRhythia:indevfrom
xWalfie-SMR:indev

Conversation

@xWalfie-SMR
Copy link
Copy Markdown

  • added getDecimalPlaces() that takes the step value of a slider and returns its decimal index rounded
  • updateSlider() now uses getDecimalPlaces() to round the slider value to avoid floating point errors

- added getDecimalPlaces() that takes the step value of a slider and returns its decimal index rounded
- updateSlider() now uses getDecimalPlaces() to round the slider value to avoid floating point errors
Copilot AI review requested due to automatic review settings April 17, 2026 08:06
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adjusts how slider values are rendered in the settings UI by formatting slider values to a fixed number of decimal places derived from the slider’s Step, aiming to reduce visible floating-point artifacts.

Changes:

  • Updated updateSlider() to format slider values using a fixed-point format string with step-derived precision.
  • Added getDecimalPlaces(step) helper to infer the number of decimal places from the slider step.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines 320 to 329
@@ -327,6 +329,16 @@ private void updateSlider(HSlider slider, LineEdit lineEdit, double value)
slider.SetValueNoSignal(value);
Copy link

Copilot AI Apr 17, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updateSlider formats the text using a fixed-point format, but it does not actually round/snap the underlying value used for slider.SetValueNoSignal(value). This means floating-point artifacts can still persist in the slider/setting value (even if the text is rounded), and equality checks elsewhere (e.g. setting.GetVariant() != value) can still churn on tiny deltas. Consider rounding/snap-to-step the numeric value first (and then using that rounded value consistently for both the LineEdit text and the slider/set-variant paths).

Copilot uses AI. Check for mistakes.
Comment on lines +334 to +337
// round step to remove floating point errors
double roundedStep = Math.Round(step, 3);

string stepStr = roundedStep.ToString(System.Globalization.CultureInfo.InvariantCulture);
Copy link

Copilot AI Apr 17, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

getDecimalPlaces hardcodes Math.Round(step, 3), so the computed decimal place count will be incorrect for step values that legitimately require more than 3 decimal places (e.g. 0.0005 would be treated as 0.001). If this helper is meant to be generally correct for any slider step, consider deriving the decimal places without truncating precision (or making the precision limit an explicit constant tied to supported step values).

Suggested change
// round step to remove floating point errors
double roundedStep = Math.Round(step, 3);
string stepStr = roundedStep.ToString(System.Globalization.CultureInfo.InvariantCulture);
decimal decimalStep = Math.Abs((decimal)step);
string stepStr = decimalStep
.ToString(System.Globalization.CultureInfo.InvariantCulture)
.TrimEnd('0');

Copilot uses AI. Check for mistakes.
@nyuwaea
Copy link
Copy Markdown
Member

nyuwaea commented Apr 17, 2026

Thank you for the fix, the code looks good, but unfortunately there is another one waiting to be merged after PRs #35 & #37 are finished as they require some adjustment and fixes. I'm sorry this wasn't communicated anywhere as the bulk of contributions are discussed and reviewed through the Discord server rather than on GitHub, which I recognize is a flaw in our process.
Also, please avoid requesting AI reviews in the future.

@nyuwaea nyuwaea closed this Apr 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants