summaryrefslogtreecommitdiff
path: root/src/ui/imgui_extensions.cpp
diff options
context:
space:
mode:
authorAldrik Ramaekers <aldrikboy@gmail.com>2025-10-26 08:27:48 +0100
committerAldrik Ramaekers <aldrikboy@gmail.com>2025-10-26 08:27:48 +0100
commit5abb2cbd8f201b8a8101a661f1dd9a68412d8674 (patch)
treed11d1483100ed89eabf37efaaf3fae16df3cc4e6 /src/ui/imgui_extensions.cpp
parent8df1486ca41edb625feb269fe7f7997fa5ffacfe (diff)
refactor ui, fix autocomplete bug
Diffstat (limited to 'src/ui/imgui_extensions.cpp')
-rw-r--r--src/ui/imgui_extensions.cpp66
1 files changed, 57 insertions, 9 deletions
diff --git a/src/ui/imgui_extensions.cpp b/src/ui/imgui_extensions.cpp
index b3b20f8..494cfc8 100644
--- a/src/ui/imgui_extensions.cpp
+++ b/src/ui/imgui_extensions.cpp
@@ -82,18 +82,28 @@ namespace ImGui
return result;
}
- void FormCountryCombo(char* buffer, size_t buf_size)
+ void FormCountryCombo(char* buffer, size_t buf_size, bool activated_only)
{
const char* selected_country = 0;
float widthAvailable = ImGui::GetContentRegionAvail().x;
ImGui::SetNextItemWidth(widthAvailable*0.5f);
+ u32 country_cursor = 0;
const char* countries[300];
+ bool enabled_countries[300] = {1};
+
for (int x = 0; x < country::get_count(); x++)
{
char locale_str[20];
strops::format(locale_str, 20, "country.%s", country::get_code_by_index(x));
countries[x] = locale::get(locale_str);
+
+ if (activated_only) {
+ enabled_countries[x] = country::is_enabled(country::get_code_by_index(x));
+ }
+ else {
+ enabled_countries[x] = 1;
+ }
}
for (int i = 0; i < country::get_count(); i++)
@@ -116,10 +126,12 @@ namespace ImGui
{
for (int n = 0; n < country::get_count(); n++)
{
- bool is_selected = (selected_country == countries[n]);
- if (ImGui::Selectable(countries[n], is_selected)) {
- selected_country = countries[n];
- selected_country_index = n;
+ if (enabled_countries[n]) {
+ bool is_selected = (selected_country == countries[n]);
+ if (ImGui::Selectable(countries[n], is_selected)) {
+ selected_country = countries[n];
+ selected_country_index = n;
+ }
}
}
ImGui::EndCombo();
@@ -151,11 +163,42 @@ namespace ImGui
}
}
+ typedef struct
+ {
+ const char* id;
+ bool is_open;
+ } open_autocomplete_ref;
+
int TextInputWithAutocomplete(const char* hint, char* buffer, size_t buf_size, char* suggestions[], int suggestion_count, bool has_error)
{
int result = -1;
- static bool is_open = false;
+
+ const u32 max_ref_count = 10;
+ static open_autocomplete_ref open_refs[max_ref_count] = {0};
+ open_autocomplete_ref* found_ref = 0;
+ {
+ for (u32 i = 0; i < max_ref_count; i++) {
+ if (open_refs[i].id == buffer) {
+ found_ref = &open_refs[i];
+ break;
+ }
+ }
+
+ if (!found_ref) {
+ for (u32 i = 0; i < max_ref_count; i++) {
+ if (open_refs[i].id == 0) {
+ found_ref = &open_refs[i];
+ found_ref->id = buffer;
+ found_ref->is_open = false;
+ break;
+ }
+ }
+ }
+ if (!found_ref) assert(0);
+ }
+
+ bool is_open = found_ref->is_open;
if (has_error) {
ImGui::PushStyleColor(ImGuiCol_Border, config::colors::COLOR_ERROR_OUTLINE);
@@ -172,8 +215,10 @@ namespace ImGui
}
- if (buffer[0] == '\0' && is_open) is_open = false;
- if (suggestion_count == 0 && is_open) is_open = false;
+ 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' && suggestion_count > 0)
@@ -192,7 +237,8 @@ namespace ImGui
(mouse_pos.x < win_pos.x || mouse_pos.x > win_pos.x + win_size.x ||
mouse_pos.y < win_pos.y || mouse_pos.y > win_pos.y + win_size.y);
- if (mouse_clicked_outside) is_open = false;
+ if (mouse_clicked_outside)
+ is_open = false;
for (int i = 0; i < suggestion_count; ++i)
{
@@ -211,6 +257,8 @@ namespace ImGui
ImGui::EndChild();
}
}
+
+ found_ref->is_open = is_open;
return result;
}