MCPcopy Create free account
hub / github.com/BoomingTech/Piccolo / InputTextFilterCharacter

Function InputTextFilterCharacter

engine/3rdparty/imgui/imgui_widgets.cpp:3869–3955  ·  view source on GitHub ↗

Return false to discard a character.

Source from the content-addressed store, hash-verified

3867
3868// Return false to discard a character.
3869static bool InputTextFilterCharacter(unsigned int* p_char, ImGuiInputTextFlags flags, ImGuiInputTextCallback callback, void* user_data, ImGuiInputSource input_source)
3870{
3871 IM_ASSERT(input_source == ImGuiInputSource_Keyboard || input_source == ImGuiInputSource_Clipboard);
3872 unsigned int c = *p_char;
3873
3874 // Filter non-printable (NB: isprint is unreliable! see #2467)
3875 bool apply_named_filters = true;
3876 if (c < 0x20)
3877 {
3878 bool pass = false;
3879 pass |= (c == '\n' && (flags & ImGuiInputTextFlags_Multiline));
3880 pass |= (c == '\t' && (flags & ImGuiInputTextFlags_AllowTabInput));
3881 if (!pass)
3882 return false;
3883 apply_named_filters = false; // Override named filters below so newline and tabs can still be inserted.
3884 }
3885
3886 if (input_source != ImGuiInputSource_Clipboard)
3887 {
3888 // We ignore Ascii representation of delete (emitted from Backspace on OSX, see #2578, #2817)
3889 if (c == 127)
3890 return false;
3891
3892 // Filter private Unicode range. GLFW on OSX seems to send private characters for special keys like arrow keys (FIXME)
3893 if (c >= 0xE000 && c <= 0xF8FF)
3894 return false;
3895 }
3896
3897 // Filter Unicode ranges we are not handling in this build
3898 if (c > IM_UNICODE_CODEPOINT_MAX)
3899 return false;
3900
3901 // Generic named filters
3902 if (apply_named_filters && (flags & (ImGuiInputTextFlags_CharsDecimal | ImGuiInputTextFlags_CharsHexadecimal | ImGuiInputTextFlags_CharsUppercase | ImGuiInputTextFlags_CharsNoBlank | ImGuiInputTextFlags_CharsScientific)))
3903 {
3904 // The libc allows overriding locale, with e.g. 'setlocale(LC_NUMERIC, "de_DE.UTF-8");' which affect the output/input of printf/scanf to use e.g. ',' instead of '.'.
3905 // The standard mandate that programs starts in the "C" locale where the decimal point is '.'.
3906 // 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.
3907 // Change the default decimal_point with:
3908 // ImGui::GetCurrentContext()->PlatformLocaleDecimalPoint = *localeconv()->decimal_point;
3909 // Users of non-default decimal point (in particular ',') may be affected by word-selection logic (is_word_boundary_from_right/is_word_boundary_from_left) functions.
3910 ImGuiContext& g = *GImGui;
3911 const unsigned c_decimal_point = (unsigned int)g.PlatformLocaleDecimalPoint;
3912
3913 // Allow 0-9 . - + * /
3914 if (flags & ImGuiInputTextFlags_CharsDecimal)
3915 if (!(c >= '0' && c <= '9') && (c != c_decimal_point) && (c != '-') && (c != '+') && (c != '*') && (c != '/'))
3916 return false;
3917
3918 // Allow 0-9 . - + * / e E
3919 if (flags & ImGuiInputTextFlags_CharsScientific)
3920 if (!(c >= '0' && c <= '9') && (c != c_decimal_point) && (c != '-') && (c != '+') && (c != '*') && (c != '/') && (c != 'e') && (c != 'E'))
3921 return false;
3922
3923 // Allow 0-9 a-F A-F
3924 if (flags & ImGuiInputTextFlags_CharsHexadecimal)
3925 if (!(c >= '0' && c <= '9') && !(c >= 'a' && c <= 'f') && !(c >= 'A' && c <= 'F'))
3926 return false;

Callers 1

InputTextExMethod · 0.85

Calls 1

ImCharIsBlankWFunction · 0.85

Tested by

no test coverage detected