From 5854629f246aed30e1e7e4239c9283e2a6c8053f Mon Sep 17 00:00:00 2001 From: Aldrik Ramaekers Date: Sat, 9 Aug 2025 11:35:49 +0200 Subject: store country code instead of country name --- src/ui/ui_contacts.cpp | 16 ++++++++++++---- src/ui/ui_settings.cpp | 2 +- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/src/ui/ui_contacts.cpp b/src/ui/ui_contacts.cpp index fd9907f..24f45f7 100644 --- a/src/ui/ui_contacts.cpp +++ b/src/ui/ui_contacts.cpp @@ -55,11 +55,16 @@ bool draw_contact_form(contact* buffer, bool back_button_enabled = true, bool vi ImGui::SetNextItemWidth(widthAvailable*0.5f); const char* countries[] = { localize("country.AT"),localize("country.BE"),localize("country.BG"),localize("country.HR"),localize("country.CY"),localize("country.CZ"),localize("country.DK"),localize("country.EE"),localize("country.FI"),localize("country.FR"),localize("country.DE"),localize("country.GR"),localize("country.HU"),localize("country.IE"),localize("country.IT"),localize("country.LV"),localize("country.LT"),localize("country.LU"),localize("country.MT"),localize("country.NL"),localize("country.PL"),localize("country.PT"),localize("country.RO"),localize("country.SK"),localize("country.SI"),localize("country.ES"),localize("country.SE") }; + const char* country_codes[] = { + "AT", "BE", "BG", "HR", "CY", "CZ", "DK", "EE", "FI", "FR", + "DE", "GR", "HU", "IE", "IT", "LV", "LT", "LU", "MT", "NL", + "PL", "PT", "RO", "SK", "SI", "ES", "SE" + }; s32 country_count = sizeof(countries) / sizeof(countries[0]); if (selected_country == 0) { for (int i = 0; i < country_count; i++) { - if (strcmp(countries[i], buffer->address.country) == 0) + if (strcmp(country_codes[i], buffer->address.country) == 0) { selected_country = countries[i]; break; @@ -67,18 +72,21 @@ bool draw_contact_form(contact* buffer, bool back_button_enabled = true, bool vi } } + int selected_country_index = -1; if (ImGui::BeginCombo(localize("contact.form.country"), selected_country)) { for (int n = 0; n < IM_ARRAYSIZE(countries); n++) { bool is_selected = (selected_country == countries[n]); - if (ImGui::Selectable(countries[n], is_selected)) + if (ImGui::Selectable(countries[n], is_selected)) { selected_country = countries[n]; + selected_country_index = n; + } } ImGui::EndCombo(); } - if (selected_country) { - strops_copy(buffer->address.country, selected_country, IM_ARRAYSIZE(buffer->address.country)); + if (selected_country_index != -1) { + strops_copy(buffer->address.country, country_codes[selected_country_index], IM_ARRAYSIZE(buffer->address.country)); } ImGui::SameLine();ui_helper_draw_required_tag(); diff --git a/src/ui/ui_settings.cpp b/src/ui/ui_settings.cpp index 81f6d31..041b672 100644 --- a/src/ui/ui_settings.cpp +++ b/src/ui/ui_settings.cpp @@ -14,7 +14,7 @@ void ui_setup_settings() void ui_draw_settings() { // @localize - if (ImGui::BeginTabBar("SettingsTabBar", 0)) + if (ImGui::BeginTabBar("SettingsTabBar")) { if (ImGui::BeginTabItem("Company")) { -- cgit v1.2.3-70-g09d2