diff options
Diffstat (limited to 'src/ui')
| -rw-r--r-- | src/ui/helpers.cpp | 125 | ||||
| -rw-r--r-- | src/ui/ui_contacts.cpp | 42 | ||||
| -rw-r--r-- | src/ui/ui_earnings.cpp | 6 | ||||
| -rw-r--r-- | src/ui/ui_expenses.cpp | 76 | ||||
| -rw-r--r-- | src/ui/ui_invoices.cpp | 52 | ||||
| -rw-r--r-- | src/ui/ui_log.cpp | 2 | ||||
| -rw-r--r-- | src/ui/ui_main.cpp | 68 | ||||
| -rw-r--r-- | src/ui/ui_projects.cpp | 32 | ||||
| -rw-r--r-- | src/ui/ui_settings.cpp | 34 |
9 files changed, 221 insertions, 216 deletions
diff --git a/src/ui/helpers.cpp b/src/ui/helpers.cpp index 19eeee3..476e780 100644 --- a/src/ui/helpers.cpp +++ b/src/ui/helpers.cpp @@ -14,82 +14,87 @@ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -#include <tinyfiledialogs.h> - #include "ui.hpp" #include "imgui.h" -#include "locales.hpp" #include "strops.hpp" -ImFont* fontBold; -ImFont* fontBig; +#define STATUS_DURATION 4.0f +#define STATUS_FLASH_INTERVAL 0.1f +#define STATUS_MAX_FLASHES 2 + +namespace ui { + + ImFont* fontBold; + ImFont* fontBig; + + static status current_status; + + void ui::draw_status() + { + float region_width = ImGui::GetContentRegionAvail().x; + float text_width = ImGui::CalcTextSize(current_status.text).x; + + if (current_status.loading) + { + ImGui::SetCursorPosX(ImGui::GetCursorPosX() + region_width - text_width - 20.0f); + ImGui::Text("%c", "|/-\\"[(int)(ImGui::GetTime() / 0.1f) & 3]); + return; + } + + if (current_status.visible) + { + ImGui::SetCursorPosX(ImGui::GetCursorPosX() + region_width - text_width); + ImGui::PushStyleColor(ImGuiCol_Text, current_status.color); + ImGui::TextUnformatted(current_status.text); + ImGui::PopStyleColor(); + } -static ui_status current_status; + ImGuiIO& io = ImGui::GetIO(); + current_status.time += io.DeltaTime; -void ui_draw_status() -{ - float region_width = ImGui::GetContentRegionAvail().x; - float text_width = ImGui::CalcTextSize(current_status.text).x; - - if (current_status.loading) + if (current_status.time >= STATUS_FLASH_INTERVAL && current_status.flash_count < STATUS_MAX_FLASHES) + { + current_status.visible = !current_status.visible; + if (current_status.visible) current_status.flash_count++; + current_status.time = 0.0f; + } + + if (current_status.time >= STATUS_DURATION) + { + current_status.text[0] = 0; + } + } + + static void set_status_ex(const char* txt, int color) { - ImGui::SetCursorPosX(ImGui::GetCursorPosX() + region_width - text_width - 20.0f); - ImGui::Text("%c", "|/-\\"[(int)(ImGui::GetTime() / 0.1f) & 3]); - return; + current_status.flash_count = 0; + current_status.visible = true; + current_status.time = 0.0f; + current_status.color = color; + current_status.loading = false; + strops::copy(current_status.text, txt, STATUS_TEXT_LEN); } - if (current_status.visible) + void ui::set_status_error(const char* txt) { - ImGui::SetCursorPosX(ImGui::GetCursorPosX() + region_width - text_width); - ImGui::PushStyleColor(ImGuiCol_Text, current_status.color); - ImGui::TextUnformatted(current_status.text); - ImGui::PopStyleColor(); + set_status_ex(txt, config::colors::COLOR_ERROR); } - ImGuiIO& io = ImGui::GetIO(); - current_status.time += io.DeltaTime; + void ui::set_status(const char* txt) + { + set_status_ex(txt, config::colors::COLOR_DEFAULT); + } - if (current_status.time >= STATUS_FLASH_INTERVAL && current_status.flash_count < STATUS_MAX_FLASHES) + void ui::set_status_loading(bool loading) { - current_status.visible = !current_status.visible; - if (current_status.visible) current_status.flash_count++; + current_status.visible = true; current_status.time = 0.0f; + current_status.loading = loading; } - if (current_status.time >= STATUS_DURATION) + status ui::get_status() { - current_status.text[0] = 0; + return current_status; } -} - -void ui_set_status_ex(const char* txt, int color) -{ - current_status.flash_count = 0; - current_status.visible = true; - current_status.time = 0.0f; - current_status.color = color; - current_status.loading = false; - strops::copy(current_status.text, txt, STATUS_TEXT_LEN); -} - -void ui_set_status_error(const char* txt) -{ - ui_set_status_ex(txt, COLOR_ERROR); -} - -void ui_set_status(const char* txt) -{ - ui_set_status_ex(txt, COLOR_DEFAULT); -} - -void ui_set_status_loading(bool loading) -{ - current_status.visible = true; - current_status.time = 0.0f; - current_status.loading = loading; -} - -ui_status ui_get_status() -{ - return current_status; -} + +}
\ No newline at end of file diff --git a/src/ui/ui_contacts.cpp b/src/ui/ui_contacts.cpp index e282374..c205c87 100644 --- a/src/ui/ui_contacts.cpp +++ b/src/ui/ui_contacts.cpp @@ -25,12 +25,12 @@ #include "administration_writer.hpp" #include "locales.hpp" -static view_state current_view_state = view_state::LIST; +static ui::view_state current_view_state = ui::view_state::LIST_ALL; static contact selected_for_removal; static contact active_contact; -void ui_draw_address_form(address* buffer, a_err last_err) +void draw_address_form(address* buffer, a_err last_err) { 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); @@ -41,9 +41,9 @@ void ui_draw_address_form(address* buffer, a_err last_err) ImGui::FormCountryCombo(buffer->country_code, IM_ARRAYSIZE(buffer->country_code)); } -void ui_setup_contacts() +void ui::setup_contacts() { - current_view_state = view_state::LIST; + current_view_state = ui::view_state::LIST_ALL; active_contact = active_contact = administration_contact_create_empty(); memset(&selected_for_removal, 0, sizeof(contact)); } @@ -61,7 +61,7 @@ void draw_addressee_form_ex(delivery_info* buffer, bool viewing_only = false) ImGui::FormInputTextWithErrorHint(locale::get("contact.form.fullname"), buffer->name, IM_ARRAYSIZE(buffer->name), last_err & A_ERR_MISSING_NAME); - ui_draw_address_form(&buffer->address, last_err); + draw_address_form(&buffer->address, last_err); if (viewing_only) ImGui::EndDisabled(); ImGui::PopID(); @@ -81,7 +81,7 @@ void draw_contact_form_ex(contact* buffer, bool viewing_only = false, bool with_ 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); - ui_draw_address_form(&buffer->address, last_err); + draw_address_form(&buffer->address, last_err); ImGui::FormContactTypeCombo(&buffer->type); @@ -115,7 +115,7 @@ static void draw_contact_list() // Table header controls: create button and pagination. if (ImGui::Button(locale::get("form.create"))) { - current_view_state = view_state::CREATE; + current_view_state = ui::view_state::CREATE; active_contact = administration_contact_create_empty(); } @@ -166,7 +166,7 @@ static void draw_contact_list() snprintf(btn_name, sizeof(btn_name), "%s##%d", locale::get("form.view"), i); if (ImGui::Button(btn_name)) { active_contact = c; - current_view_state = view_state::VIEW; + current_view_state = ui::view_state::VIEW_EXISTING; } ImGui::SameLine(); @@ -174,7 +174,7 @@ static void draw_contact_list() snprintf(btn_name, sizeof(btn_name), "%s##%d", locale::get("form.change"), i); if (ImGui::Button(btn_name)) { active_contact = c; - current_view_state = view_state::EDIT; + current_view_state = ui::view_state::EDIT_EXISTING; } ImGui::SameLine(); @@ -205,10 +205,10 @@ static void draw_contact_list() } } -static void ui_draw_contacts_create() +static void draw_contacts_create() { if (ImGui::Button(locale::get("form.back"))) { - current_view_state = view_state::LIST; + current_view_state = ui::view_state::LIST_ALL; } draw_contact_form(&active_contact); @@ -220,15 +220,15 @@ static void ui_draw_contacts_create() ImGui::Spacing(); if (ImGui::Button(locale::get("form.save"))) { administration_contact_add(active_contact); - current_view_state = view_state::LIST; + current_view_state = ui::view_state::LIST_ALL; } if (!can_save) ImGui::EndDisabled(); } -static void ui_draw_contacts_update() +static void draw_contacts_update() { if (ImGui::Button(locale::get("form.back"))) { - current_view_state = view_state::LIST; + current_view_state = ui::view_state::LIST_ALL; } draw_contact_form(&active_contact); @@ -240,22 +240,22 @@ static void ui_draw_contacts_update() ImGui::Spacing(); if (ImGui::Button(locale::get("form.save"))) { administration_contact_update(active_contact); - current_view_state = view_state::LIST; + current_view_state = ui::view_state::LIST_ALL; } if (!can_save) ImGui::EndDisabled(); } -void ui_draw_contacts() +void ui::draw_contacts() { switch(current_view_state) { - case view_state::LIST: draw_contact_list(); break; - case view_state::CREATE: ui_draw_contacts_create(); break; - case view_state::EDIT: ui_draw_contacts_update(); break; + case ui::view_state::LIST_ALL: draw_contact_list(); break; + case ui::view_state::CREATE: draw_contacts_create(); break; + case ui::view_state::EDIT_EXISTING: draw_contacts_update(); break; - case view_state::VIEW: + case ui::view_state::VIEW_EXISTING: if (ImGui::Button(locale::get("form.back"))) { - current_view_state = view_state::LIST; + current_view_state = ui::view_state::LIST_ALL; } draw_contact_form(&active_contact, true); diff --git a/src/ui/ui_earnings.cpp b/src/ui/ui_earnings.cpp index 2106015..07c01ef 100644 --- a/src/ui/ui_earnings.cpp +++ b/src/ui/ui_earnings.cpp @@ -24,18 +24,18 @@ income_statement* statement = 0; -void ui_setup_earnings() +void ui::setup_earnings() { statement = (income_statement*)malloc(sizeof(income_statement)); administration_create_income_statement(statement); } -void ui_destroy_earnings() +void ui::destroy_earnings() { free(statement); } -void ui_draw_earnings() +void ui::draw_earnings() { static s32 current_page = 0; s32 max_page = ((statement->quarter_count) / 4); diff --git a/src/ui/ui_expenses.cpp b/src/ui/ui_expenses.cpp index acb53a8..a63cd50 100644 --- a/src/ui/ui_expenses.cpp +++ b/src/ui/ui_expenses.cpp @@ -29,9 +29,9 @@ #include "locales.hpp" #include "importer.hpp" -static import_invoice_request* active_import_request = 0; +static importer::invoice_request* active_import_request = 0; -static view_state current_view_state = view_state::LIST; +static ui::view_state current_view_state = ui::view_state::LIST_ALL; static invoice active_invoice = {0}; static invoice selected_for_removal = {0}; @@ -41,18 +41,18 @@ void draw_addressee_form_ex(delivery_info* buffer, bool viewing_only = false); void draw_contact_form_ex(contact* buffer, bool viewing_only = false, bool with_autocomplete = false); void draw_invoice_items_form(invoice* invoice); -void ui_destroy_expenses() +void ui::destroy_expenses() { free(invoice_items_buffer); } -void ui_setup_expenses() +void ui::setup_expenses() { if (active_import_request != 0) { - current_view_state = view_state::VIEW_IMPORT_REQUEST; + current_view_state = ui::view_state::VIEW_IMPORT_REQUEST; } else { - current_view_state = view_state::LIST; + current_view_state = ui::view_state::LIST_ALL; } active_invoice = administration_invoice_create_empty(); @@ -142,7 +142,7 @@ static void draw_expense_form(invoice* buffer, bool viewing_only = false) if (viewing_only) ImGui::EndDisabled(); } -static void ui_draw_expenses_list() +static void draw_expenses_list() { if (!administration_can_create_invoices()) { ImGui::PushStyleColor(ImGuiCol_Text, IM_COL32(0, 102, 204, 255)); // blue @@ -152,7 +152,7 @@ static void ui_draw_expenses_list() if (ImGui::IsItemHovered()) { ImGui::SetMouseCursor(ImGuiMouseCursor_Hand); if (ImGui::IsMouseClicked(ImGuiMouseButton_Left)) { - ui_set_state(main_state::UI_SETTINGS); + ui::set_state(ui::main_state::UI_SETTINGS); } } @@ -174,7 +174,7 @@ static void ui_draw_expenses_list() // Table header controls: create, import, and pagination. if (ImGui::Button(locale::get("form.create"))) { - current_view_state = view_state::CREATE; + current_view_state = ui::view_state::CREATE; active_invoice = administration_invoice_create_empty(); // @leak active_invoice.customer = administration_company_info_get(); active_invoice.is_outgoing = 0; @@ -184,13 +184,13 @@ static void ui_draw_expenses_list() char import_file_path[MAX_LEN_PATH] = {0}; ImGui::SameLine(); if (ImGui::FormInvoiceFileSelector("+ Import", import_file_path)) { // @locale::get - current_view_state = view_state::VIEW_IMPORT_REQUEST; + current_view_state = ui::view_state::VIEW_IMPORT_REQUEST; active_invoice = administration_invoice_create_empty(); // @leak active_invoice.customer = administration_company_info_get(); active_invoice.is_outgoing = 0; active_invoice.status = invoice_status::INVOICE_RECEIVED; - active_import_request = ai_document_to_invoice(import_file_path); + active_import_request = importer::ai_document_to_invoice(import_file_path); } if (current_page >= max_page-1) current_page = max_page-1; @@ -247,7 +247,7 @@ static void ui_draw_expenses_list() snprintf(btn_name, sizeof(btn_name), "%s##%d", locale::get("form.view"), i); if (ImGui::Button(btn_name)) { active_invoice = c; - current_view_state = view_state::VIEW; + current_view_state = ui::view_state::VIEW_EXISTING; } ImGui::SameLine(); @@ -255,7 +255,7 @@ static void ui_draw_expenses_list() snprintf(btn_name, sizeof(btn_name), "%s##%d", locale::get("form.change"), i); if (ImGui::Button(btn_name)) { active_invoice = administration_invoice_create_copy(&c); // We create a copy because of billing item list pointers. - current_view_state = view_state::EDIT; + current_view_state = ui::view_state::EDIT_EXISTING; } ImGui::SameLine(); @@ -287,10 +287,10 @@ static void ui_draw_expenses_list() } -static void ui_draw_expense_update() +static void draw_expense_update() { if (ImGui::Button(locale::get("form.back"))) { - current_view_state = view_state::LIST; + current_view_state = ui::view_state::LIST_ALL; } draw_expense_form(&active_invoice); @@ -302,19 +302,19 @@ static void ui_draw_expense_update() if (ImGui::Button(locale::get("form.save"))) { administration_invoice_update(&active_invoice); - current_view_state = view_state::LIST; + current_view_state = ui::view_state::LIST_ALL; - ui_destroy_expenses(); - ui_setup_expenses(); + ui::destroy_expenses(); + ui::setup_expenses(); } if (!can_save) ImGui::EndDisabled(); } -static void ui_draw_expense_create() +static void draw_expense_create() { if (ImGui::Button(locale::get("form.back"))) { - current_view_state = view_state::LIST; + current_view_state = ui::view_state::LIST_ALL; } draw_expense_form(&active_invoice); @@ -326,51 +326,51 @@ static void ui_draw_expense_create() if (ImGui::Button(locale::get("form.save"))) { administration_invoice_add(&active_invoice); - current_view_state = view_state::LIST; + current_view_state = ui::view_state::LIST_ALL; - ui_destroy_expenses(); - ui_setup_expenses(); + ui::destroy_expenses(); + ui::setup_expenses(); } if (!can_save) ImGui::EndDisabled(); } -static void ui_draw_expense_view() +static void draw_expense_view() { if (ImGui::Button(locale::get("form.back"))) { - current_view_state = view_state::LIST; + current_view_state = ui::view_state::LIST_ALL; } draw_expense_form(&active_invoice, true); } -static void ui_draw_import_request() +static void draw_import_request() { assert(active_import_request); - if (active_import_request->status == import_status::IMPORT_DONE) { + if (active_import_request->status == importer::status::IMPORT_DONE) { if (active_import_request->error == I_ERR_SUCCESS) { active_invoice = active_import_request->result; - current_view_state = view_state::CREATE; + current_view_state = ui::view_state::CREATE; active_import_request = 0; return; } else { if (ImGui::Button(locale::get("form.back"))) { - current_view_state = view_state::LIST; + current_view_state = ui::view_state::LIST_ALL; active_import_request = 0; return; } } } - ImGui::PushFont(fontBig); + ImGui::PushFont(ui::fontBig); ImVec2 windowSize = ImGui::GetWindowSize(); float radius = 60.0f; - const char* text = import_status_to_str(active_import_request->status); - if (active_import_request->error != I_ERR_SUCCESS) text = import_error_to_str(active_import_request->error); + const char* text = importer::status_to_string(active_import_request->status); + if (active_import_request->error != I_ERR_SUCCESS) text = importer::error_to_string(active_import_request->error); ImVec2 textSize = ImGui::CalcTextSize(text); ImGui::SetCursorPos(ImVec2((windowSize.x - textSize.x) * 0.5f, (windowSize.y) * 0.5f - radius - 40.0f)); @@ -388,14 +388,14 @@ static void ui_draw_import_request() ImGui::PopFont(); } -void ui_draw_expenses() +void ui::draw_expenses() { switch(current_view_state) { - case view_state::LIST: ui_draw_expenses_list(); break; - case view_state::CREATE: ui_draw_expense_create(); break; - case view_state::EDIT: ui_draw_expense_update(); break; - case view_state::VIEW: ui_draw_expense_view(); break; - case view_state::VIEW_IMPORT_REQUEST: ui_draw_import_request(); break; + case ui::view_state::LIST_ALL: draw_expenses_list(); break; + case ui::view_state::CREATE: draw_expense_create(); break; + case ui::view_state::EDIT_EXISTING: draw_expense_update(); break; + case ui::view_state::VIEW_EXISTING: draw_expense_view(); break; + case ui::view_state::VIEW_IMPORT_REQUEST: draw_import_request(); break; } }
\ No newline at end of file diff --git a/src/ui/ui_invoices.cpp b/src/ui/ui_invoices.cpp index ee816a9..1a039b9 100644 --- a/src/ui/ui_invoices.cpp +++ b/src/ui/ui_invoices.cpp @@ -29,7 +29,7 @@ #include "locales.hpp" -static view_state current_view_state = view_state::LIST; +static ui::view_state current_view_state = ui::view_state::LIST_ALL; static invoice active_invoice = {0}; static invoice selected_for_removal = {0}; @@ -38,14 +38,14 @@ static billing_item* invoice_items_buffer = 0; void draw_contact_form_ex(contact* buffer, bool viewing_only = false, bool with_autocomplete = false); void draw_addressee_form_ex(delivery_info* buffer, bool viewing_only = false); -void ui_destroy_invoices() +void ui::destroy_invoices() { free(invoice_items_buffer); } -void ui_setup_invoices() +void ui::setup_invoices() { - current_view_state = view_state::LIST; + current_view_state = ui::view_state::LIST_ALL; active_invoice = administration_invoice_create_empty(); u32 invoice_items_count = MAX_BILLING_ITEMS; @@ -251,7 +251,7 @@ static void draw_invoice_form(invoice* buffer, bool viewing_only = false) if (viewing_only) ImGui::EndDisabled(); } -static void ui_draw_invoices_list() +static void draw_invoices_list() { if (!administration_can_create_invoices()) { ImGui::PushStyleColor(ImGuiCol_Text, IM_COL32(0, 102, 204, 255)); // blue @@ -261,7 +261,7 @@ static void ui_draw_invoices_list() if (ImGui::IsItemHovered()) { ImGui::SetMouseCursor(ImGuiMouseCursor_Hand); if (ImGui::IsMouseClicked(ImGuiMouseButton_Left)) { - ui_set_state(main_state::UI_SETTINGS); + ui::set_state(ui::main_state::UI_SETTINGS); } } @@ -283,7 +283,7 @@ static void ui_draw_invoices_list() // Table header controls: create button and pagination. if (ImGui::Button(locale::get("form.create"))) { - current_view_state = view_state::CREATE; + current_view_state = ui::view_state::CREATE; active_invoice = administration_invoice_create_empty(); // @leak active_invoice.supplier = administration_company_info_get(); active_invoice.is_outgoing = 1; @@ -344,7 +344,7 @@ static void ui_draw_invoices_list() snprintf(btn_name, sizeof(btn_name), "%s##%d", locale::get("form.view"), i); if (ImGui::Button(btn_name)) { active_invoice = c; - current_view_state = view_state::VIEW; + current_view_state = ui::view_state::VIEW_EXISTING; } ImGui::SameLine(); @@ -354,7 +354,7 @@ static void ui_draw_invoices_list() snprintf(btn_name, sizeof(btn_name), "%s##%d", locale::get("form.change"), i); if (ImGui::Button(btn_name)) { active_invoice = administration_invoice_create_copy(&c); // We create a copy because of billing item list pointers. - current_view_state = view_state::EDIT; + current_view_state = ui::view_state::EDIT_EXISTING; } ImGui::SameLine(); @@ -387,10 +387,10 @@ static void ui_draw_invoices_list() } -static void ui_draw_invoice_update() +static void draw_invoice_update() { if (ImGui::Button(locale::get("form.back"))) { - current_view_state = view_state::LIST; + current_view_state = ui::view_state::LIST_ALL; } draw_invoice_form(&active_invoice); @@ -402,19 +402,19 @@ static void ui_draw_invoice_update() if (ImGui::Button(locale::get("form.save"))) { administration_invoice_update(&active_invoice); - current_view_state = view_state::LIST; + current_view_state = ui::view_state::LIST_ALL; - ui_destroy_invoices(); - ui_setup_invoices(); + ui::destroy_invoices(); + ui::setup_invoices(); } if (!can_save) ImGui::EndDisabled(); } -static void ui_draw_invoice_create() +static void draw_invoice_create() { if (ImGui::Button(locale::get("form.back"))) { - current_view_state = view_state::LIST; + current_view_state = ui::view_state::LIST_ALL; } draw_invoice_form(&active_invoice); @@ -426,31 +426,31 @@ static void ui_draw_invoice_create() if (ImGui::Button(locale::get("form.save"))) { administration_invoice_add(&active_invoice); - current_view_state = view_state::LIST; + current_view_state = ui::view_state::LIST_ALL; - ui_destroy_invoices(); - ui_setup_invoices(); + ui::destroy_invoices(); + ui::setup_invoices(); } if (!can_save) ImGui::EndDisabled(); } -static void ui_draw_invoice_view() +static void draw_invoice_view() { if (ImGui::Button(locale::get("form.back"))) { - current_view_state = view_state::LIST; + current_view_state = ui::view_state::LIST_ALL; } draw_invoice_form(&active_invoice, true); } -void ui_draw_invoices() +void ui::draw_invoices() { switch(current_view_state) { - case view_state::LIST: ui_draw_invoices_list(); break; - case view_state::CREATE: ui_draw_invoice_create(); break; - case view_state::EDIT: ui_draw_invoice_update(); break; - case view_state::VIEW: ui_draw_invoice_view(); break; + case ui::view_state::LIST_ALL: draw_invoices_list(); break; + case ui::view_state::CREATE: draw_invoice_create(); break; + case ui::view_state::EDIT_EXISTING: draw_invoice_update(); break; + case ui::view_state::VIEW_EXISTING: draw_invoice_view(); break; } }
\ No newline at end of file diff --git a/src/ui/ui_log.cpp b/src/ui/ui_log.cpp index 48eaf1c..d19e26e 100644 --- a/src/ui/ui_log.cpp +++ b/src/ui/ui_log.cpp @@ -21,7 +21,7 @@ #include "logger.hpp" #include "locales.hpp" -void ui_draw_log() +void ui::draw_log() { logger::program_log* l = logger::get(); diff --git a/src/ui/ui_main.cpp b/src/ui/ui_main.cpp index ef2e9df..b54ca62 100644 --- a/src/ui/ui_main.cpp +++ b/src/ui/ui_main.cpp @@ -22,50 +22,50 @@ #include "administration_writer.hpp" #include "administration_reader.hpp" -static main_state ui_state = main_state::UI_END; -void (*drawcalls[main_state::UI_END])(void) = { - ui_draw_invoices, - ui_draw_expenses, - ui_draw_contacts, - ui_draw_earnings, +static ui::main_state ui_state = ui::main_state::UI_END; +void (*drawcalls[ui::main_state::UI_END])(void) = { + ui::draw_invoices, + ui::draw_expenses, + ui::draw_contacts, + ui::draw_earnings, 0, - ui_draw_projects, - ui_draw_settings, - ui_draw_log, + ui::draw_projects, + ui::draw_settings, + ui::draw_log, }; -void (*setupcalls[main_state::UI_END])(void) = { - ui_setup_invoices, - ui_setup_expenses, - ui_setup_contacts, - ui_setup_earnings, +void (*setupcalls[ui::main_state::UI_END])(void) = { + ui::setup_invoices, + ui::setup_expenses, + ui::setup_contacts, + ui::setup_earnings, 0, - ui_setup_projects, - ui_setup_settings, + ui::setup_projects, + ui::setup_settings, 0, }; -void (*destroycalls[main_state::UI_END])(void) = { - ui_destroy_invoices, - ui_destroy_expenses, +void (*destroycalls[ui::main_state::UI_END])(void) = { + ui::destroy_invoices, + ui::destroy_expenses, 0, - ui_destroy_earnings, + ui::destroy_earnings, 0, 0, - ui_destroy_settings, + ui::destroy_settings, 0, }; -void ui_set_state(main_state state) +void ui::set_state(ui::main_state state) { - if (ui_state != main_state::UI_END && destroycalls[ui_state]) destroycalls[ui_state](); + if (ui_state != ui::main_state::UI_END && destroycalls[ui_state]) destroycalls[ui_state](); ui_state = state; if (setupcalls[ui_state]) setupcalls[ui_state](); } -void ui_draw_main() +void ui::draw_main() { - if (ui_state == main_state::UI_END) ui_set_state(main_state::UI_INVOICES); + if (ui_state == ui::main_state::UI_END) ui::set_state(ui::main_state::UI_INVOICES); // @locale::get if (ImGui::BeginMainMenuBar()) @@ -81,7 +81,7 @@ void ui_draw_main() if (ImGui::BeginMenu("Help")) { - if (ImGui::MenuItem("Event Log")) { ui_set_state(main_state::UI_LOG); } + if (ImGui::MenuItem("Event Log")) { ui::set_state(ui::main_state::UI_LOG); } ImGui::EndMenu(); } @@ -107,22 +107,22 @@ void ui_draw_main() float buttonWidth = sidePanelWidth; - if (ImGui::Button(locale::get("nav.invoices"), ImVec2(buttonWidth, 24))) ui_set_state(main_state::UI_INVOICES); - if (ImGui::Button(locale::get("nav.expenses"), ImVec2(buttonWidth, 24))) ui_set_state(main_state::UI_EXPENSES); - if (ImGui::Button(locale::get("nav.contacts"), ImVec2(buttonWidth, 24))) ui_set_state(main_state::UI_CONTACTS); + if (ImGui::Button(locale::get("nav.invoices"), ImVec2(buttonWidth, 24))) ui::set_state(ui::main_state::UI_INVOICES); + if (ImGui::Button(locale::get("nav.expenses"), ImVec2(buttonWidth, 24))) ui::set_state(ui::main_state::UI_EXPENSES); + if (ImGui::Button(locale::get("nav.contacts"), ImVec2(buttonWidth, 24))) ui::set_state(ui::main_state::UI_CONTACTS); static bool reports_opened = true; if (ImGui::Button(locale::get("nav.reports"), ImVec2(buttonWidth, 24))) reports_opened = !reports_opened; if (reports_opened) { ImGui::PushStyleVar(ImGuiStyleVar_FramePadding, ImVec2(20.0f, 0.0f)); - if (ImGui::Button(locale::get("nav.reports.results"), ImVec2(buttonWidth, 24))) ui_set_state(main_state::UI_REPORT_RESULTS); - if (ImGui::Button(locale::get("nav.reports.tax"), ImVec2(buttonWidth, 24))) ui_set_state(main_state::UI_REPORT_TAX); + if (ImGui::Button(locale::get("nav.reports.results"), ImVec2(buttonWidth, 24))) ui::set_state(ui::main_state::UI_REPORT_RESULTS); + if (ImGui::Button(locale::get("nav.reports.tax"), ImVec2(buttonWidth, 24))) ui::set_state(ui::main_state::UI_REPORT_TAX); ImGui::PopStyleVar(); } - if (ImGui::Button(locale::get("nav.projects"), ImVec2(buttonWidth, 24))) ui_set_state(main_state::UI_PROJECTS); - if (ImGui::Button(locale::get("nav.settings"), ImVec2(buttonWidth, 24))) ui_set_state(main_state::UI_SETTINGS); + if (ImGui::Button(locale::get("nav.projects"), ImVec2(buttonWidth, 24))) ui::set_state(ui::main_state::UI_PROJECTS); + if (ImGui::Button(locale::get("nav.settings"), ImVec2(buttonWidth, 24))) ui::set_state(ui::main_state::UI_SETTINGS); ImGui::PopStyleColor(1); ImGui::PopStyleVar(3); @@ -161,7 +161,7 @@ void ui_draw_main() } ImGui::SameLine(); - ui_draw_status(); + ui::draw_status(); ImGui::End(); ImGui::PopStyleVar(); diff --git a/src/ui/ui_projects.cpp b/src/ui/ui_projects.cpp index 560bc72..be0cc2a 100644 --- a/src/ui/ui_projects.cpp +++ b/src/ui/ui_projects.cpp @@ -22,25 +22,25 @@ #include "administration_writer.hpp" #include "locales.hpp" -static view_state current_view_state = view_state::LIST; +static ui::view_state current_view_state = ui::view_state::LIST_ALL; static project selected_for_cancellation; static project active_project; -void ui_setup_projects() +void ui::setup_projects() { - current_view_state = view_state::LIST; + current_view_state = ui::view_state::LIST_ALL; active_project = administration_project_create_empty(); } static void draw_project_form() { float widthAvailable = ImGui::GetContentRegionAvail().x; - bool viewing_only = (current_view_state == view_state::VIEW); + bool viewing_only = (current_view_state == ui::view_state::VIEW_EXISTING); static const char* selected_country = NULL; if (ImGui::Button(locale::get("form.back"))) { - current_view_state = view_state::LIST; + current_view_state = ui::view_state::LIST_ALL; active_project = administration_project_create_empty(); selected_country = 0; return; @@ -65,15 +65,15 @@ static void draw_project_form() // Save button ImGui::Spacing(); if (ImGui::Button(locale::get("form.save"))) { - if (current_view_state == view_state::CREATE) { + if (current_view_state == ui::view_state::CREATE) { administration_project_add(active_project); } - else if (current_view_state == view_state::EDIT) { + else if (current_view_state == ui::view_state::EDIT_EXISTING) { administration_project_update(active_project); } - current_view_state = view_state::LIST; + current_view_state = ui::view_state::LIST_ALL; selected_country = 0; active_project = administration_project_create_empty(); } @@ -93,7 +93,7 @@ static void draw_project_list() if (ImGui::Button(locale::get("form.create"))) { - current_view_state = view_state::CREATE; + current_view_state = ui::view_state::CREATE; active_project = administration_project_create_empty(); } @@ -142,7 +142,7 @@ static void draw_project_list() snprintf(btn_name, sizeof(btn_name), "%s##%d", locale::get("form.view"), i); if (ImGui::Button(btn_name)) { active_project = c; - current_view_state = view_state::VIEW; + current_view_state = ui::view_state::VIEW_EXISTING; } if (c.state == project_state::PROJECT_RUNNING) @@ -151,7 +151,7 @@ static void draw_project_list() snprintf(btn_name, sizeof(btn_name), "%s##%d", locale::get("form.change"), i); if (ImGui::Button(btn_name)) { active_project = c; - current_view_state = view_state::EDIT; + current_view_state = ui::view_state::EDIT_EXISTING; } ImGui::SameLine(); @@ -182,13 +182,13 @@ static void draw_project_list() } } -void ui_draw_projects() +void ui::draw_projects() { switch(current_view_state) { - case view_state::LIST: draw_project_list(); break; - case view_state::CREATE: draw_project_form(); break; - case view_state::EDIT: draw_project_form(); break; - case view_state::VIEW: draw_project_form(); break; + case ui::view_state::LIST_ALL: draw_project_list(); break; + case ui::view_state::CREATE: draw_project_form(); break; + case ui::view_state::EDIT_EXISTING: draw_project_form(); break; + case ui::view_state::VIEW_EXISTING: draw_project_form(); break; } }
\ No newline at end of file diff --git a/src/ui/ui_settings.cpp b/src/ui/ui_settings.cpp index e497615..a6ce57a 100644 --- a/src/ui/ui_settings.cpp +++ b/src/ui/ui_settings.cpp @@ -37,13 +37,13 @@ cost_center* cost_centers = 0; static int select_company_tab = 0; static ai_service new_service; -void ui_destroy_settings() +void ui::destroy_settings() { free(tax_rates); free(cost_centers); } -void ui_setup_settings() +void ui::setup_settings() { select_company_tab = 1; company_info = administration_company_info_get(); @@ -59,7 +59,7 @@ void ui_setup_settings() new_service = administration_get_ai_service(); } -static void ui_draw_vat_rates() +static void draw_vat_rates() { static bool is_adding_item = false; static tax_rate new_tax_rate; @@ -151,8 +151,8 @@ static void ui_draw_vat_rates() administration_tax_rate_update(new_tax_rate); - ui_destroy_settings(); - ui_setup_settings(); + ui::destroy_settings(); + ui::setup_settings(); } ImGui::SameLine(); @@ -197,8 +197,8 @@ static void ui_draw_vat_rates() administration_tax_rate_add(new_tax_rate); - ui_destroy_settings(); - ui_setup_settings(); + ui::destroy_settings(); + ui::setup_settings(); } ImGui::SameLine(); @@ -215,7 +215,7 @@ static void ui_draw_vat_rates() } } -static void ui_draw_cost_centers() +static void draw_cost_centers() { static bool is_adding_item = false; static cost_center new_cost_center; @@ -255,8 +255,8 @@ static void ui_draw_cost_centers() memset(&new_cost_center, 0, sizeof(new_cost_center)); - ui_destroy_settings(); - ui_setup_settings(); + ui::destroy_settings(); + ui::setup_settings(); } if (!is_desc_valid) ImGui::EndDisabled(); @@ -308,8 +308,8 @@ static void ui_draw_cost_centers() is_editing_item = false; administration_cost_center_add(new_cost_center); - ui_destroy_settings(); - ui_setup_settings(); + ui::destroy_settings(); + ui::setup_settings(); } if (!can_save) ImGui::EndDisabled(); @@ -333,7 +333,7 @@ static void ui_draw_cost_centers() } } -static void ui_draw_services() +static void draw_services() { // AI service if (ImGui::CollapsingHeader(locale::get("settings.services.ai_service"))) @@ -365,7 +365,7 @@ static void ui_draw_services() } } -void ui_draw_settings() +void ui::draw_settings() { if (ImGui::BeginTabBar("SettingsTabBar")) { @@ -387,17 +387,17 @@ void ui_draw_settings() } if (ImGui::BeginTabItem(locale::get("settings.table.vatrates"))) { - ui_draw_vat_rates(); + draw_vat_rates(); ImGui::EndTabItem(); } if (ImGui::BeginTabItem(locale::get("settings.table.costcenters"))) { - ui_draw_cost_centers(); + draw_cost_centers(); ImGui::EndTabItem(); } if (ImGui::BeginTabItem(locale::get("settings.table.services"))) { - ui_draw_services(); + draw_services(); ImGui::EndTabItem(); } ImGui::EndTabBar(); |
