MCPcopy Create free account
hub / github.com/ShenCiao/CialloResearch / InputTextFilterCharacter

Function InputTextFilterCharacter

imgui/imgui_widgets.cpp:3808–3903  ·  view source on GitHub ↗

Return false to discard a character.

Source from the content-addressed store, hash-verified

3806
3807// Return false to discard a character.
3808static bool InputTextFilterCharacter(unsigned int* p_char, ImGuiInputTextFlags flags, ImGuiInputTextCallback callback, void* user_data, ImGuiInputSource input_source)
3809{
3810 IM_ASSERT(input_source == ImGuiInputSource_Keyboard || input_source == ImGuiInputSource_Clipboard);
3811 unsigned int c = *p_char;
3812
3813 // Filter non-printable (NB: isprint is unreliable! see #2467)
3814 bool apply_named_filters = true;
3815 if (c < 0x20)
3816 {
3817 bool pass = false;
3818 pass |= (c == '\n' && (flags & ImGuiInputTextFlags_Multiline)); // Note that an Enter KEY will emit \r and be ignored (we poll for KEY in InputText() code)
3819 pass |= (c == '\t' && (flags & ImGuiInputTextFlags_AllowTabInput));
3820 if (!pass)
3821 return false;
3822 apply_named_filters = false; // Override named filters below so newline and tabs can still be inserted.
3823 }
3824
3825 if (input_source != ImGuiInputSource_Clipboard)
3826 {
3827 // We ignore Ascii representation of delete (emitted from Backspace on OSX, see #2578, #2817)
3828 if (c == 127)
3829 return false;
3830
3831 // Filter private Unicode range. GLFW on OSX seems to send private characters for special keys like arrow keys (FIXME)
3832 if (c >= 0xE000 && c <= 0xF8FF)
3833 return false;
3834 }
3835
3836 // Filter Unicode ranges we are not handling in this build
3837 if (c > IM_UNICODE_CODEPOINT_MAX)
3838 return false;
3839
3840 // Generic named filters
3841 if (apply_named_filters && (flags & (ImGuiInputTextFlags_CharsDecimal | ImGuiInputTextFlags_CharsHexadecimal | ImGuiInputTextFlags_CharsUppercase | ImGuiInputTextFlags_CharsNoBlank | ImGuiInputTextFlags_CharsScientific)))
3842 {
3843 // 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 '.'.
3844 // The standard mandate that programs starts in the "C" locale where the decimal point is '.'.
3845 // 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.
3846 // Change the default decimal_point with:
3847 // ImGui::GetCurrentContext()->PlatformLocaleDecimalPoint = *localeconv()->decimal_point;
3848 // 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.
3849 ImGuiContext& g = *GImGui;
3850 const unsigned c_decimal_point = (unsigned int)g.PlatformLocaleDecimalPoint;
3851
3852 // Full-width -> half-width conversion for numeric fields (https://en.wikipedia.org/wiki/Halfwidth_and_Fullwidth_Forms_(Unicode_block)
3853 // While this is mostly convenient, this has the side-effect for uninformed users accidentally inputting full-width characters that they may
3854 // scratch their head as to why it works in numerical fields vs in generic text fields it would require support in the font.
3855 if (flags & (ImGuiInputTextFlags_CharsDecimal | ImGuiInputTextFlags_CharsScientific | ImGuiInputTextFlags_CharsHexadecimal))
3856 if (c >= 0xFF01 && c <= 0xFF5E)
3857 c = c - 0xFF01 + 0x21;
3858
3859 // Allow 0-9 . - + * /
3860 if (flags & ImGuiInputTextFlags_CharsDecimal)
3861 if (!(c >= '0' && c <= '9') && (c != c_decimal_point) && (c != '-') && (c != '+') && (c != '*') && (c != '/'))
3862 return false;
3863
3864 // Allow 0-9 . - + * / e E
3865 if (flags & ImGuiInputTextFlags_CharsScientific)

Callers 1

InputTextExMethod · 0.85

Calls 1

ImCharIsBlankWFunction · 0.85

Tested by

no test coverage detected