diff --git a/docs/CHANGELOG.txt b/docs/CHANGELOG.txt index afa1d5534..4324c69ef 100644 --- a/docs/CHANGELOG.txt +++ b/docs/CHANGELOG.txt @@ -155,9 +155,9 @@ Other Changes: next to each components, in multi-components functions. - Added a way to select a specific marker color. - InputText: - - Made ImGuiInputTextCallbackData::SelectAll() also sets CursorPos to SelectionEnd. - - Added ImGuiInputTextCallbackData::SetSelection() helper. - - Added ImGuiInputTextCallbackData::ID field. + - ImGuiInputTextCallbackData: SelectAll() also sets CursorPos to SelectionEnd. + - ImGuiInputTextCallbackData: Added SetSelection() helper. + - ImGuiInputTextCallbackData: Added ID and EventActive helpers. (#9174) - Text, InputText: - Reworked word-wrapping logic: - Try to not wrap in the middle of contiguous punctuations. (#8139, #8439, #9094) diff --git a/imgui.h b/imgui.h index 01e5113d7..4a9af9b7a 100644 --- a/imgui.h +++ b/imgui.h @@ -2638,6 +2638,7 @@ struct ImGuiInputTextCallbackData // - If you know your edits are not going to resize the underlying buffer allocation, you may modify the contents of 'Buf[]' directly. You need to update 'BufTextLen' accordingly (0 <= BufTextLen < BufSize) and set 'BufDirty'' to true so InputText can update its internal state. ImGuiKey EventKey; // Key pressed (Up/Down/TAB) // Read-only // [Completion,History] ImWchar EventChar; // Character input // Read-write // [CharFilter] Replace character with another one, or set to zero to drop. return 1 is equivalent to setting EventChar=0; + bool EventActivated; // Input field just got activated // Read-only // [Always] bool BufDirty; // Set if you modify Buf/BufTextLen! // Write // [Completion,History,Always] char* Buf; // Text buffer // Read-write // [Resize] Can replace pointer / [Completion,History,Always] Only write to pointed data, don't replace the actual pointer! int BufTextLen; // Text length (in bytes) // Read-write // [Resize,Completion,History,Always] Exclude zero-terminator storage. In C land: == strlen(some_text), in C++ land: string.length() diff --git a/imgui_widgets.cpp b/imgui_widgets.cpp index 17e69c3b5..8faf35e50 100644 --- a/imgui_widgets.cpp +++ b/imgui_widgets.cpp @@ -4506,6 +4506,7 @@ static bool InputTextFilterCharacter(ImGuiContext* ctx, ImGuiInputTextState* sta callback_data.Flags = flags; callback_data.EventFlag = ImGuiInputTextFlags_CallbackCharFilter; callback_data.EventChar = (ImWchar)c; + callback_data.EventActivated = (g.ActiveId == state->ID && g.ActiveIdIsJustActivated); callback_data.UserData = user_data; if (callback(&callback_data) != 0) return false; @@ -5302,6 +5303,7 @@ bool ImGui::InputTextEx(const char* label, const char* hint, char* buf, int buf_ callback_data.ID = id; callback_data.Flags = flags; callback_data.EventFlag = event_flag; + callback_data.EventActivated = (g.ActiveId == state->ID && g.ActiveIdIsJustActivated); callback_data.UserData = callback_user_data; // FIXME-OPT: Undo stack reconcile needs a backup of the data until we rework API, see #7925 @@ -5380,6 +5382,7 @@ bool ImGui::InputTextEx(const char* label, const char* hint, char* buf, int buf_ callback_data.ID = id; callback_data.Flags = flags; callback_data.EventFlag = ImGuiInputTextFlags_CallbackResize; + callback_data.EventActivated = (g.ActiveId == state->ID && g.ActiveIdIsJustActivated); callback_data.Buf = buf; callback_data.BufTextLen = apply_new_text_length; callback_data.BufSize = ImMax(buf_size, apply_new_text_length + 1);