MCPcopy Create free account
hub / github.com/TurningWheel/Barony / InputTextFilterCharacter

Function InputTextFilterCharacter

src/imgui/imgui_widgets.cpp:3828–3923  ·  view source on GitHub ↗

Return false to discard a character.

Source from the content-addressed store, hash-verified

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

Callers 1

InputTextExMethod · 0.85

Calls 1

ImCharIsBlankWFunction · 0.85

Tested by

no test coverage detected