From d4dc9d7c3e5eb09fd44d3ab1f89199ca084847fe Mon Sep 17 00:00:00 2001 From: Amos <48657826+Mauler125@users.noreply.github.com> Date: Mon, 17 Jan 2022 13:55:39 +0100 Subject: [PATCH] Implement new ImGui Input Text flag to move cursor to the end of char buffer --- r5dev/thirdparty/imgui/include/imgui.h | 3 ++- r5dev/thirdparty/imgui/src/imgui_widgets.cpp | 9 ++++++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/r5dev/thirdparty/imgui/include/imgui.h b/r5dev/thirdparty/imgui/include/imgui.h index ff0a44be..ce01fa06 100644 --- a/r5dev/thirdparty/imgui/include/imgui.h +++ b/r5dev/thirdparty/imgui/include/imgui.h @@ -1009,7 +1009,8 @@ enum ImGuiInputTextFlags_ ImGuiInputTextFlags_NoUndoRedo = 1 << 16, // Disable undo/redo. Note that input text owns the text data while active, if you want to provide your own undo/redo stack you need e.g. to call ClearActiveID(). ImGuiInputTextFlags_CharsScientific = 1 << 17, // Allow 0123456789.+-*/eE (Scientific notation input) ImGuiInputTextFlags_CallbackResize = 1 << 18, // Callback on buffer capacity changes request (beyond 'buf_size' parameter value), allowing the string to grow. Notify when the string wants to be resized (for string types which hold a cache of their Size). You will be provided a new BufSize in the callback and NEED to honor it. (see misc/cpp/imgui_stdlib.h for an example of using this) - ImGuiInputTextFlags_CallbackEdit = 1 << 19 // Callback on any edit (note that InputText() already returns true on edit, the callback is useful mainly to manipulate the underlying buffer while focus is active) + ImGuiInputTextFlags_CallbackEdit = 1 << 19, // Callback on any edit (note that InputText() already returns true on edit, the callback is useful mainly to manipulate the underlying buffer while focus is active) + ImGuiInputTextFlags_AutoCaretEnd = 1 << 20 // Move the input text cursor automatically to the end of the buffer on initial focus. // Obsolete names (will be removed soon) #ifndef IMGUI_DISABLE_OBSOLETE_FUNCTIONS diff --git a/r5dev/thirdparty/imgui/src/imgui_widgets.cpp b/r5dev/thirdparty/imgui/src/imgui_widgets.cpp index 411bb639..43de44b3 100644 --- a/r5dev/thirdparty/imgui/src/imgui_widgets.cpp +++ b/r5dev/thirdparty/imgui/src/imgui_widgets.cpp @@ -4048,6 +4048,7 @@ bool ImGui::InputTextEx(const char* label, const char* hint, char* buf, int buf_ const bool user_scroll_active = is_multiline && state != NULL && g.ActiveId == GetWindowScrollbarID(draw_window, ImGuiAxis_Y); bool clear_active_id = false; bool select_all = false; + bool auto_caret = false; float scroll_y = is_multiline ? draw_window->Scroll.y : FLT_MAX; @@ -4090,6 +4091,12 @@ bool ImGui::InputTextEx(const char* label, const char* hint, char* buf, int buf_ stb_textedit_initialize_state(&state->Stb, !is_multiline); } + if (flags & ImGuiInputTextFlags_AutoCaretEnd) + { + state->Stb.cursor = state->CurLenW; + auto_caret = true; + } + if (!is_multiline) { if (flags & ImGuiInputTextFlags_AutoSelectAll) @@ -4230,7 +4237,7 @@ bool ImGui::InputTextEx(const char* label, const char* hint, char* buf, int buf_ } state->CursorAnimReset(); } - else if (io.MouseClicked[0] && !state->SelectedAllMouseLock) + else if (io.MouseClicked[0] && !state->SelectedAllMouseLock && !auto_caret) { // FIXME: unselect on late click could be done release? if (hovered)