Skip to content

Commit 4a24264

Browse files
committed
Drags, Sliders, Inputs: removed all attempts to filter non-numerical characters during text editing. (#6810, #7096)
1 parent f039e69 commit 4a24264

File tree

2 files changed

+3
-15
lines changed

2 files changed

+3
-15
lines changed

docs/CHANGELOG.txt

+2
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,8 @@ Other changes:
7070
- InputTextMultiline: Tabbing through a multi-line text editor which allows Tab character inputs
7171
(using the ImGuiInputTextFlags_AllowTabInput flag) doesn't automatically activate it, in order
7272
to allow passing through multiple widgets easily. (#3092, #5759, #787)
73+
- Drags, Sliders, Inputs: removed all attempts to filter non-numerical characters during text
74+
editing. Invalid inputs not applied to value, visibly reverted after validation. (#6810, #7096)
7375
- DragScalarN, SliderScalarN, InputScalarN, PushMultiItemsWidths: improve multi-components
7476
width computation to better distribute the error. (#7120, #7121) [@Nahor]
7577
- ColorEdit4: Layout tweaks for very small sizes. (#7120, #7121)

imgui_widgets.cpp

+1-15
Original file line numberDiff line numberDiff line change
@@ -3395,14 +3395,6 @@ bool ImGui::TempInputText(const ImRect& bb, ImGuiID id, const char* label, char*
33953395
return value_changed;
33963396
}
33973397

3398-
static inline ImGuiInputTextFlags InputScalar_DefaultCharsFilter(ImGuiDataType data_type, const char* format)
3399-
{
3400-
if (data_type == ImGuiDataType_Float || data_type == ImGuiDataType_Double)
3401-
return ImGuiInputTextFlags_CharsScientific;
3402-
const char format_last_char = format[0] ? format[strlen(format) - 1] : 0;
3403-
return (format_last_char == 'x' || format_last_char == 'X') ? ImGuiInputTextFlags_CharsHexadecimal : ImGuiInputTextFlags_CharsDecimal;
3404-
}
3405-
34063398
// Note that Drag/Slider functions are only forwarding the min/max values clamping values if the ImGuiSliderFlags_AlwaysClamp flag is set!
34073399
// This is intended: this way we allow CTRL+Click manual input to set a value out of bounds, for maximum flexibility.
34083400
// However this may not be ideal for all uses, as some user code may break on out of bound values.
@@ -3420,7 +3412,6 @@ bool ImGui::TempInputScalar(const ImRect& bb, ImGuiID id, const char* label, ImG
34203412
ImStrTrimBlanks(data_buf);
34213413

34223414
ImGuiInputTextFlags flags = ImGuiInputTextFlags_AutoSelectAll | (ImGuiInputTextFlags)ImGuiInputTextFlags_NoMarkEdited;
3423-
flags |= InputScalar_DefaultCharsFilter(data_type, format);
34243415

34253416
bool value_changed = false;
34263417
if (TempInputText(bb, id, label, data_buf, IM_ARRAYSIZE(data_buf), flags))
@@ -3464,9 +3455,6 @@ bool ImGui::InputScalar(const char* label, ImGuiDataType data_type, void* p_data
34643455
char buf[64];
34653456
DataTypeFormatString(buf, IM_ARRAYSIZE(buf), data_type, p_data, format);
34663457

3467-
// Testing ActiveId as a minor optimization as filtering is not needed until active
3468-
if (g.ActiveId == 0 && (flags & (ImGuiInputTextFlags_CharsDecimal | ImGuiInputTextFlags_CharsHexadecimal | ImGuiInputTextFlags_CharsScientific)) == 0)
3469-
flags |= InputScalar_DefaultCharsFilter(data_type, format);
34703458
flags |= ImGuiInputTextFlags_AutoSelectAll | (ImGuiInputTextFlags)ImGuiInputTextFlags_NoMarkEdited; // We call MarkItemEdited() ourselves by comparing the actual data rather than the string.
34713459

34723460
bool value_changed = false;
@@ -3561,7 +3549,6 @@ bool ImGui::InputScalarN(const char* label, ImGuiDataType data_type, void* p_dat
35613549

35623550
bool ImGui::InputFloat(const char* label, float* v, float step, float step_fast, const char* format, ImGuiInputTextFlags flags)
35633551
{
3564-
flags |= ImGuiInputTextFlags_CharsScientific;
35653552
return InputScalar(label, ImGuiDataType_Float, (void*)v, (void*)(step > 0.0f ? &step : NULL), (void*)(step_fast > 0.0f ? &step_fast : NULL), format, flags);
35663553
}
35673554

@@ -3604,7 +3591,6 @@ bool ImGui::InputInt4(const char* label, int v[4], ImGuiInputTextFlags flags)
36043591

36053592
bool ImGui::InputDouble(const char* label, double* v, double step, double step_fast, const char* format, ImGuiInputTextFlags flags)
36063593
{
3607-
flags |= ImGuiInputTextFlags_CharsScientific;
36083594
return InputScalar(label, ImGuiDataType_Double, (void*)v, (void*)(step > 0.0 ? &step : NULL), (void*)(step_fast > 0.0 ? &step_fast : NULL), format, flags);
36093595
}
36103596

@@ -5238,7 +5224,7 @@ bool ImGui::ColorEdit4(const char* label, float col[4], ImGuiColorEditFlags flag
52385224
else
52395225
ImFormatString(buf, IM_ARRAYSIZE(buf), "#%02X%02X%02X", ImClamp(i[0], 0, 255), ImClamp(i[1], 0, 255), ImClamp(i[2], 0, 255));
52405226
SetNextItemWidth(w_inputs);
5241-
if (InputText("##Text", buf, IM_ARRAYSIZE(buf), ImGuiInputTextFlags_CharsHexadecimal | ImGuiInputTextFlags_CharsUppercase))
5227+
if (InputText("##Text", buf, IM_ARRAYSIZE(buf), ImGuiInputTextFlags_CharsUppercase))
52425228
{
52435229
value_changed = true;
52445230
char* p = buf;

0 commit comments

Comments
 (0)