From 9a16fd2cf0bca13d8a3015da89833db2230b391f Mon Sep 17 00:00:00 2001 From: Aldrik Ramaekers Date: Sat, 20 Sep 2025 19:38:37 +0200 Subject: ui refactor --- src/ui/imgui_extensions.cpp | 14 ++++---------- src/ui/ui_contacts.cpp | 24 ++++++++++++------------ src/ui/ui_projects.cpp | 2 +- 3 files changed, 17 insertions(+), 23 deletions(-) (limited to 'src/ui') diff --git a/src/ui/imgui_extensions.cpp b/src/ui/imgui_extensions.cpp index 5fdc3a7..1875c22 100644 --- a/src/ui/imgui_extensions.cpp +++ b/src/ui/imgui_extensions.cpp @@ -9,19 +9,16 @@ namespace ImGui { - void FormInputTextWithErrorHint(const char* hint, void* data, char* buffer, size_t buf_size, bool has_error) + void FormInputTextWithErrorHint(const char* hint, char* buffer, size_t buf_size, bool has_error) { float widthAvailable = ImGui::GetContentRegionAvail().x; ImGui::SetNextItemWidth(widthAvailable*0.5f); - char id[MAX_LEN_LONG_DESC]; - snprintf(id, sizeof(id), "%s##%p", hint, data); - if (has_error) { ImGui::PushStyleColor(ImGuiCol_Border, COLOR_ERROR_OUTLINE); ImGui::PushStyleVar(ImGuiStyleVar_FrameBorderSize, 1.5f); } - ImGui::InputTextWithHint(id, hint, buffer, buf_size); + ImGui::InputTextWithHint(hint, hint, buffer, buf_size); if (has_error) { ImGui::PopStyleVar(); ImGui::PopStyleColor(); @@ -32,10 +29,9 @@ namespace ImGui } } - void FormCountryCombo(void* data, char* buffer, size_t buf_size) + void FormCountryCombo(char* buffer, size_t buf_size) { const char* selected_country = 0; - char id[MAX_LEN_LONG_DESC]; float widthAvailable = ImGui::GetContentRegionAvail().x; ImGui::SetNextItemWidth(widthAvailable*0.5f); @@ -58,14 +54,12 @@ namespace ImGui bool has_a_selection = selected_country != 0; int selected_country_index = -1; - snprintf(id, sizeof(id), "%s##%p", localize("contact.form.country"), data); - if (!has_a_selection) { ImGui::PushStyleColor(ImGuiCol_Border, COLOR_ERROR_OUTLINE); ImGui::PushStyleVar(ImGuiStyleVar_FrameBorderSize, 1.5f); } - if (ImGui::BeginCombo(id, selected_country)) + if (ImGui::BeginCombo(localize("contact.form.country"), selected_country)) { for (int n = 0; n < country_count; n++) { diff --git a/src/ui/ui_contacts.cpp b/src/ui/ui_contacts.cpp index b471f58..549273d 100644 --- a/src/ui/ui_contacts.cpp +++ b/src/ui/ui_contacts.cpp @@ -32,13 +32,13 @@ static contact active_contact; void ui_draw_address_form(address* buffer, a_err last_err) { - ImGui::FormInputTextWithErrorHint(localize("contact.form.address1"), buffer, buffer->address1, IM_ARRAYSIZE(buffer->address1), last_err & A_ERR_MISSING_ADDRESS1); - ImGui::FormInputTextWithErrorHint(localize("contact.form.address2"), buffer, buffer->address2, IM_ARRAYSIZE(buffer->address2), 0); - ImGui::FormInputTextWithErrorHint(localize("contact.form.city"), buffer, buffer->city, IM_ARRAYSIZE(buffer->city), last_err & A_ERR_MISSING_CITY); - ImGui::FormInputTextWithErrorHint(localize("contact.form.postal"), buffer, buffer->postal, IM_ARRAYSIZE(buffer->postal), last_err & A_ERR_MISSING_POSTAL); - ImGui::FormInputTextWithErrorHint(localize("contact.form.region"), buffer, buffer->region, IM_ARRAYSIZE(buffer->region), 0); + ImGui::FormInputTextWithErrorHint(localize("contact.form.address1"), buffer->address1, IM_ARRAYSIZE(buffer->address1), last_err & A_ERR_MISSING_ADDRESS1); + ImGui::FormInputTextWithErrorHint(localize("contact.form.address2"), buffer->address2, IM_ARRAYSIZE(buffer->address2), 0); + ImGui::FormInputTextWithErrorHint(localize("contact.form.city"), buffer->city, IM_ARRAYSIZE(buffer->city), last_err & A_ERR_MISSING_CITY); + ImGui::FormInputTextWithErrorHint(localize("contact.form.postal"), buffer->postal, IM_ARRAYSIZE(buffer->postal), last_err & A_ERR_MISSING_POSTAL); + ImGui::FormInputTextWithErrorHint(localize("contact.form.region"), buffer->region, IM_ARRAYSIZE(buffer->region), 0); - ImGui::FormCountryCombo(buffer, buffer->country_code, IM_ARRAYSIZE(buffer->country_code)); + ImGui::FormCountryCombo(buffer->country_code, IM_ARRAYSIZE(buffer->country_code)); } void ui_setup_contacts() @@ -60,7 +60,7 @@ void draw_contact_form_ex(contact* buffer, bool viewing_only = false, bool with_ if (!viewing_only) ImGui::EndDisabled(); if (with_autocomplete) ImGui::FormContactAutocomplete(buffer, last_err & A_ERR_MISSING_NAME); - else ImGui::FormInputTextWithErrorHint(localize("contact.form.fullname"), buffer, buffer->name, IM_ARRAYSIZE(buffer->name), last_err & A_ERR_MISSING_NAME); + else ImGui::FormInputTextWithErrorHint(localize("contact.form.fullname"), buffer->name, IM_ARRAYSIZE(buffer->name), last_err & A_ERR_MISSING_NAME); ui_draw_address_form(&buffer->address, last_err); @@ -69,13 +69,13 @@ void draw_contact_form_ex(contact* buffer, bool viewing_only = false, bool with_ // Fields only required for businesses. if (buffer->type == contact_type::CONTACT_BUSINESS) { - ImGui::FormInputTextWithErrorHint(localize("contact.form.taxnumber"), buffer, buffer->taxid, IM_ARRAYSIZE(buffer->taxid), last_err & A_ERR_MISSING_TAXID); - ImGui::FormInputTextWithErrorHint(localize("contact.form.businessnumber"), buffer, buffer->businessid, IM_ARRAYSIZE(buffer->businessid), last_err & A_ERR_MISSING_BUSINESSID); + ImGui::FormInputTextWithErrorHint(localize("contact.form.taxnumber"), buffer->taxid, IM_ARRAYSIZE(buffer->taxid), last_err & A_ERR_MISSING_TAXID); + ImGui::FormInputTextWithErrorHint(localize("contact.form.businessnumber"), buffer->businessid, IM_ARRAYSIZE(buffer->businessid), last_err & A_ERR_MISSING_BUSINESSID); } - ImGui::FormInputTextWithErrorHint(localize("contact.form.email"), buffer, buffer->email, IM_ARRAYSIZE(buffer->email), last_err & A_ERR_MISSING_EMAIL); - ImGui::FormInputTextWithErrorHint(localize("contact.form.phonenumber"), buffer, buffer->phone_number, IM_ARRAYSIZE(buffer->phone_number), 0); - ImGui::FormInputTextWithErrorHint(localize("contact.form.bankaccount"), buffer, buffer->bank_account, IM_ARRAYSIZE(buffer->bank_account), 0); + ImGui::FormInputTextWithErrorHint(localize("contact.form.email"), buffer->email, IM_ARRAYSIZE(buffer->email), last_err & A_ERR_MISSING_EMAIL); + ImGui::FormInputTextWithErrorHint(localize("contact.form.phonenumber"), buffer->phone_number, IM_ARRAYSIZE(buffer->phone_number), 0); + ImGui::FormInputTextWithErrorHint(localize("contact.form.bankaccount"), buffer->bank_account, IM_ARRAYSIZE(buffer->bank_account), 0); if (viewing_only) ImGui::EndDisabled(); ImGui::PopID(); diff --git a/src/ui/ui_projects.cpp b/src/ui/ui_projects.cpp index 37cf5d8..e7fa86f 100644 --- a/src/ui/ui_projects.cpp +++ b/src/ui/ui_projects.cpp @@ -54,7 +54,7 @@ static void draw_project_form() ImGui::InputText(localize("project.form.identifier"), active_project.id, IM_ARRAYSIZE(active_project.id)); if (!viewing_only) ImGui::EndDisabled(); - ImGui::FormInputTextWithErrorHint(localize("project.form.description"), &active_project, active_project.description, IM_ARRAYSIZE(active_project.description), last_err & A_ERR_MISSING_DESCRIPTION); + ImGui::FormInputTextWithErrorHint(localize("project.form.description"), active_project.description, IM_ARRAYSIZE(active_project.description), last_err & A_ERR_MISSING_DESCRIPTION); if (viewing_only) ImGui::EndDisabled(); -- cgit v1.2.3-70-g09d2