summaryrefslogtreecommitdiff
path: root/src/ui/ui_contacts.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/ui/ui_contacts.cpp')
-rw-r--r--src/ui/ui_contacts.cpp108
1 files changed, 59 insertions, 49 deletions
diff --git a/src/ui/ui_contacts.cpp b/src/ui/ui_contacts.cpp
index d57776e..7d03ba6 100644
--- a/src/ui/ui_contacts.cpp
+++ b/src/ui/ui_contacts.cpp
@@ -11,6 +11,63 @@ static contact selected_for_removal;
static contact active_contact;
+void ui_draw_address_form(address* buffer)
+{
+ const char* selected_country = NULL;
+ float widthAvailable = ImGui::GetContentRegionAvail().x;
+
+ char id[128];
+
+ ImGui::SetNextItemWidth(widthAvailable*0.5f);
+ snprintf(id, sizeof(id), "%s##%p", localize("contact.form.address1"), buffer);
+ ImGui::InputTextWithHint(id, localize("contact.form.address1"), buffer->address1, IM_ARRAYSIZE(buffer->address1));
+ ImGui::SameLine();ui_helper_draw_required_tag();
+
+ ImGui::SetNextItemWidth(widthAvailable*0.5f);
+ snprintf(id, sizeof(id), "%s##%p", localize("contact.form.address2"), buffer);
+ ImGui::InputTextWithHint(id, localize("contact.form.address2"), buffer->address2, IM_ARRAYSIZE(buffer->address2));
+ ImGui::SameLine();ui_helper_draw_required_tag();
+
+ // 5. Country dropdown.
+ 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(country_codes[i], buffer->country_code) == 0)
+ {
+ selected_country = countries[i];
+ break;
+ }
+ }
+ }
+
+ int selected_country_index = -1;
+ snprintf(id, sizeof(id), "%s##%p", localize("contact.form.country"), buffer);
+ if (ImGui::BeginCombo(id, 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)) {
+ selected_country = countries[n];
+ selected_country_index = n;
+ }
+ }
+ ImGui::EndCombo();
+ }
+ if (selected_country_index != -1) {
+ strops_copy(buffer->country_code, country_codes[selected_country_index], IM_ARRAYSIZE(buffer->country_code));
+ }
+ ImGui::SameLine();ui_helper_draw_required_tag();
+}
+
void ui_setup_contacts()
{
current_view_state = view_state::LIST;
@@ -20,8 +77,6 @@ void ui_setup_contacts()
void draw_contact_form_ex(contact* buffer, bool viewing_only = false, bool with_autocomplete = false, bool* on_autocomplete = 0)
{
- const char* selected_country = NULL;
-
ImGui::Spacing();
float widthAvailable = ImGui::GetContentRegionAvail().x;
@@ -60,53 +115,8 @@ void draw_contact_form_ex(contact* buffer, bool viewing_only = false, bool with_
else ImGui::InputTextWithHint(localize("contact.form.fullname"), localize("contact.form.fullname"), buffer->name, IM_ARRAYSIZE(buffer->name));
ImGui::SameLine();ui_helper_draw_required_tag();
- // 3. Address line 1
- ImGui::SetNextItemWidth(widthAvailable*0.5f);
- ImGui::InputTextWithHint(localize("contact.form.address1"), localize("contact.form.address1"), buffer->address.address1, IM_ARRAYSIZE(buffer->address.address1));
- ImGui::SameLine();ui_helper_draw_required_tag();
-
- // 4. Address line 2
- ImGui::SetNextItemWidth(widthAvailable*0.5f);
- ImGui::InputTextWithHint(localize("contact.form.address2"), localize("contact.form.address2"), buffer->address.address2, IM_ARRAYSIZE(buffer->address.address2));
- ImGui::SameLine();ui_helper_draw_required_tag();
-
- // 5. Country dropdown.
- 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(country_codes[i], buffer->address.country_code) == 0)
- {
- selected_country = countries[i];
- break;
- }
- }
- }
-
- 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)) {
- selected_country = countries[n];
- selected_country_index = n;
- }
- }
- ImGui::EndCombo();
- }
- if (selected_country_index != -1) {
- strops_copy(buffer->address.country_code, country_codes[selected_country_index], IM_ARRAYSIZE(buffer->address.country_code));
- }
- ImGui::SameLine();ui_helper_draw_required_tag();
+ // 3. Address line 1, 4. address line 2, 5. country
+ ui_draw_address_form(&buffer->address);
// 6. Contact type dropdown.
ImGui::SetNextItemWidth(widthAvailable*0.5f);