diff options
Diffstat (limited to 'src/ui')
| -rw-r--r-- | src/ui/imgui_extensions.cpp | 92 | ||||
| -rw-r--r-- | src/ui/ui_contacts.cpp | 76 | ||||
| -rw-r--r-- | src/ui/ui_expenses.cpp | 20 | ||||
| -rw-r--r-- | src/ui/ui_invoices.cpp | 21 | ||||
| -rw-r--r-- | src/ui/ui_projects.cpp | 4 | ||||
| -rw-r--r-- | src/ui/ui_settings.cpp | 6 |
6 files changed, 102 insertions, 117 deletions
diff --git a/src/ui/imgui_extensions.cpp b/src/ui/imgui_extensions.cpp index 494cfc8..d1abc58 100644 --- a/src/ui/imgui_extensions.cpp +++ b/src/ui/imgui_extensions.cpp @@ -22,7 +22,7 @@ namespace ImGui } } - void FormInputTextWithErrorHint(const char* hint, char* buffer, size_t buf_size, bool has_error) + void InputTextWithErrorHint(const char* hint, char* buffer, size_t buf_size, bool has_error) { float widthAvailable = ImGui::GetContentRegionAvail().x; ImGui::SetNextItemWidth(widthAvailable*0.5f); @@ -42,7 +42,7 @@ namespace ImGui } } - bool FormInvoiceFileSelector(char* text, char* buffer) + bool FileSelect(char* text, char* buffer) { bool result = false; float widthAvailable = ImGui::GetContentRegionAvail().x; @@ -82,15 +82,14 @@ namespace ImGui return result; } - void FormCountryCombo(char* buffer, size_t buf_size, bool activated_only) + void CountryDropdown(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}; + bool enabled_countries[300] = {0}; for (int x = 0; x < country::get_count(); x++) { @@ -151,7 +150,7 @@ namespace ImGui } } - void FormContactTypeCombo(contact_type* type) + void ContactTypeDropdown(contact_type* type) { float widthAvailable = ImGui::GetContentRegionAvail().x; ImGui::SetNextItemWidth(widthAvailable*0.5f); @@ -170,7 +169,7 @@ namespace ImGui } open_autocomplete_ref; - int TextInputWithAutocomplete(const char* hint, char* buffer, size_t buf_size, char* suggestions[], int suggestion_count, bool has_error) + int InputTextWithAutocomplete(const char* hint, char* buffer, size_t buf_size, char* suggestions[], int suggestion_count, bool has_error) { int result = -1; @@ -262,7 +261,7 @@ namespace ImGui return result; } - void FormContactAutocomplete(contact* buffer, bool has_error) + static void _ContactFormNameAutocomplete(contact* buffer, bool has_error) { float widthAvailable = ImGui::GetContentRegionAvail().x; ImGui::SetNextItemWidth(widthAvailable*0.5f); @@ -277,7 +276,7 @@ namespace ImGui strops::format(autocomplete_strings[i], 200, "%s (%s %s)", autocomplete_list[i].name, autocomplete_list[i].address.address1, autocomplete_list[i].address.address2); } - int autocomplete_index = ImGui::TextInputWithAutocomplete(locale::get("contact.form.fullname"), + int autocomplete_index = ImGui::InputTextWithAutocomplete(locale::get("contact.form.fullname"), buffer->name, IM_ARRAYSIZE(buffer->name), (char**)autocomplete_strings, autocomplete_count, has_error); if (autocomplete_index != -1) @@ -291,7 +290,40 @@ namespace ImGui } } - void FormCostCenterCombo(char* costcenter_id) + void ContactForm(contact* buffer, bool viewing_only, bool with_autocomplete, bool active_countries_only) + { + a_err last_err = administration::contact_is_valid(*buffer); + + ImGui::PushID(buffer); + + ImGui::Spacing(); + ImGui::BeginDisabled(); + + if (!viewing_only) ImGui::EndDisabled(); + + if (with_autocomplete) _ContactFormNameAutocomplete(buffer, last_err & A_ERR_MISSING_NAME); + else ImGui::InputTextWithErrorHint(locale::get("contact.form.fullname"), buffer->name, IM_ARRAYSIZE(buffer->name), last_err & A_ERR_MISSING_NAME); + + ImGui::AddressForm(&buffer->address, last_err, active_countries_only); + + ImGui::ContactTypeDropdown(&buffer->type); + + // Fields only required for businesses. + if (buffer->type == contact_type::CONTACT_BUSINESS) + { + ImGui::InputTextWithErrorHint(locale::get("contact.form.taxnumber"), buffer->taxid, IM_ARRAYSIZE(buffer->taxid), last_err & A_ERR_MISSING_TAXID); + ImGui::InputTextWithErrorHint(locale::get("contact.form.businessnumber"), buffer->businessid, IM_ARRAYSIZE(buffer->businessid), last_err & A_ERR_MISSING_BUSINESSID); + } + + ImGui::InputTextWithErrorHint(locale::get("contact.form.email"), buffer->email, IM_ARRAYSIZE(buffer->email), last_err & A_ERR_MISSING_EMAIL); + ImGui::InputTextWithErrorHint(locale::get("contact.form.phonenumber"), buffer->phone_number, IM_ARRAYSIZE(buffer->phone_number), 0); + ImGui::InputTextWithErrorHint(locale::get("contact.form.bankaccount"), buffer->bank_account, IM_ARRAYSIZE(buffer->bank_account), 0); + + if (viewing_only) ImGui::EndDisabled(); + ImGui::PopID(); + } + + void CostCenterDropdown(char* costcenter_id) { u32 costcenter_count = administration::cost_center_count(); cost_center* buffer = (cost_center*) memops::alloc(sizeof(cost_center) * costcenter_count); @@ -332,7 +364,7 @@ namespace ImGui memops::unalloc(buffer); } - void FormProjectCombo(char* project_id) + void ProjectDropdown(char* project_id) { u32 project_count = administration::project_count(); project* buffer = (project*) memops::alloc(sizeof(project) * project_count); @@ -373,7 +405,7 @@ namespace ImGui memops::unalloc(buffer); } - void FormTaxRateCombo(char* tax_internal_code, bool outgoing, bool has_error) + void TaxRateDropdown(char* tax_internal_code, bool outgoing, bool has_error) { u32 tax_rate_count = administration::tax_rate_count(); tax_rate* buffer = (tax_rate*) memops::alloc(sizeof(tax_rate) * tax_rate_count); @@ -437,7 +469,7 @@ namespace ImGui memops::unalloc(buffer); } - bool FormCurrencyCombo(char* currency) + bool CurrencyDropdown(char* currency) { int currentCurrency = 0; bool result = false; @@ -492,7 +524,7 @@ namespace ImGui return result; } - void FormToggleCombo(bool *buffer, char* option1, char* option2) + void ToggleDropdown(bool *buffer, char* option1, char* option2) { const char* items[] = { option1, option2 }; @@ -512,7 +544,7 @@ namespace ImGui } } - bool DrawWarningIcon(float radius) + bool WarningIcon(float radius) { ImGui::SameLine(); @@ -547,4 +579,34 @@ namespace ImGui } return false; } + + void DeliveryInfoForm(delivery_info* buffer, bool viewing_only) + { + a_err last_err = administration::addressee_is_valid(*buffer); + + ImGui::PushID(buffer); + + ImGui::Spacing(); + ImGui::BeginDisabled(); + + if (!viewing_only) ImGui::EndDisabled(); + + ImGui::InputTextWithErrorHint(locale::get("contact.form.fullname"), buffer->name, IM_ARRAYSIZE(buffer->name), last_err & A_ERR_MISSING_NAME); + + ImGui::AddressForm(&buffer->address, last_err); + + if (viewing_only) ImGui::EndDisabled(); + ImGui::PopID(); + } + + void AddressForm(address* buffer, a_err last_err, bool active_countries_only) + { + ImGui::InputTextWithErrorHint(locale::get("contact.form.address1"), buffer->address1, IM_ARRAYSIZE(buffer->address1), last_err & A_ERR_MISSING_ADDRESS1); + ImGui::InputTextWithErrorHint(locale::get("contact.form.address2"), buffer->address2, IM_ARRAYSIZE(buffer->address2), 0); + ImGui::InputTextWithErrorHint(locale::get("contact.form.city"), buffer->city, IM_ARRAYSIZE(buffer->city), last_err & A_ERR_MISSING_CITY); + ImGui::InputTextWithErrorHint(locale::get("contact.form.postal"), buffer->postal, IM_ARRAYSIZE(buffer->postal), last_err & A_ERR_MISSING_POSTAL); + ImGui::InputTextWithErrorHint(locale::get("contact.form.region"), buffer->region, IM_ARRAYSIZE(buffer->region), 0); + + ImGui::CountryDropdown(buffer->country_code, IM_ARRAYSIZE(buffer->country_code), active_countries_only); + } }
\ No newline at end of file diff --git a/src/ui/ui_contacts.cpp b/src/ui/ui_contacts.cpp index 4e15bb1..0f1716f 100644 --- a/src/ui/ui_contacts.cpp +++ b/src/ui/ui_contacts.cpp @@ -28,17 +28,6 @@ static contact selected_for_removal; static contact active_contact; -void draw_address_form(address* buffer, a_err last_err, bool active_countries_only = false) -{ - ImGui::FormInputTextWithErrorHint(locale::get("contact.form.address1"), buffer->address1, IM_ARRAYSIZE(buffer->address1), last_err & A_ERR_MISSING_ADDRESS1); - ImGui::FormInputTextWithErrorHint(locale::get("contact.form.address2"), buffer->address2, IM_ARRAYSIZE(buffer->address2), 0); - ImGui::FormInputTextWithErrorHint(locale::get("contact.form.city"), buffer->city, IM_ARRAYSIZE(buffer->city), last_err & A_ERR_MISSING_CITY); - ImGui::FormInputTextWithErrorHint(locale::get("contact.form.postal"), buffer->postal, IM_ARRAYSIZE(buffer->postal), last_err & A_ERR_MISSING_POSTAL); - ImGui::FormInputTextWithErrorHint(locale::get("contact.form.region"), buffer->region, IM_ARRAYSIZE(buffer->region), 0); - - ImGui::FormCountryCombo(buffer->country_code, IM_ARRAYSIZE(buffer->country_code), active_countries_only); -} - void ui::setup_contacts() { current_view_state = ui::view_state::LIST_ALL; @@ -46,63 +35,6 @@ void ui::setup_contacts() memops::zero(&selected_for_removal, sizeof(contact)); } -void draw_addressee_form_ex(delivery_info* buffer, bool viewing_only = false) -{ - a_err last_err = administration::addressee_is_valid(*buffer); - - ImGui::PushID(buffer); - - ImGui::Spacing(); - ImGui::BeginDisabled(); - - if (!viewing_only) ImGui::EndDisabled(); - - ImGui::FormInputTextWithErrorHint(locale::get("contact.form.fullname"), buffer->name, IM_ARRAYSIZE(buffer->name), last_err & A_ERR_MISSING_NAME); - - draw_address_form(&buffer->address, last_err); - - if (viewing_only) ImGui::EndDisabled(); - ImGui::PopID(); -} - -void draw_contact_form_ex(contact* buffer, bool viewing_only = false, bool with_autocomplete = false, bool active_countries_only = false) -{ - a_err last_err = administration::contact_is_valid(*buffer); - - ImGui::PushID(buffer); - - ImGui::Spacing(); - ImGui::BeginDisabled(); - - if (!viewing_only) ImGui::EndDisabled(); - - if (with_autocomplete) ImGui::FormContactAutocomplete(buffer, last_err & A_ERR_MISSING_NAME); - else ImGui::FormInputTextWithErrorHint(locale::get("contact.form.fullname"), buffer->name, IM_ARRAYSIZE(buffer->name), last_err & A_ERR_MISSING_NAME); - - draw_address_form(&buffer->address, last_err, active_countries_only); - - ImGui::FormContactTypeCombo(&buffer->type); - - // Fields only required for businesses. - if (buffer->type == contact_type::CONTACT_BUSINESS) - { - ImGui::FormInputTextWithErrorHint(locale::get("contact.form.taxnumber"), buffer->taxid, IM_ARRAYSIZE(buffer->taxid), last_err & A_ERR_MISSING_TAXID); - ImGui::FormInputTextWithErrorHint(locale::get("contact.form.businessnumber"), buffer->businessid, IM_ARRAYSIZE(buffer->businessid), last_err & A_ERR_MISSING_BUSINESSID); - } - - ImGui::FormInputTextWithErrorHint(locale::get("contact.form.email"), buffer->email, IM_ARRAYSIZE(buffer->email), last_err & A_ERR_MISSING_EMAIL); - ImGui::FormInputTextWithErrorHint(locale::get("contact.form.phonenumber"), buffer->phone_number, IM_ARRAYSIZE(buffer->phone_number), 0); - ImGui::FormInputTextWithErrorHint(locale::get("contact.form.bankaccount"), buffer->bank_account, IM_ARRAYSIZE(buffer->bank_account), 0); - - if (viewing_only) ImGui::EndDisabled(); - ImGui::PopID(); -} - -void draw_contact_form(contact* buffer, bool viewing_only = false) -{ - draw_contact_form_ex(buffer, viewing_only, false); -} - static void draw_contact_list() { static char search_buffer[MAX_LEN_LONG_DESC]; @@ -169,7 +101,7 @@ static void draw_contact_list() if (administration::contact_is_valid(c) != A_ERR_SUCCESS) { - if (ImGui::DrawWarningIcon(8.0f)) { + if (ImGui::WarningIcon(8.0f)) { ImGui::SetTooltip(locale::get("ui.tooltip.invalidContact")); } } @@ -228,7 +160,7 @@ static void draw_contacts_create() current_view_state = ui::view_state::LIST_ALL; } - draw_contact_form(&active_contact); + ImGui::ContactForm(&active_contact, false, false); a_err contact_validation_err = administration::contact_is_valid(active_contact); bool can_save = contact_validation_err == A_ERR_SUCCESS; @@ -248,7 +180,7 @@ static void draw_contacts_update() current_view_state = ui::view_state::LIST_ALL; } - draw_contact_form(&active_contact); + ImGui::ContactForm(&active_contact, false, false); a_err contact_validation_err = administration::contact_is_valid(active_contact); bool can_save = contact_validation_err == A_ERR_SUCCESS; @@ -275,7 +207,7 @@ void ui::draw_contacts() current_view_state = ui::view_state::LIST_ALL; } - draw_contact_form(&active_contact, true); + ImGui::ContactForm(&active_contact, true, false); break; } }
\ No newline at end of file diff --git a/src/ui/ui_expenses.cpp b/src/ui/ui_expenses.cpp index e09db5b..d1121b1 100644 --- a/src/ui/ui_expenses.cpp +++ b/src/ui/ui_expenses.cpp @@ -34,8 +34,6 @@ static invoice selected_for_removal = {0}; static billing_item* invoice_items_buffer = 0; -void draw_addressee_form_ex(delivery_info* buffer, bool viewing_only = false); -void draw_contact_form_ex(contact* buffer, bool viewing_only, bool with_autocomplete, bool active_countries_only); void draw_invoice_items_form(invoice* invoice, bool outgoing = true); void ui::destroy_expenses() @@ -91,30 +89,30 @@ static void draw_expense_form(invoice* buffer, bool viewing_only = false) ImGui::Separator(); - if (ImGui::FormInvoiceFileSelector("Select file...", buffer->document.original_path)) { // @locale::get + if (ImGui::FileSelect("Select file...", buffer->document.original_path)) { // @locale::get buffer->document.copy_path[0] = 0; } ImGui::Separator(); ImGui::Text(locale::get("invoice.form.billinginformation")); - draw_contact_form_ex(&buffer->customer, false, true, false); + ImGui::ContactForm(&buffer->customer, false, true, false); ImGui::Separator(); ImGui::Text(locale::get("invoice.form.supplier")); - draw_contact_form_ex(&buffer->supplier, false, true, false); + ImGui::ContactForm(&buffer->supplier, false, true, false); ImGui::Checkbox(locale::get("invoice.form.triangulation"), &buffer->is_triangulation); if (buffer->is_triangulation) { ImGui::Spacing(); ImGui::Text(locale::get("invoice.form.shippinginformation")); - draw_addressee_form_ex(&buffer->addressee, 0); + ImGui::DeliveryInfoForm(&buffer->addressee, 0); } ImGui::Separator(); - ImGui::FormProjectCombo(buffer->project_id); - ImGui::FormCostCenterCombo(buffer->cost_center_id); + ImGui::ProjectDropdown(buffer->project_id); + ImGui::CostCenterDropdown(buffer->cost_center_id); ImGui::Separator(); @@ -134,7 +132,7 @@ static void draw_expense_form(invoice* buffer, bool viewing_only = false) ImGui::SameLine(); ImGui::Text("| %s: ", locale::get("invoice.form.currency")); ImGui::SameLine(); - if (ImGui::FormCurrencyCombo(buffer->currency)) + if (ImGui::CurrencyDropdown(buffer->currency)) { administration::invoice_set_currency(buffer, buffer->currency); } @@ -185,7 +183,7 @@ static void draw_expenses_list() char import_file_path[MAX_LEN_PATH] = {0}; ImGui::SameLine(); - if (ImGui::FormInvoiceFileSelector("+ Import", import_file_path)) { // @localize + if (ImGui::FileSelect("+ Import", import_file_path)) { // @localize current_view_state = ui::view_state::VIEW_IMPORT_REQUEST; active_invoice = administration::invoice_create_empty(); // @leak active_invoice.customer = administration::company_info_get(); @@ -236,7 +234,7 @@ static void draw_expenses_list() if (administration::invoice_is_valid(&c) != A_ERR_SUCCESS) { - if (ImGui::DrawWarningIcon(8.0f)) { + if (ImGui::WarningIcon(8.0f)) { ImGui::SetTooltip(locale::get("ui.tooltip.invalidInvoice")); } } diff --git a/src/ui/ui_invoices.cpp b/src/ui/ui_invoices.cpp index 4ae325f..8741965 100644 --- a/src/ui/ui_invoices.cpp +++ b/src/ui/ui_invoices.cpp @@ -32,9 +32,6 @@ static invoice selected_for_removal = {0}; static billing_item* invoice_items_buffer = 0; -void draw_contact_form_ex(contact* buffer, bool viewing_only, bool with_autocomplete, bool active_countries_only); -void draw_addressee_form_ex(delivery_info* buffer, bool viewing_only = false); - void ui::destroy_invoices() { memops::unalloc(invoice_items_buffer); @@ -87,7 +84,7 @@ void draw_invoice_items_form(invoice* invoice, bool outgoing) ImGui::InputFloat("##amount", &item.amount, 0.0f, 0.0f, "%.0f"); ImGui::SameLine(); - ImGui::FormToggleCombo(&item.amount_is_percentage, "X", "%"); + ImGui::ToggleDropdown(&item.amount_is_percentage, "X", "%"); ImGui::TableSetColumnIndex(2); ImGui::PushItemWidth(-1); @@ -103,14 +100,14 @@ void draw_invoice_items_form(invoice* invoice, bool outgoing) ImGui::InputFloat("##discount", &item.discount, 0.0f, 0.0f, "%.2f"); ImGui::SameLine(); - ImGui::FormToggleCombo(&item.discount_is_percentage, item.currency, "%"); + ImGui::ToggleDropdown(&item.discount_is_percentage, item.currency, "%"); ImGui::TableSetColumnIndex(5); ImGui::Text("%.2f %s", item.net, item.currency); ImGui::TableSetColumnIndex(6); ImGui::PushItemWidth(-1); - ImGui::FormTaxRateCombo(item.tax_internal_code, outgoing, valid & A_ERR_MISSING_TAX_RATE); + ImGui::TaxRateDropdown(item.tax_internal_code, outgoing, valid & A_ERR_MISSING_TAX_RATE); ImGui::PopItemWidth(); @@ -203,24 +200,24 @@ static void draw_invoice_form(invoice* buffer, bool viewing_only = false) ImGui::Separator(); - if (ImGui::FormInvoiceFileSelector("Select file...", buffer->document.original_path)) { // @locale::get + if (ImGui::FileSelect("Select file...", buffer->document.original_path)) { // @locale::get buffer->document.copy_path[0] = 0; } ImGui::Separator(); ImGui::Text(locale::get("invoice.form.billinginformation")); - draw_contact_form_ex(&buffer->customer, false, true, false); + ImGui::ContactForm(&buffer->customer, false, true, false); ImGui::Checkbox(locale::get("invoice.form.triangulation"), &buffer->is_triangulation); if (buffer->is_triangulation) { ImGui::Spacing(); ImGui::Text(locale::get("invoice.form.shippinginformation")); - draw_addressee_form_ex(&buffer->addressee, 0); + ImGui::DeliveryInfoForm(&buffer->addressee, 0); } ImGui::Separator(); - ImGui::FormProjectCombo(buffer->project_id); + ImGui::ProjectDropdown(buffer->project_id); ImGui::Spacing(); ImGui::Spacing(); @@ -238,7 +235,7 @@ static void draw_invoice_form(invoice* buffer, bool viewing_only = false) ImGui::SameLine(); ImGui::Text("| %s: ", locale::get("invoice.form.currency")); ImGui::SameLine(); - if (ImGui::FormCurrencyCombo(buffer->currency)) + if (ImGui::CurrencyDropdown(buffer->currency)) { administration::invoice_set_currency(buffer, buffer->currency); } @@ -328,7 +325,7 @@ static void draw_invoices_list() if (administration::invoice_is_valid(&c) != A_ERR_SUCCESS) { - if (ImGui::DrawWarningIcon(8.0f)) { + if (ImGui::WarningIcon(8.0f)) { ImGui::SetTooltip(locale::get("ui.tooltip.invalidInvoice")); } } diff --git a/src/ui/ui_projects.cpp b/src/ui/ui_projects.cpp index 5e0df0c..82597b4 100644 --- a/src/ui/ui_projects.cpp +++ b/src/ui/ui_projects.cpp @@ -53,7 +53,7 @@ static void draw_project_form() ImGui::InputText(locale::get("project.form.identifier"), active_project.id, IM_ARRAYSIZE(active_project.id)); if (!viewing_only) ImGui::EndDisabled(); - ImGui::FormInputTextWithErrorHint(locale::get("project.form.description"), active_project.description, IM_ARRAYSIZE(active_project.description), last_err & A_ERR_MISSING_DESCRIPTION); + ImGui::InputTextWithErrorHint(locale::get("project.form.description"), active_project.description, IM_ARRAYSIZE(active_project.description), last_err & A_ERR_MISSING_DESCRIPTION); if (viewing_only) ImGui::EndDisabled(); @@ -135,7 +135,7 @@ static void draw_project_list() if (administration::project_is_valid(c) != A_ERR_SUCCESS) { - if (ImGui::DrawWarningIcon(8.0f)) { + if (ImGui::WarningIcon(8.0f)) { ImGui::SetTooltip(locale::get("ui.tooltip.invalidInvoice")); } } diff --git a/src/ui/ui_settings.cpp b/src/ui/ui_settings.cpp index 06409b7..e15bde0 100644 --- a/src/ui/ui_settings.cpp +++ b/src/ui/ui_settings.cpp @@ -24,8 +24,6 @@ #include "administration.hpp" #include "administration_writer.hpp" -extern void draw_contact_form(contact* buffer, bool viewing_only = false); - static contact company_info; u32 tax_rate_count; @@ -325,8 +323,6 @@ static void draw_services() } } -void draw_contact_form_ex(contact* buffer, bool viewing_only, bool with_autocomplete, bool active_countries_only); - void ui::draw_settings() { if (ImGui::BeginTabBar("SettingsTabBar")) @@ -334,7 +330,7 @@ void ui::draw_settings() if (ImGui::BeginTabItem(locale::get("settings.table.company"), nullptr, select_company_tab == 1 ? ImGuiTabItemFlags_SetSelected : 0)) { select_company_tab = 0; - draw_contact_form_ex(&company_info, false, false, true); + ImGui::ContactForm(&company_info, false, false, true); // Save button. bool can_save = administration::contact_is_valid(company_info) == A_ERR_SUCCESS; |
