diff options
Diffstat (limited to 'src/ui/helpers.cpp')
| -rw-r--r-- | src/ui/helpers.cpp | 14 |
1 files changed, 10 insertions, 4 deletions
diff --git a/src/ui/helpers.cpp b/src/ui/helpers.cpp index a239f4c..4c6647e 100644 --- a/src/ui/helpers.cpp +++ b/src/ui/helpers.cpp @@ -65,20 +65,24 @@ void ui_helper_draw_required_tag() ImGui::PopStyleColor(); } -void ui_helper_TextInputWithAutocomplete(const char* label, const char* hint, char* buffer, size_t buf_size, +int ui_helper_TextInputWithAutocomplete(const char* label, const char* hint, char* buffer, size_t buf_size, char* suggestions[], int suggestion_count) { + int result = -1; static bool is_open = false; ImGui::InputTextWithHint(label, hint, buffer, buf_size); + if (buffer[0] == '\0' && is_open) is_open = false; + if (suggestion_count == 0 && is_open) is_open = false; + bool is_active = ImGui::IsItemActive(); - if (is_active && buffer[0] != '\0') + if (is_active && buffer[0] != '\0' && suggestion_count > 0) { is_open = true; } if (is_open) { - ImGui::BeginChild("autocomplete_popup", ImVec2(0, 100), true); + ImGui::BeginChild("autocomplete_popup", ImVec2(0, 10.0f + suggestion_count*23.0f), true); { ImVec2 win_pos = ImGui::GetWindowPos(); ImVec2 win_size = ImGui::GetWindowSize(); @@ -97,7 +101,7 @@ void ui_helper_TextInputWithAutocomplete(const char* label, const char* hint, ch // Copy selected suggestion to buffer strops_copy(buffer, suggestions[i], buf_size); buffer[buf_size - 1] = '\0'; - + result = i; is_open = false; } } @@ -105,4 +109,6 @@ void ui_helper_TextInputWithAutocomplete(const char* label, const char* hint, ch ImGui::EndChild(); } } + return result; } + |
