mirror of
https://github.com/Drezil/imgui.git
synced 2024-11-22 11:57:00 +00:00
IO: Renamed InputCharacters[], marked internal as was always intended. AddInputCharacter() goes into a queue which can receive as many characters as needed during the frame. This is useful for automation to not have an upper limit on typing speed. Will later transition key/mouse to use the event queue later.
This commit is contained in:
parent
1705a81efb
commit
c3af134cc8
@ -70,6 +70,9 @@ Other Changes:
|
||||
- Error recovery: Missing calls to End(), pass the assert, should not lead to crashes or to the fallback Debug window
|
||||
appearing on screen, (#1651).
|
||||
- IO: Added BackendPlatformUserData, BackendRendererUserData, BackendLanguageUserData void* for storage use by back-ends.
|
||||
- IO: Renamed InputCharacters[], marked internal as was always intended. Please don't access directly, and use AddInputCharacter() instead!
|
||||
- IO: AddInputCharacter() goes into a queue which can receive as many characters as needed during the frame. This is useful
|
||||
for automation to not have an upper limit on typing speed. Will later transition key/mouse to use the event queue later.
|
||||
- Style: Tweaked default value of style.DisplayWindowPadding from (20,20) to (19,19) so the default style as a value
|
||||
which is the same as the title bar height.
|
||||
- Demo: "Simple Layout" and "Style Editor" are now using tabs.
|
||||
|
28
imgui.cpp
28
imgui.cpp
@ -363,6 +363,7 @@ CODE
|
||||
When you are not sure about a old symbol or function name, try using the Search/Find function of your IDE to look for comments or references in all imgui files.
|
||||
You can read releases logs https://github.com/ocornut/imgui/releases for more details.
|
||||
|
||||
- 2019/01/04 (1.67) - renamed io.InputCharacters[], marked internal as was always intended. Please don't access directly, and use AddInputCharacter() instead!
|
||||
- 2018/12/10 (1.67) - renamed io.ConfigResizeWindowsFromEdges to io.ConfigWindowsResizeFromEdges as we are doing a large pass on configuration flags.
|
||||
- 2018/10/12 (1.66) - renamed misc/stl/imgui_stl.* to misc/cpp/imgui_stdlib.* in prevision for other C++ helper files.
|
||||
- 2018/09/28 (1.66) - renamed SetScrollHere() to SetScrollHereY(). Kept redirection function (will obsolete).
|
||||
@ -1164,22 +1165,23 @@ ImGuiIO::ImGuiIO()
|
||||
// - on Windows you can get those using ToAscii+keyboard state, or via the WM_CHAR message
|
||||
void ImGuiIO::AddInputCharacter(ImWchar c)
|
||||
{
|
||||
const int n = ImStrlenW(InputCharacters);
|
||||
if (n + 1 < IM_ARRAYSIZE(InputCharacters))
|
||||
{
|
||||
InputCharacters[n] = c;
|
||||
InputCharacters[n+1] = '\0';
|
||||
}
|
||||
InputQueueCharacters.push_back(c);
|
||||
}
|
||||
|
||||
void ImGuiIO::AddInputCharactersUTF8(const char* utf8_chars)
|
||||
{
|
||||
// We can't pass more wchars than ImGuiIO::InputCharacters[] can hold so don't convert more
|
||||
const int wchars_buf_len = sizeof(ImGuiIO::InputCharacters) / sizeof(ImWchar);
|
||||
ImWchar wchars[wchars_buf_len];
|
||||
ImTextStrFromUtf8(wchars, wchars_buf_len, utf8_chars, NULL);
|
||||
for (int i = 0; i < wchars_buf_len && wchars[i] != 0; i++)
|
||||
AddInputCharacter(wchars[i]);
|
||||
while (*utf8_chars != 0)
|
||||
{
|
||||
unsigned int c = 0;
|
||||
utf8_chars += ImTextCharFromUtf8(&c, utf8_chars, NULL);
|
||||
if (c > 0 && c <= 0xFFFF)
|
||||
InputQueueCharacters.push_back((ImWchar)c);
|
||||
}
|
||||
}
|
||||
|
||||
void ImGuiIO::ClearInputCharacters()
|
||||
{
|
||||
InputQueueCharacters.resize(0);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
@ -3713,7 +3715,7 @@ void ImGui::EndFrame()
|
||||
|
||||
// Clear Input data for next frame
|
||||
g.IO.MouseWheel = g.IO.MouseWheelH = 0.0f;
|
||||
memset(g.IO.InputCharacters, 0, sizeof(g.IO.InputCharacters));
|
||||
g.IO.InputQueueCharacters.resize(0);
|
||||
memset(g.IO.NavInputs, 0, sizeof(g.IO.NavInputs));
|
||||
}
|
||||
|
||||
|
8
imgui.h
8
imgui.h
@ -1353,13 +1353,12 @@ struct ImGuiIO
|
||||
bool KeyAlt; // Keyboard modifier pressed: Alt
|
||||
bool KeySuper; // Keyboard modifier pressed: Cmd/Super/Windows
|
||||
bool KeysDown[512]; // Keyboard keys that are pressed (ideally left in the "native" order your engine has access to keyboard keys, so you can use your own defines/enums for keys).
|
||||
ImWchar InputCharacters[16+1]; // List of characters input (translated by user from keypress+keyboard state). Fill using AddInputCharacter() helper.
|
||||
float NavInputs[ImGuiNavInput_COUNT]; // Gamepad inputs. Cleared back to zero by EndFrame(). Keyboard keys will be auto-mapped and be written here by NewFrame().
|
||||
|
||||
// Functions
|
||||
IMGUI_API void AddInputCharacter(ImWchar c); // Add new character into InputCharacters[]
|
||||
IMGUI_API void AddInputCharactersUTF8(const char* utf8_chars); // Add new characters into InputCharacters[] from an UTF-8 string
|
||||
inline void ClearInputCharacters() { InputCharacters[0] = 0; } // Clear the text input buffer manually
|
||||
IMGUI_API void AddInputCharacter(ImWchar c); // Queue new character input
|
||||
IMGUI_API void AddInputCharactersUTF8(const char* str); // Queue new characters input from an UTF-8 string
|
||||
IMGUI_API void ClearInputCharacters(); // Clear the text input buffer manually
|
||||
|
||||
//------------------------------------------------------------------
|
||||
// Output - Retrieve after calling NewFrame()
|
||||
@ -1399,6 +1398,7 @@ struct ImGuiIO
|
||||
float KeysDownDurationPrev[512]; // Previous duration the key has been down
|
||||
float NavInputsDownDuration[ImGuiNavInput_COUNT];
|
||||
float NavInputsDownDurationPrev[ImGuiNavInput_COUNT];
|
||||
ImVector<ImWchar> InputQueueCharacters; // Queue of _characters_ input (obtained by platform back-end). Fill using AddInputCharacter() helper.
|
||||
|
||||
IMGUI_API ImGuiIO();
|
||||
};
|
||||
|
@ -3127,7 +3127,7 @@ bool ImGui::InputTextEx(const char* label, char* buf, int buf_size, const ImVec2
|
||||
IM_ASSERT(!((flags & ImGuiInputTextFlags_CallbackCompletion) && (flags & ImGuiInputTextFlags_AllowTabInput))); // Can't use both together (they both use tab key)
|
||||
|
||||
ImGuiContext& g = *GImGui;
|
||||
const ImGuiIO& io = g.IO;
|
||||
ImGuiIO& io = g.IO;
|
||||
const ImGuiStyle& style = g.Style;
|
||||
|
||||
const bool is_multiline = (flags & ImGuiInputTextFlags_Multiline) != 0;
|
||||
@ -3312,22 +3312,22 @@ bool ImGui::InputTextEx(const char* label, char* buf, int buf_size, const ImVec2
|
||||
if (edit_state.SelectedAllMouseLock && !io.MouseDown[0])
|
||||
edit_state.SelectedAllMouseLock = false;
|
||||
|
||||
if (io.InputCharacters[0])
|
||||
if (io.InputQueueCharacters.Size > 0)
|
||||
{
|
||||
// Process text input (before we check for Return because using some IME will effectively send a Return?)
|
||||
// We ignore CTRL inputs, but need to allow ALT+CTRL as some keyboards (e.g. German) use AltGR (which _is_ Alt+Ctrl) to input certain characters.
|
||||
bool ignore_inputs = (io.KeyCtrl && !io.KeyAlt) || (is_osx && io.KeySuper);
|
||||
if (!ignore_inputs && is_editable && !user_nav_input_start)
|
||||
for (int n = 0; n < IM_ARRAYSIZE(io.InputCharacters) && io.InputCharacters[n]; n++)
|
||||
for (int n = 0; n < io.InputQueueCharacters.Size; n++)
|
||||
{
|
||||
// Insert character if they pass filtering
|
||||
unsigned int c = (unsigned int)io.InputCharacters[n];
|
||||
unsigned int c = (unsigned int)io.InputQueueCharacters[n];
|
||||
if (InputTextFilterCharacter(&c, flags, callback, callback_user_data))
|
||||
edit_state.OnKeyPressed((int)c);
|
||||
}
|
||||
|
||||
// Consume characters
|
||||
memset(g.IO.InputCharacters, 0, sizeof(g.IO.InputCharacters));
|
||||
io.InputQueueCharacters.resize(0);
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user