summaryrefslogtreecommitdiff
path: root/src/ui/imgui_extensions.cpp
diff options
context:
space:
mode:
authorAldrik Ramaekers <aldrikboy@gmail.com>2025-10-26 13:20:40 +0100
committerAldrik Ramaekers <aldrikboy@gmail.com>2025-10-26 13:20:40 +0100
commit5e06ad208e32330b662af90ce41613f5421095cb (patch)
tree176e59c9a1e3c650c20d5be240a6c84291535a8c /src/ui/imgui_extensions.cpp
parent5abb2cbd8f201b8a8101a661f1dd9a68412d8674 (diff)
ui refactors
Diffstat (limited to 'src/ui/imgui_extensions.cpp')
-rw-r--r--src/ui/imgui_extensions.cpp92
1 files changed, 77 insertions, 15 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