mirror of
https://github.com/Drezil/imgui.git
synced 2024-11-14 17:07:01 +00:00
InputText: numerical fields automatically accept full-width characters (U+FF01..U+FF5E) by converting them to half-width (U+0021..U+007E).
This commit is contained in:
parent
a396233cb6
commit
268565079c
@ -65,6 +65,8 @@ Other Changes:
|
||||
|
||||
- InputText: added experimental io.ConfigInputTextEnterKeepActive feature to make pressing
|
||||
Enter keep the input active and select all text.
|
||||
- InputText: numerical fields automatically accept full-width characters (U+FF01..U+FF5E)
|
||||
by converting them to half-width (U+0021..U+007E).
|
||||
- Tables,Columns: fixed a layout issue where SameLine() prior to a row change would set the
|
||||
next row in such state where subsequent SameLine() would move back to previous row.
|
||||
- Tabs: Fixed a crash when closing multiple windows (possible with docking only) with an
|
||||
|
@ -3923,6 +3923,13 @@ static bool InputTextFilterCharacter(unsigned int* p_char, ImGuiInputTextFlags f
|
||||
ImGuiContext& g = *GImGui;
|
||||
const unsigned c_decimal_point = (unsigned int)g.PlatformLocaleDecimalPoint;
|
||||
|
||||
// Full-width -> half-width conversion for numeric fields (https://en.wikipedia.org/wiki/Halfwidth_and_Fullwidth_Forms_(Unicode_block)
|
||||
// While this is mostly convenient, this has the side-effect for uninformed users accidentally inputting full-width characters that they may
|
||||
// scratch their head as to why it works in numerical fields vs in generic text fields it would require support in the font.
|
||||
if (flags & (ImGuiInputTextFlags_CharsDecimal | ImGuiInputTextFlags_CharsScientific | ImGuiInputTextFlags_CharsHexadecimal))
|
||||
if (c >= 0xFF01 && c <= 0xFF5E)
|
||||
c = c - 0xFF01 + 0x21;
|
||||
|
||||
// Allow 0-9 . - + * /
|
||||
if (flags & ImGuiInputTextFlags_CharsDecimal)
|
||||
if (!(c >= '0' && c <= '9') && (c != c_decimal_point) && (c != '-') && (c != '+') && (c != '*') && (c != '/'))
|
||||
@ -3941,11 +3948,13 @@ static bool InputTextFilterCharacter(unsigned int* p_char, ImGuiInputTextFlags f
|
||||
// Turn a-z into A-Z
|
||||
if (flags & ImGuiInputTextFlags_CharsUppercase)
|
||||
if (c >= 'a' && c <= 'z')
|
||||
*p_char = (c += (unsigned int)('A' - 'a'));
|
||||
c += (unsigned int)('A' - 'a');
|
||||
|
||||
if (flags & ImGuiInputTextFlags_CharsNoBlank)
|
||||
if (ImCharIsBlankW(c))
|
||||
return false;
|
||||
|
||||
*p_char = c;
|
||||
}
|
||||
|
||||
// Custom callback filter
|
||||
|
Loading…
Reference in New Issue
Block a user