MCPcopy Create free account
hub / github.com/dartsim/dart / InputTextFilterCharacter

Function InputTextFilterCharacter

dart/external/imgui/imgui_widgets.cpp:3839–3924  ·  view source on GitHub ↗

Return false to discard a character.

Source from the content-addressed store, hash-verified

3837
3838// Return false to discard a character.
3839static bool InputTextFilterCharacter(unsigned int* p_char, ImGuiInputTextFlags flags, ImGuiInputTextCallback callback, void* user_data, ImGuiInputSource input_source)
3840{
3841 IM_ASSERT(input_source == ImGuiInputSource_Keyboard || input_source == ImGuiInputSource_Clipboard);
3842 unsigned int c = *p_char;
3843
3844 // Filter non-printable (NB: isprint is unreliable! see #2467)
3845 bool apply_named_filters = true;
3846 if (c < 0x20)
3847 {
3848 bool pass = false;
3849 pass |= (c == '\n' && (flags & ImGuiInputTextFlags_Multiline));
3850 pass |= (c == '\t' && (flags & ImGuiInputTextFlags_AllowTabInput));
3851 if (!pass)
3852 return false;
3853 apply_named_filters = false; // Override named filters below so newline and tabs can still be inserted.
3854 }
3855
3856 if (input_source != ImGuiInputSource_Clipboard)
3857 {
3858 // We ignore Ascii representation of delete (emitted from Backspace on OSX, see #2578, #2817)
3859 if (c == 127)
3860 return false;
3861
3862 // Filter private Unicode range. GLFW on OSX seems to send private characters for special keys like arrow keys (FIXME)
3863 if (c >= 0xE000 && c <= 0xF8FF)
3864 return false;
3865 }
3866
3867 // Filter Unicode ranges we are not handling in this build
3868 if (c > IM_UNICODE_CODEPOINT_MAX)
3869 return false;
3870
3871 // Generic named filters
3872 if (apply_named_filters && (flags & (ImGuiInputTextFlags_CharsDecimal | ImGuiInputTextFlags_CharsHexadecimal | ImGuiInputTextFlags_CharsUppercase | ImGuiInputTextFlags_CharsNoBlank | ImGuiInputTextFlags_CharsScientific)))
3873 {
3874 // The libc allows overriding locale, with e.g. 'setlocale(LC_NUMERIC, "de_DE.UTF-8");' which affect the output/input of printf/scanf.
3875 // The standard mandate that programs starts in the "C" locale where the decimal point is '.'.
3876 // We don't really intend to provide widespread support for it, but out of empathy for people stuck with using odd API, we support the bare minimum aka overriding the decimal point.
3877 // Change the default decimal_point with:
3878 // ImGui::GetCurrentContext()->PlatformLocaleDecimalPoint = *localeconv()->decimal_point;
3879 ImGuiContext& g = *GImGui;
3880 const unsigned c_decimal_point = (unsigned int)g.PlatformLocaleDecimalPoint;
3881
3882 // Allow 0-9 . - + * /
3883 if (flags & ImGuiInputTextFlags_CharsDecimal)
3884 if (!(c >= '0' && c <= '9') && (c != c_decimal_point) && (c != '-') && (c != '+') && (c != '*') && (c != '/'))
3885 return false;
3886
3887 // Allow 0-9 . - + * / e E
3888 if (flags & ImGuiInputTextFlags_CharsScientific)
3889 if (!(c >= '0' && c <= '9') && (c != c_decimal_point) && (c != '-') && (c != '+') && (c != '*') && (c != '/') && (c != 'e') && (c != 'E'))
3890 return false;
3891
3892 // Allow 0-9 a-F A-F
3893 if (flags & ImGuiInputTextFlags_CharsHexadecimal)
3894 if (!(c >= '0' && c <= '9') && !(c >= 'a' && c <= 'f') && !(c >= 'A' && c <= 'F'))
3895 return false;
3896

Callers 1

InputTextExMethod · 0.85

Calls 1

ImCharIsBlankWFunction · 0.85

Tested by

no test coverage detected