Fix SliderFloat resetting small values (below 0.001) to zero#474
Draft
Fix SliderFloat resetting small values (below 0.001) to zero#474
Conversation
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
Owner
|
@copilot that is not the reason. still the same problem |
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>
Contributor
Author
You're right, the format string change wasn't the root cause. The actual issue is twofold:
New fix in 2cec2ea:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
applyFormatToValueconverts printf format strings (e.g.,"%.4f") into pre-formatted literal strings (e.g.,"0.0001"), stripping the%specifier. This causes two problems in ImGui:ImParseFormatPrecisionfalls back to default precision 3 when it finds no%, settinglogarithmic_zero_epsilon = 0.001. On logarithmic sliders withmin=0, any value ≤ 0.001 gets a ratio of 0 and snaps tov_min(0) on interaction.RoundScalarWithFormatTrounds slider values to the format's precision during interaction. With"%.3f", any value below 0.001 rounds to 0.Fix
Two changes in
BasicSlider:Pass original printf format to ImGui: When
tryMaintainFormat=truefor floats, return the original format string (e.g.,"%.4f") instead of a pre-formatted literal. This matches the existing behavior forinttypes and allows ImGui to correctly parse the precision for logarithmic epsilon calculation.Add
ImGuiSliderFlags_NoRoundToFormat: PreventsRoundScalarWithFormatTfrom 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.tryMaintainFormat=falsepath (e.g., collapsed color-dependent range display)💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.