Skip to content

Fix SliderFloat resetting small values (below 0.001) to zero#474

Draft
Copilot wants to merge 5 commits intodevelopfrom
copilot/fix-sliderfloat-small-values
Draft

Fix SliderFloat resetting small values (below 0.001) to zero#474
Copilot wants to merge 5 commits intodevelopfrom
copilot/fix-sliderfloat-small-values

Conversation

Copy link
Contributor

Copilot AI commented Feb 21, 2026

applyFormatToValue converts printf format strings (e.g., "%.4f") into pre-formatted literal strings (e.g., "0.0001"), stripping the % specifier. This causes two problems in ImGui:

  1. Broken precision parsing: ImParseFormatPrecision falls back to default precision 3 when it finds no %, setting logarithmic_zero_epsilon = 0.001. On logarithmic sliders with min=0, any value ≤ 0.001 gets a ratio of 0 and snaps to v_min (0) on interaction.
  2. Rounding to zero: RoundScalarWithFormatT rounds slider values to the format's precision during interaction. With "%.3f", any value below 0.001 rounds to 0.

Fix

Two changes in BasicSlider:

  1. Pass original printf format to ImGui: When tryMaintainFormat=true for floats, return the original format string (e.g., "%.4f") instead of a pre-formatted literal. This matches the existing behavior for int types and allows ImGui to correctly parse the precision for logarithmic epsilon calculation.

  2. Add ImGuiSliderFlags_NoRoundToFormat: Prevents RoundScalarWithFormatT from rounding small values to zero during slider interaction. This flag is explicitly recommended by ImGui's documentation for logarithmic sliders with limited-precision format strings.

// applyFormatToValue: return original format for floats when tryMaintainFormat=true
if constexpr (std::is_same_v<T, float>) {
    if (tryMaintainFormat) {
        return format;  // e.g., "%.4f" instead of "0.0001"
    }
    // ... existing pre-formatting for display strings ...
}

// BasicSlider: add NoRoundToFormat flag for float sliders
auto flags = ImGuiSliderFlags_NoRoundToFormat | (parameters._logarithmic ? ImGuiSliderFlags_Logarithmic : 0);
result |= ImGui::SliderFloat("##slider", &sliderValue, parameters._min, parameters._max, format.c_str(), flags);
  • Pre-formatted display strings (with comma separators) are still used for the tryMaintainFormat=false path (e.g., collapsed color-dependent range display)
  • Int sliders are unchanged

💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Copilot AI self-assigned this Feb 21, 2026
Copilot AI and others added 2 commits February 21, 2026 19:14
When applyFormatToValue formats small float values with limited decimal
places (e.g. "%.3f"), values below 0.001 produce "0.000" - a string
without a printf format specifier. This pre-formatted string passed to
ImGui::SliderFloat breaks ImGui's internal value handling:

- RoundScalarWithFormatT rounds the value to 0 during text input
- TempInputScalar falls back to "%.3f", displaying "0.000" and parsing
  it back as 0.0

Fix: When the value is too small for the specified decimal places,
dynamically increase precision and return a proper printf-style format
string (e.g. "%.4f" for 0.0001) so ImGui handles display, rounding,
and text input correctly. Normal/large values keep pre-formatted strings
with comma separators.

Co-authored-by: chrxh <73127001+chrxh@users.noreply.github.com>
Co-authored-by: chrxh <73127001+chrxh@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix float sliders in AlienGui for small values Fix SliderFloat resetting small values (below 0.001) to zero Feb 21, 2026
Copilot AI requested a review from chrxh February 21, 2026 18:18
@chrxh
Copy link
Owner

chrxh commented Feb 21, 2026

@copilot that is not the reason. still the same problem

Copilot AI and others added 2 commits February 21, 2026 21:28
Co-authored-by: chrxh <73127001+chrxh@users.noreply.github.com>
…isable rounding

The root cause is that applyFormatToValue converts printf formats (e.g.
"%.4f") into pre-formatted strings (e.g. "0.0001") which strips the %
specifier. This breaks ImGui's ImParseFormatPrecision (falls back to
default precision 3), causing logarithmic_zero_epsilon=0.001 and
snapping small values to 0 on interaction. Additionally,
RoundScalarWithFormatT rounds values below the format precision to 0.

Fix:
1. Return original printf format when tryMaintainFormat=true for floats
   (matching existing int behavior), so ImGui can parse precision
2. Add ImGuiSliderFlags_NoRoundToFormat to prevent rounding small values
   to 0 during slider interaction (as recommended by ImGui docs for
   logarithmic sliders with limited-precision formats)

Co-authored-by: chrxh <73127001+chrxh@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Feb 21, 2026

@copilot that is not the reason. still the same problem

You're right, the format string change wasn't the root cause. The actual issue is twofold:

  1. applyFormatToValue converts printf formats like "%.4f" into pre-formatted strings like "0.0001", stripping the % specifier. This causes ImGui's ImParseFormatPrecision to fall back to default precision 3, setting logarithmic_zero_epsilon=0.001 — so any value ≤ 0.001 gets snapped to 0 on logarithmic sliders.

  2. RoundScalarWithFormatT rounds values below the format precision to 0 during slider interaction.

New fix in 2cec2ea:

  • Return original printf format when tryMaintainFormat=true for floats (matching existing int behavior), so ImGui can correctly parse the precision
  • Add ImGuiSliderFlags_NoRoundToFormat to prevent rounding (as ImGui docs recommend for logarithmic sliders)

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.

2 participants