summaryrefslogtreecommitdiff
path: root/src/ui/imgui_extensions.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/ui/imgui_extensions.cpp')
-rw-r--r--src/ui/imgui_extensions.cpp30
1 files changed, 28 insertions, 2 deletions
diff --git a/src/ui/imgui_extensions.cpp b/src/ui/imgui_extensions.cpp
index 1875c22..8485dbf 100644
--- a/src/ui/imgui_extensions.cpp
+++ b/src/ui/imgui_extensions.cpp
@@ -9,6 +9,19 @@
namespace ImGui
{
+ void InputTextWithError(const char* text, char* buffer, size_t buf_size, bool has_error)
+ {
+ if (has_error) {
+ ImGui::PushStyleColor(ImGuiCol_Border, COLOR_ERROR_OUTLINE);
+ ImGui::PushStyleVar(ImGuiStyleVar_FrameBorderSize, 1.5f);
+ }
+ ImGui::InputText(text, buffer, buf_size);
+ if (has_error) {
+ ImGui::PopStyleVar();
+ ImGui::PopStyleColor();
+ }
+ }
+
void FormInputTextWithErrorHint(const char* hint, char* buffer, size_t buf_size, bool has_error)
{
float widthAvailable = ImGui::GetContentRegionAvail().x;
@@ -272,7 +285,7 @@ namespace ImGui
free(buffer);
}
- void FormTaxRateCombo(char* tax_rate_id, char* orig_country, char* dest_country)
+ void FormTaxRateCombo(char* tax_rate_id, char* orig_country, char* dest_country, bool has_error)
{
u32 tax_rate_count = administration_tax_rate_count();
tax_rate* buffer = (tax_rate*) malloc(sizeof(tax_rate) * tax_rate_count);
@@ -307,6 +320,11 @@ namespace ImGui
else snprintf(rate_str_buf, 40, "%s/%.1f%%", selected_tax_rate->country_code, selected_tax_rate->rate);
}
+ if (has_error) {
+ ImGui::PushStyleColor(ImGuiCol_Border, COLOR_ERROR_OUTLINE);
+ ImGui::PushStyleVar(ImGuiStyleVar_FrameBorderSize, 1.5f);
+ }
+
if (ImGui::BeginCombo("##Tax Bracket", rate_str_buf))
{
for (u32 n = 0; n < tax_rate_count; n++)
@@ -326,6 +344,11 @@ namespace ImGui
}
ImGui::EndCombo();
}
+
+ if (has_error) {
+ ImGui::PopStyleVar();
+ ImGui::PopStyleColor();
+ }
if (selected_tax_rate_index != -1) {
strops_copy(tax_rate_id, buffer[selected_tax_rate_index].id, MAX_LEN_ID);
@@ -392,7 +415,10 @@ namespace ImGui
void FormToggleCombo(bool *buffer, char* option1, char* option2)
{
const char* items[] = { option1, option2 };
- if (ImGui::BeginCombo("Mode", items[*buffer])) {
+
+ char ID[MAX_LEN_LONG_DESC];
+ snprintf(ID, MAX_LEN_LONG_DESC, "Mode##%p", buffer);
+ if (ImGui::BeginCombo(ID, items[*buffer])) {
for (int n = 0; n < 2; n++) {
bool is_selected = (n == (int)*buffer);
if (ImGui::Selectable(items[n], is_selected)) {