mirror of
https://github.com/Drezil/imgui.git
synced 2025-07-06 04:58:47 +02:00
Demo: added casing swap demo to clarify use of ImGuiInputTextFlags_CallbackCharFilter. (#6457) + Metrics: simplified some code.
This commit is contained in:
@ -1390,7 +1390,15 @@ static void ShowDemoWindowWidgets()
|
||||
{
|
||||
struct TextFilters
|
||||
{
|
||||
// Return 0 (pass) if the character is 'i' or 'm' or 'g' or 'u' or 'i'
|
||||
// Modify character input by altering 'data->Eventchar' (ImGuiInputTextFlags_CallbackCharFilter callback)
|
||||
static int FilterCasingSwap(ImGuiInputTextCallbackData* data)
|
||||
{
|
||||
if (data->EventChar >= 'a' && data->EventChar <= 'z') { data->EventChar = data->EventChar - 'A' - 'a'; } // Lowercase becomes uppercase
|
||||
else if (data->EventChar >= 'A' && data->EventChar <= 'Z') { data->EventChar = data->EventChar + 'a' - 'A'; } // Uppercase becomes lowercase
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Return 0 (pass) if the character is 'i' or 'm' or 'g' or 'u' or 'i', otherwise return 1 (filter out)
|
||||
static int FilterImGuiLetters(ImGuiInputTextCallbackData* data)
|
||||
{
|
||||
if (data->EventChar < 256 && strchr("imgui", (char)data->EventChar))
|
||||
@ -1399,12 +1407,13 @@ static void ShowDemoWindowWidgets()
|
||||
}
|
||||
};
|
||||
|
||||
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 | ImGuiInputTextFlags_CharsUppercase);
|
||||
static char buf4[64] = ""; ImGui::InputText("uppercase", buf4, 64, ImGuiInputTextFlags_CharsUppercase);
|
||||
static char buf5[64] = ""; ImGui::InputText("no blank", buf5, 64, ImGuiInputTextFlags_CharsNoBlank);
|
||||
static char buf6[64] = ""; ImGui::InputText("\"imgui\" letters", buf6, 64, ImGuiInputTextFlags_CallbackCharFilter, TextFilters::FilterImGuiLetters);
|
||||
static char buf1[32] = ""; ImGui::InputText("default", buf1, 32);
|
||||
static char buf2[32] = ""; ImGui::InputText("decimal", buf2, 32, ImGuiInputTextFlags_CharsDecimal);
|
||||
static char buf3[32] = ""; ImGui::InputText("hexadecimal", buf3, 32, ImGuiInputTextFlags_CharsHexadecimal | ImGuiInputTextFlags_CharsUppercase);
|
||||
static char buf4[32] = ""; ImGui::InputText("uppercase", buf4, 32, ImGuiInputTextFlags_CharsUppercase);
|
||||
static char buf5[32] = ""; ImGui::InputText("no blank", buf5, 32, ImGuiInputTextFlags_CharsNoBlank);
|
||||
static char buf6[32] = ""; ImGui::InputText("casing swap", buf6, 32, ImGuiInputTextFlags_CallbackCharFilter, TextFilters::FilterCasingSwap); // Use CharFilter callback to replace characters.
|
||||
static char buf7[32] = ""; ImGui::InputText("\"imgui\"", buf7, 32, ImGuiInputTextFlags_CallbackCharFilter, TextFilters::FilterImGuiLetters); // Use CharFilter callback to disable some characters.
|
||||
ImGui::TreePop();
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user