mirror of
https://github.com/Drezil/imgui.git
synced 2024-11-26 13:37:00 +00:00
Added ImGuiInputTextFlags_CharsUppercase stock filter
This commit is contained in:
parent
9473cd491e
commit
b73484a66b
28
imgui.cpp
28
imgui.cpp
@ -5243,6 +5243,10 @@ static bool InputTextFilterCharacter(unsigned int* p_char, ImGuiInputTextFlags f
|
||||
if (!(c >= '0' && c <= '9') && !(c >= 'a' && c <= 'f') && !(c >= 'A' && c <= 'F'))
|
||||
return false;
|
||||
|
||||
if (flags & ImGuiInputTextFlags_CharsUppercase)
|
||||
if (c >= 'a' && c <= 'z')
|
||||
*p_char = (c += 'A'-'a');
|
||||
|
||||
if (flags & ImGuiInputTextFlags_CallbackCharFilter)
|
||||
{
|
||||
ImGuiTextEditCallbackData callback_data;
|
||||
@ -8346,26 +8350,10 @@ void ImGui::ShowTestWindow(bool* opened)
|
||||
{
|
||||
static char buf1[64] = ""; ImGui::InputText("default", buf1, 64);
|
||||
static char buf2[64] = ""; ImGui::InputText("decimal", buf2, 64, ImGuiInputTextFlags_CharsDecimal);
|
||||
static char buf3[64] = ""; ImGui::InputText("hexadecimal", buf3, 64, ImGuiInputTextFlags_CharsHexadecimal);
|
||||
struct TextFilters
|
||||
{
|
||||
static int FilterAZ(ImGuiTextEditCallbackData* data)
|
||||
{
|
||||
const ImWchar c = data->EventChar;
|
||||
if (!((c >= 'a' && c <= 'z') || c >= 'A' && c <= 'Z'))
|
||||
data->EventChar = 0;
|
||||
return 0;
|
||||
}
|
||||
static int FilterUppercase(ImGuiTextEditCallbackData* data)
|
||||
{
|
||||
const ImWchar c = data->EventChar;
|
||||
if (c >= 'a' && c <= 'z')
|
||||
data->EventChar += 'A'-'a';
|
||||
return 0;
|
||||
}
|
||||
};
|
||||
static char buf4[64] = ""; ImGui::InputText("a-z only", buf4, 64, ImGuiInputTextFlags_CallbackCharFilter, TextFilters::FilterAZ);
|
||||
static char buf5[64] = ""; ImGui::InputText("uppercase", buf5, 64, ImGuiInputTextFlags_CallbackCharFilter, TextFilters::FilterUppercase);
|
||||
static char buf3[64] = ""; ImGui::InputText("hexadecimal", buf3, 64, ImGuiInputTextFlags_CharsHexadecimal | ImGuiInputTextFlags_CharsUppercase);
|
||||
static char buf4[64] = ""; ImGui::InputText("uppercase", buf4, 64, ImGuiInputTextFlags_CharsUppercase);
|
||||
struct TextFilters { static int FilterNoSpace(ImGuiTextEditCallbackData* data) { if (data->EventChar == ' ') data->EventChar = 0; return 0; } };
|
||||
static char buf5[64] = ""; ImGui::InputText("custom: no spaces", buf5, 64, ImGuiInputTextFlags_CallbackCharFilter, TextFilters::FilterNoSpace);
|
||||
ImGui::TreePop();
|
||||
}
|
||||
|
||||
|
13
imgui.h
13
imgui.h
@ -388,12 +388,13 @@ enum ImGuiInputTextFlags_
|
||||
// Default: 0
|
||||
ImGuiInputTextFlags_CharsDecimal = 1 << 0, // Allow 0123456789.+-*/
|
||||
ImGuiInputTextFlags_CharsHexadecimal = 1 << 1, // Allow 0123456789ABCDEFabcdef
|
||||
ImGuiInputTextFlags_AutoSelectAll = 1 << 2, // Select entire text when first taking focus
|
||||
ImGuiInputTextFlags_EnterReturnsTrue = 1 << 3, // Return 'true' when Enter is pressed (as opposed to when the value was modified)
|
||||
ImGuiInputTextFlags_CallbackCompletion = 1 << 4, // Call user function on pressing TAB (for completion handling)
|
||||
ImGuiInputTextFlags_CallbackHistory = 1 << 5, // Call user function on pressing Up/Down arrows (for history handling)
|
||||
ImGuiInputTextFlags_CallbackAlways = 1 << 6, // Call user function every time
|
||||
ImGuiInputTextFlags_CallbackCharFilter = 1 << 7 // Call user function to filter character. Modify data->EventChar to replace/filter input.
|
||||
ImGuiInputTextFlags_CharsUppercase = 1 << 2, // Turn a..z into A..Z
|
||||
ImGuiInputTextFlags_AutoSelectAll = 1 << 3, // Select entire text when first taking focus
|
||||
ImGuiInputTextFlags_EnterReturnsTrue = 1 << 4, // Return 'true' when Enter is pressed (as opposed to when the value was modified)
|
||||
ImGuiInputTextFlags_CallbackCompletion = 1 << 5, // Call user function on pressing TAB (for completion handling)
|
||||
ImGuiInputTextFlags_CallbackHistory = 1 << 6, // Call user function on pressing Up/Down arrows (for history handling)
|
||||
ImGuiInputTextFlags_CallbackAlways = 1 << 7, // Call user function every time
|
||||
ImGuiInputTextFlags_CallbackCharFilter = 1 << 8 // Call user function to filter character. Modify data->EventChar to replace/filter input.
|
||||
//ImGuiInputTextFlags_AlignCenter = 1 << 6,
|
||||
};
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user