summaryrefslogtreecommitdiff
path: root/src/ui/helpers.cpp
diff options
context:
space:
mode:
authorAldrik Ramaekers <aldrikboy@gmail.com>2025-08-10 19:03:46 +0200
committerAldrik Ramaekers <aldrikboy@gmail.com>2025-08-10 19:03:46 +0200
commit572caa74ed824fefa02eb81adc7639a783f243c7 (patch)
tree9938efe957a708a3642c19a03fdacaaa2b0618d5 /src/ui/helpers.cpp
parent3c83a2d06cf33429ca0e654a415fc95581df46e1 (diff)
working on invoice form
Diffstat (limited to 'src/ui/helpers.cpp')
-rw-r--r--src/ui/helpers.cpp14
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;
}
+