MCPcopy Create free account
hub / github.com/antopilo/Nuake / InputTextFilterCharacter

Function InputTextFilterCharacter

Nuake/Vendors/imgui/imgui_widgets.cpp:3925–4023  ·  view source on GitHub ↗

Return false to discard a character.

Source from the content-addressed store, hash-verified

3923
3924// Return false to discard a character.
3925static bool InputTextFilterCharacter(ImGuiContext* ctx, unsigned int* p_char, ImGuiInputTextFlags flags, ImGuiInputTextCallback callback, void* user_data, bool input_source_is_clipboard)
3926{
3927 unsigned int c = *p_char;
3928
3929 // Filter non-printable (NB: isprint is unreliable! see #2467)
3930 bool apply_named_filters = true;
3931 if (c < 0x20)
3932 {
3933 bool pass = false;
3934 pass |= (c == '\n') && (flags & ImGuiInputTextFlags_Multiline) != 0; // Note that an Enter KEY will emit \r and be ignored (we poll for KEY in InputText() code)
3935 pass |= (c == '\t') && (flags & ImGuiInputTextFlags_AllowTabInput) != 0;
3936 if (!pass)
3937 return false;
3938 apply_named_filters = false; // Override named filters below so newline and tabs can still be inserted.
3939 }
3940
3941 if (input_source_is_clipboard == false)
3942 {
3943 // We ignore Ascii representation of delete (emitted from Backspace on OSX, see #2578, #2817)
3944 if (c == 127)
3945 return false;
3946
3947 // Filter private Unicode range. GLFW on OSX seems to send private characters for special keys like arrow keys (FIXME)
3948 if (c >= 0xE000 && c <= 0xF8FF)
3949 return false;
3950 }
3951
3952 // Filter Unicode ranges we are not handling in this build
3953 if (c > IM_UNICODE_CODEPOINT_MAX)
3954 return false;
3955
3956 // Generic named filters
3957 if (apply_named_filters && (flags & (ImGuiInputTextFlags_CharsDecimal | ImGuiInputTextFlags_CharsHexadecimal | ImGuiInputTextFlags_CharsUppercase | ImGuiInputTextFlags_CharsNoBlank | ImGuiInputTextFlags_CharsScientific)))
3958 {
3959 // 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 '.'.
3960 // The standard mandate that programs starts in the "C" locale where the decimal point is '.'.
3961 // 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.
3962 // Change the default decimal_point with:
3963 // ImGui::GetIO()->PlatformLocaleDecimalPoint = *localeconv()->decimal_point;
3964 // 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.
3965 ImGuiContext& g = *ctx;
3966 const unsigned c_decimal_point = (unsigned int)g.IO.PlatformLocaleDecimalPoint;
3967 if (flags & (ImGuiInputTextFlags_CharsDecimal | ImGuiInputTextFlags_CharsScientific))
3968 if (c == '.' || c == ',')
3969 c = c_decimal_point;
3970
3971 // Full-width -> half-width conversion for numeric fields (https://en.wikipedia.org/wiki/Halfwidth_and_Fullwidth_Forms_(Unicode_block)
3972 // While this is mostly convenient, this has the side-effect for uninformed users accidentally inputting full-width characters that they may
3973 // scratch their head as to why it works in numerical fields vs in generic text fields it would require support in the font.
3974 if (flags & (ImGuiInputTextFlags_CharsDecimal | ImGuiInputTextFlags_CharsScientific | ImGuiInputTextFlags_CharsHexadecimal))
3975 if (c >= 0xFF01 && c <= 0xFF5E)
3976 c = c - 0xFF01 + 0x21;
3977
3978 // Allow 0-9 . - + * /
3979 if (flags & ImGuiInputTextFlags_CharsDecimal)
3980 if (!(c >= '0' && c <= '9') && (c != c_decimal_point) && (c != '-') && (c != '+') && (c != '*') && (c != '/'))
3981 return false;
3982

Callers 1

InputTextExMethod · 0.85

Calls 1

ImCharIsBlankWFunction · 0.85

Tested by

no test coverage detected