MCPcopy Create free account
hub / github.com/KebsCS/KBotExt / InputTextFilterCharacter

Function InputTextFilterCharacter

KBotExt/imgui/imgui_widgets.cpp:3905–4004  ·  view source on GitHub ↗

Return false to discard a character.

Source from the content-addressed store, hash-verified

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

Callers 1

InputTextExMethod · 0.85

Calls 1

ImCharIsBlankWFunction · 0.85

Tested by

no test coverage detected