From 1fd1e4b5f2418e3ac2909658993bfedb615537ec Mon Sep 17 00:00:00 2001 From: rtk0c Date: Thu, 6 May 2021 21:56:40 -0700 Subject: Change brace style to on new line, add initial deliveries view when an order entry is selected --- core/src/UI/Localization.hpp | 3 +- core/src/UI/States.cpp | 15 +- core/src/UI/States.hpp | 5 +- core/src/UI/UI_DatabaseView.cpp | 314 +++++++++++++++++++++++++++++----------- core/src/UI/UI_Items.cpp | 45 ++++-- core/src/UI/UI_MainWindow.cpp | 9 +- core/src/UI/UI_Settings.cpp | 3 +- core/src/UI/UI_Utils.cpp | 30 ++-- core/src/UI/UI_Workflows.cpp | 35 +++-- 9 files changed, 334 insertions(+), 125 deletions(-) (limited to 'core/src/UI') diff --git a/core/src/UI/Localization.hpp b/core/src/UI/Localization.hpp index 777c161..043170a 100644 --- a/core/src/UI/Localization.hpp +++ b/core/src/UI/Localization.hpp @@ -7,7 +7,8 @@ using namespace std::literals::string_view_literals; -class LocaleStrings { +class LocaleStrings +{ public: static std::unique_ptr Instance; diff --git a/core/src/UI/States.cpp b/core/src/UI/States.cpp index 546e1ab..b7b4c9f 100644 --- a/core/src/UI/States.cpp +++ b/core/src/UI/States.cpp @@ -8,22 +8,26 @@ static std::unique_ptr uiStateInstance; -void UIState::Init() { +void UIState::Init() +{ uiStateInstance = std::make_unique(); } -void UIState::Shutdown() { +void UIState::Shutdown() +{ if (uiStateInstance) { uiStateInstance->CloseCurrentProject(); uiStateInstance = nullptr; } } -UIState& UIState::GetInstance() { +UIState& UIState::GetInstance() +{ return *uiStateInstance; } -void UIState::SetCurrentProject(std::unique_ptr project) { +void UIState::SetCurrentProject(std::unique_ptr project) +{ CloseCurrentProject(); if (project) { GlobalStates::GetInstance().MoveProjectToTop(*project); @@ -31,7 +35,8 @@ void UIState::SetCurrentProject(std::unique_ptr project) { CurrentProject = std::move(project); } -void UIState::CloseCurrentProject() { +void UIState::CloseCurrentProject() +{ if (CurrentProject) { CurrentProject->WriteToDisk(); CurrentProject = nullptr; diff --git a/core/src/UI/States.hpp b/core/src/UI/States.hpp index 4cc3b0f..d314494 100644 --- a/core/src/UI/States.hpp +++ b/core/src/UI/States.hpp @@ -2,12 +2,13 @@ #include "cplt_fwd.hpp" -#include #include +#include /// Minimal state shared by all UI components, such as database, items, export, etc. /// Note that global components (settings) is not supposed to access these. -class UIState { +class UIState +{ public: static void Init(); static void Shutdown(); diff --git a/core/src/UI/UI_DatabaseView.cpp b/core/src/UI/UI_DatabaseView.cpp index 96009fb..bc458da 100644 --- a/core/src/UI/UI_DatabaseView.cpp +++ b/core/src/UI/UI_DatabaseView.cpp @@ -10,7 +10,9 @@ #include #include #include +#include #include +#include #include #include @@ -19,27 +21,36 @@ namespace { // TODO move to Settings constexpr int kMaxEntriesPerPage = 20; -class SaleEntry { -public: - std::string Customer; - std::string Deadline; - std::string DeliveryTime; +enum class DeliveryDirection +{ + FactoryToWarehouse, + WarehouseToCustomer, }; -class PurchaseEntry { -public: - std::string Factory; - std::string OrderTime; - std::string DeliveryTime; +struct DeliveryEntry +{ + std::string ShipmentTime; + std::string ArriveTime; + DeliveryDirection Direction; + + const char* StringifyDirection() const + { + switch (Direction) { + case DeliveryDirection::FactoryToWarehouse: return "Factory to warehouse"; + case DeliveryDirection::WarehouseToCustomer: return "Warehouse to customer"; + } + } }; -class GenericTableView { +class GenericTableView +{ protected: // Translation entries for implementer to fill out const char* mEditDialogTitle; SQLite::Statement* mGetRowCountStatement; SQLite::Statement* mGetRowsStatement; + SQLite::Statement* mFilterRowsStatement; Project* mProject; @@ -69,28 +80,33 @@ protected: int mSelectedEntryRowId; public: - static int CalcPageForRowId(int64_t rowId) { + static int CalcPageForRowId(int64_t rowId) + { return rowId / kMaxEntriesPerPage; } /// Calculate range [begin, end) of index for the list of entries that are currently visible that the path-th page would show. /// i.e. when there is a filter, look into \c mActiveEntryIndices; when there is no filter, use directly. - static std::pair CalcRangeForPage(int page) { + static std::pair CalcRangeForPage(int page) + { int begin = page * kMaxEntriesPerPage; return { begin, begin + kMaxEntriesPerPage }; } - Project* GetProject() const { + Project* GetProject() const + { return mProject; } - virtual void OnProjectChanged(Project* newProject) { + virtual void OnProjectChanged(Project* newProject) + { mProject = newProject; if (mGetRowCountStatement->executeStep()) { mRowCount = mGetRowCountStatement->getColumn(0).getInt(); } else { - // TODO report error + std::cerr << "Failed to fetch row count from SQLite.\n"; + mRowCount = 0; } mFirstCachedRowId = 0; @@ -105,13 +121,16 @@ public: mSelectedEntryRowId = -1; } - TableRowsFilter* GetFilter() const { + TableRowsFilter* GetFilter() const + { return mActiveFilter.get(); } - virtual void OnFilterChanged() { - auto& stmt = mProject->GetTransactionsModel().GetSales().FilterRowsStatement; - DEFER { + virtual void OnFilterChanged() + { + auto& stmt = *mFilterRowsStatement; + DEFER + { stmt.reset(); }; @@ -128,12 +147,14 @@ public: mSelectedEntryRowId = -1; } - void OnFilterChanged(std::unique_ptr filter) { + void OnFilterChanged(std::unique_ptr filter) + { mActiveFilter = std::move(filter); OnFilterChanged(); } - void Draw() { + void Draw() + { bool dummy = true; auto ls = LocaleStrings::Instance.get(); @@ -161,8 +182,24 @@ public: ImGui::EndPopup(); } - if (ImGui::BeginTable("", GetTableColumnCount())) { + ImGui::SameLine(); + if (ImGui::Button(ls->Add.Get())) { + // TODO + } + if (mSelectedEntryRowId == -1) { + DrawMainTable(); + } else { + // TODO better layout + DrawMainTable(); + ImGui::SameLine(); + DrawDeliveriesTable(); + } + } + + void DrawMainTable() + { + if (ImGui::BeginTable("DataTable", GetTableColumnCount(), ImGuiTableFlags_ScrollX)) { SetupTableColumns(); ImGui::TableHeadersRow(); @@ -184,34 +221,94 @@ public: } } - void SetPage(int page) { + void DrawDeliveriesTable() + { + if (ImGui::BeginTable("DeliveriesTable", 2)) { + + ImGui::TableSetupColumn("Shipment time"); + ImGui::TableSetupColumn("Arrival time"); + ImGui::TableHeadersRow(); + + auto& deliveries = GetEntryAssociatedDeliveries(mSelectedEntryRowId); + for (auto& delivery : deliveries) { + ImGui::TableNextRow(); + + ImGui::TableNextColumn(); + ImGui::TextUnformatted(delivery.ShipmentTime.c_str()); + + ImGui::TableNextColumn(); + ImGui::TextUnformatted(delivery.ArriveTime.c_str()); + } + + ImGui::EndTable(); + } + } + + void SetPage(int page) + { mCurrentPage = page; EnsureCacheCoversPage(page); } - int RowIdToIndex(int64_t rowId) const { + int RowIdToIndex(int64_t rowId) const + { return rowId - mFirstCachedRowId; } - int64_t IndexToRowId(int index) const { + int64_t IndexToRowId(int index) const + { return index + mFirstCachedRowId; } + std::vector LoadDeliveriesEntries(int64_t orderRowId, DeliveryDirection type) + { + bool outgoingFlag; + switch (type) { + case DeliveryDirection::FactoryToWarehouse: outgoingFlag = false; break; + case DeliveryDirection::WarehouseToCustomer: outgoingFlag = true; break; + } + + auto& stmt = mProject->GetTransactionsModel().GetDeliveries().FilterByTypeAndId; + DEFER + { + stmt.reset(); + }; + + stmt.bind(1, orderRowId); + stmt.bind(2, static_cast(type)); + + std::vector entries; + int sendTimeCol = stmt.getColumnIndex("ShipmentTime"); + int arrivalTimeCol = stmt.getColumnIndex("ArrivalTime"); + while (stmt.executeStep()) { + entries.push_back(DeliveryEntry{ + .ShipmentTime = StringifyTimeStamp(stmt.getColumn(arrivalTimeCol).getInt64()), + .ArriveTime = StringifyTimeStamp(stmt.getColumn(sendTimeCol).getInt64()), + .Direction = type, + }); + } + + return entries; + } + protected: virtual int GetTableColumnCount() const = 0; virtual void SetupTableColumns() = 0; + virtual const std::vector& GetEntryAssociatedDeliveries(int rowId) = 0; virtual void DisplayEntry(int rowId) = 0; virtual void EditEntry(int rowId) = 0; virtual void ClearEntries() = 0; - void EnsureCacheCoversPage(int page) { + void EnsureCacheCoversPage(int page) + { auto [begin, end] = CalcRangeForPage(page); EnsureCacheCovers(begin, end - 1); } - void EnsureCacheCovers(int64_t firstRow, int64_t lastRow) { + void EnsureCacheCovers(int64_t firstRow, int64_t lastRow) + { if (firstRow > lastRow) { std::swap(firstRow, lastRow); } @@ -239,7 +336,21 @@ protected: virtual void EnsureCacheCoversImpl(int newFirst, int newLast) = 0; template - std::vector LoadRange(int64_t begin, int64_t end, TCollector&& collector) { + void LoadExtraEntries(std::vector& entries, int newFirst, int newLast, TCollector&& collector) + { + auto front = LoadRange(newFirst, mFirstCachedRowId, collector); + auto back = LoadRange(mLastCachedRowId + 1, newLast + 1, collector); + + mFirstCachedRowId -= front.size(); + mLastCachedRowId += back.size(); + + entries.insert(entries.begin(), std::make_move_iterator(front.begin()), std::make_move_iterator(front.end())); + entries.insert(entries.end(), std::make_move_iterator(back.begin()), std::make_move_iterator(back.end())); + } + + template + std::vector LoadRange(int64_t begin, int64_t end, TCollector&& collector) + { std::vector result; size_t size = end - begin; @@ -249,10 +360,10 @@ protected: result.reserve(size); - DEFER { + DEFER + { mGetRowsStatement->reset(); }; - mGetRowsStatement->bind(1, begin); mGetRowsStatement->bind(2, end); @@ -260,46 +371,75 @@ protected: return result; } - void UpdateLastPage() { +private: + void UpdateLastPage() + { mLastPage = mActiveEntries.empty() ? CalcPageForRowId(mRowCount) : CalcPageForRowId(mActiveEntries.back()); } }; -class SalesTableView : public GenericTableView { +class SaleEntry +{ +public: + std::vector AssociatedDeliveries; + std::string Customer; + std::string Deadline; + std::string DeliveryTime; + bool DeliveriesCached = false; +}; + +class SalesTableView : public GenericTableView +{ private: /// A cached, contiguous (row id of each entry is monotonically increasing, but not necessarily starts at 0) list ready-to-be-presented entries. May be incomplete. std::vector mEntries; public: - SalesTableView() { + SalesTableView() + { auto ls = LocaleStrings::Instance.get(); mEditDialogTitle = ls->EditSaleEntryDialogTitle.Get(); } - virtual void OnProjectChanged(Project* newProject) override { + virtual void OnProjectChanged(Project* newProject) override + { auto& sales = newProject->GetTransactionsModel().GetSales(); - mGetRowCountStatement = &sales.GetRowCountStatement; - mGetRowsStatement = &sales.GetRowsStatement; + mGetRowCountStatement = &sales.GetRowCount; + mGetRowsStatement = &sales.GetRows; + // mFilterRowsStatement = &sales.FilterRows; GenericTableView::OnProjectChanged(newProject); } protected: - virtual int GetTableColumnCount() const override { + virtual int GetTableColumnCount() const override + { return 3; } - virtual void SetupTableColumns() override { + virtual void SetupTableColumns() override + { auto ls = LocaleStrings::Instance.get(); ImGui::TableSetupColumn(ls->DatabaseCustomerColumn.Get()); ImGui::TableSetupColumn(ls->DatabaseDeadlineColumn.Get()); ImGui::TableSetupColumn(ls->DatabaseDeliveryTimeColumn.Get()); } - virtual void DisplayEntry(int rowId) override { - auto& entry = GetEntry(rowId); + virtual const std::vector& GetEntryAssociatedDeliveries(int rowId) override + { + auto& entry = mEntries[RowIdToIndex(rowId)]; + if (!entry.DeliveriesCached) { + entry.AssociatedDeliveries = LoadDeliveriesEntries(rowId, DeliveryDirection::FactoryToWarehouse); + entry.DeliveriesCached = true; + } + return entry.AssociatedDeliveries; + } + + virtual void DisplayEntry(int rowId) override + { + auto& entry = mEntries[RowIdToIndex(rowId)]; auto ls = LocaleStrings::Instance.get(); ImGui::PushID(rowId); @@ -323,15 +463,18 @@ protected: ImGui::PopID(); } - virtual void EditEntry(int rowId) override { - // TODO + virtual void EditEntry(int rowId) override + { + // `TODO` } - virtual void ClearEntries() override { + virtual void ClearEntries() override + { mEntries.clear(); } - virtual void EnsureCacheCoversImpl(int newFirst, int newLast) override { + virtual void EnsureCacheCoversImpl(int newFirst, int newLast) override + { auto CollectRows = [&](std::vector& result) { auto& stmt = *mGetRowsStatement; int customerCol = stmt.getColumnIndex("Customer"); @@ -350,53 +493,69 @@ protected: } }; - auto front = LoadRange(newFirst, mFirstCachedRowId, CollectRows); - auto back = LoadRange(mLastCachedRowId + 1, newLast + 1, CollectRows); - - mFirstCachedRowId -= front.size(); - mLastCachedRowId += back.size(); - - mEntries.insert(mEntries.begin(), std::make_move_iterator(front.begin()), std::make_move_iterator(front.end())); - mEntries.insert(mEntries.end(), std::make_move_iterator(back.begin()), std::make_move_iterator(back.end())); + LoadExtraEntries(mEntries, newFirst, newLast, CollectRows); } +}; - SaleEntry& GetEntry(int rowId) { - return mEntries[RowIdToIndex(rowId)]; - } +class PurchaseEntry +{ +public: + std::vector AssociatedDeliveries; + std::string Factory; + std::string OrderTime; + std::string DeliveryTime; + bool DeliveriesCached; }; -class PurchasesTableView : public GenericTableView { +class PurchasesTableView : public GenericTableView +{ private: std::vector mEntries; public: - PurchasesTableView() { + PurchasesTableView() + { auto ls = LocaleStrings::Instance.get(); mEditDialogTitle = ls->EditPurchaseEntryDialogTitle.Get(); } - virtual void OnProjectChanged(Project* newProject) override { + virtual void OnProjectChanged(Project* newProject) override + { auto& purchases = newProject->GetTransactionsModel().GetPurchases(); - mGetRowCountStatement = &purchases.GetRowCountStatement; - mGetRowsStatement = &purchases.GetRowsStatement; + mGetRowCountStatement = &purchases.GetRowCount; + mGetRowsStatement = &purchases.GetRows; + // mFilterRowsStatement = &purchases.FilterRowsStatement; GenericTableView::OnProjectChanged(newProject); } protected: - virtual int GetTableColumnCount() const override { + virtual int GetTableColumnCount() const override + { return 3; } - virtual void SetupTableColumns() override { + virtual void SetupTableColumns() override + { auto ls = LocaleStrings::Instance.get(); ImGui::TableSetupColumn(ls->DatabaseFactoryColumn.Get()); ImGui::TableSetupColumn(ls->DatabaseOrderTimeColumn.Get()); ImGui::TableSetupColumn(ls->DatabaseDeliveryTimeColumn.Get()); } - virtual void DisplayEntry(int rowId) override { - auto& entry = GetEntry(rowId); + virtual const std::vector& GetEntryAssociatedDeliveries(int rowId) override + { + auto& entry = mEntries[RowIdToIndex(rowId)]; + if (!entry.DeliveriesCached) { + entry.AssociatedDeliveries = LoadDeliveriesEntries(rowId, DeliveryDirection::FactoryToWarehouse); + entry.DeliveriesCached = true; + } + return entry.AssociatedDeliveries; + } + + virtual void DisplayEntry(int rowId) override + { + auto& entry = mEntries[RowIdToIndex(rowId)]; auto ls = LocaleStrings::Instance.get(); ImGui::PushID(rowId); @@ -424,15 +583,18 @@ protected: ImGui::PopID(); } - virtual void EditEntry(int rowId) override { + virtual void EditEntry(int rowId) override + { // TODO } - virtual void ClearEntries() override { + virtual void ClearEntries() override + { mEntries.clear(); } - virtual void EnsureCacheCoversImpl(int newFirst, int newLast) override { + virtual void EnsureCacheCoversImpl(int newFirst, int newLast) override + { auto CollectRows = [&](std::vector& result) { auto& stmt = *mGetRowsStatement; int factoryCol = stmt.getColumnIndex("Factory"); @@ -451,23 +613,13 @@ protected: } }; - auto front = LoadRange(newFirst, mFirstCachedRowId, CollectRows); - auto back = LoadRange(mLastCachedRowId + 1, newLast + 1, CollectRows); - - mFirstCachedRowId -= front.size(); - mLastCachedRowId += back.size(); - - mEntries.insert(mEntries.begin(), std::make_move_iterator(front.begin()), std::make_move_iterator(front.end())); - mEntries.insert(mEntries.end(), std::make_move_iterator(back.begin()), std::make_move_iterator(back.end())); - } - - PurchaseEntry& GetEntry(int rowId) { - return mEntries[RowIdToIndex(rowId)]; + LoadExtraEntries(mEntries, newFirst, newLast, CollectRows); } }; } // namespace -void UI::DatabaseViewTab() { +void UI::DatabaseViewTab() +{ auto ls = LocaleStrings::Instance.get(); auto& uis = UIState::GetInstance(); diff --git a/core/src/UI/UI_Items.cpp b/core/src/UI/UI_Items.cpp index 624f942..8633c1f 100644 --- a/core/src/UI/UI_Items.cpp +++ b/core/src/UI/UI_Items.cpp @@ -10,7 +10,8 @@ namespace { -enum class ActionResult { +enum class ActionResult +{ Confirmed, Canceled, Pending, @@ -19,9 +20,16 @@ enum class ActionResult { /// \param list Item list that the item is in. /// \param item A non-null pointer to the currently being edited item. It should not change until this function returns a non-\c ActionResult::Pending value. template -ActionResult ItemEditor(ItemList& list, T* item) { - constexpr bool kHasDescription = requires(T t) { t.GetDescription(); }; - constexpr bool kHasEmail = requires(T t) { t.GetEmail(); }; +ActionResult ItemEditor(ItemList& list, T* item) +{ + constexpr bool kHasDescription = requires(T t) + { + t.GetDescription(); + }; + constexpr bool kHasEmail = requires(T t) + { + t.GetEmail(); + }; auto ls = LocaleStrings::Instance.get(); auto& uis = UIState::GetInstance(); @@ -88,11 +96,24 @@ ActionResult ItemEditor(ItemList& list, T* item) { } template -void ItemListEntries(ItemList& list, int& selectedIdx) { - constexpr bool kHasDescription = requires(T t) { t.GetDescription(); }; - constexpr bool kHasEmail = requires(T t) { t.GetEmail(); }; - constexpr bool kHasStock = requires(T t) { t.GetPrice(); }; - constexpr bool kHasPrice = requires(T t) { t.GetPrice(); }; +void ItemListEntries(ItemList& list, int& selectedIdx) +{ + constexpr bool kHasDescription = requires(T t) + { + t.GetDescription(); + }; + constexpr bool kHasEmail = requires(T t) + { + t.GetEmail(); + }; + constexpr bool kHasStock = requires(T t) + { + t.GetPrice(); + }; + constexpr bool kHasPrice = requires(T t) + { + t.GetPrice(); + }; constexpr int kColumns = 1 /* Name column */ + kHasDescription + kHasEmail + kHasStock + kHasPrice; auto ls = LocaleStrings::Instance.get(); @@ -148,7 +169,8 @@ void ItemListEntries(ItemList& list, int& selectedIdx) { } template -void ItemListEditor(ItemList& list) { +void ItemListEditor(ItemList& list) +{ auto ls = LocaleStrings::Instance.get(); bool opened = true; @@ -216,7 +238,8 @@ void ItemListEditor(ItemList& list) { } } // namespace -void UI::ItemsTab() { +void UI::ItemsTab() +{ auto ls = LocaleStrings::Instance.get(); auto& uis = UIState::GetInstance(); diff --git a/core/src/UI/UI_MainWindow.cpp b/core/src/UI/UI_MainWindow.cpp index 4f09281..62a195e 100644 --- a/core/src/UI/UI_MainWindow.cpp +++ b/core/src/UI/UI_MainWindow.cpp @@ -15,7 +15,8 @@ namespace fs = std::filesystem; namespace { -void ProjectTab_Normal() { +void ProjectTab_Normal() +{ auto ls = LocaleStrings::Instance.get(); auto& gs = GlobalStates::GetInstance(); auto& uis = UIState::GetInstance(); @@ -33,7 +34,8 @@ void ProjectTab_Normal() { ImGui::Text("%s%s", ls->ActiveProjectPath.Get(), uis.CurrentProject->GetPathString().c_str()); } -void ProjectTab_NoProject() { +void ProjectTab_NoProject() +{ auto ls = LocaleStrings::Instance.get(); auto& gs = GlobalStates::GetInstance(); auto& uis = UIState::GetInstance(); @@ -186,7 +188,8 @@ void ProjectTab_NoProject() { } } // namespace -void UI::MainWindow() { +void UI::MainWindow() +{ auto ls = LocaleStrings::Instance.get(); auto& uis = UIState::GetInstance(); diff --git a/core/src/UI/UI_Settings.cpp b/core/src/UI/UI_Settings.cpp index 3dbb0d2..da935c6 100644 --- a/core/src/UI/UI_Settings.cpp +++ b/core/src/UI/UI_Settings.cpp @@ -4,6 +4,7 @@ #include -void UI::SettingsTab() { +void UI::SettingsTab() +{ // TODO } diff --git a/core/src/UI/UI_Utils.cpp b/core/src/UI/UI_Utils.cpp index 06fd55e..15f88cf 100644 --- a/core/src/UI/UI_Utils.cpp +++ b/core/src/UI/UI_Utils.cpp @@ -4,31 +4,37 @@ #include #include -void ImGui::SetNextWindowSizeRelScreen(float xPercent, float yPercent, ImGuiCond cond) { +void ImGui::SetNextWindowSizeRelScreen(float xPercent, float yPercent, ImGuiCond cond) +{ auto vs = ImGui::GetMainViewport()->Size; ImGui::SetNextWindowSize({ vs.x * xPercent, vs.y * yPercent }, cond); } -void ImGui::SetNextWindowCentered(ImGuiCond cond) { +void ImGui::SetNextWindowCentered(ImGuiCond cond) +{ auto vs = ImGui::GetMainViewport()->Size; ImGui::SetNextWindowPos({ vs.x / 2, vs.y / 2 }, cond, { 0.5f, 0.5f }); } -void ImGui::PushDisabled() { +void ImGui::PushDisabled() +{ ImGui::PushItemFlag(ImGuiItemFlags_Disabled, true); ImGui::PushStyleVar(ImGuiStyleVar_Alpha, 0.5f * ImGui::GetStyle().Alpha); } -void ImGui::PopDisabled() { +void ImGui::PopDisabled() +{ ImGui::PopItemFlag(); ImGui::PopStyleVar(); } -bool ImGui::Button(const char* label, bool disabled) { +bool ImGui::Button(const char* label, bool disabled) +{ return Button(label, ImVec2{}, disabled); } -bool ImGui::Button(const char* label, const ImVec2& sizeArg, bool disabled) { +bool ImGui::Button(const char* label, const ImVec2& sizeArg, bool disabled) +{ if (disabled) PushDisabled(); bool res = ImGui::Button(label, sizeArg); if (disabled) PopDisabled(); @@ -36,13 +42,15 @@ bool ImGui::Button(const char* label, const ImVec2& sizeArg, bool disabled) { return res; } -void ImGui::ErrorIcon() { +void ImGui::ErrorIcon() +{ ImGui::PushStyleColor(ImGuiCol_Text, ImVec4{ 237 / 255.0f, 67 / 255.0f, 55 / 255.0f, 1.0f }); // #ED4337 ImGui::Text(ICON_FA_EXCLAMATION_CIRCLE); ImGui::PopStyleColor(); } -void ImGui::ErrorMessage(const char* fmt, ...) { +void ImGui::ErrorMessage(const char* fmt, ...) +{ ErrorIcon(); SameLine(); @@ -52,13 +60,15 @@ void ImGui::ErrorMessage(const char* fmt, ...) { va_end(args); } -void ImGui::WarningIcon() { +void ImGui::WarningIcon() +{ ImGui::PushStyleColor(ImGuiCol_Text, ImVec4{ 255 / 255.0f, 184 / 255.0f, 24 / 255.0f, 1.0f }); // #FFB818 ImGui::Text(ICON_FA_EXCLAMATION_TRIANGLE); ImGui::PopStyleColor(); } -void ImGui::WarningMessage(const char* fmt, ...) { +void ImGui::WarningMessage(const char* fmt, ...) +{ WarningIcon(); SameLine(); diff --git a/core/src/UI/UI_Workflows.cpp b/core/src/UI/UI_Workflows.cpp index fe504e2..108410c 100644 --- a/core/src/UI/UI_Workflows.cpp +++ b/core/src/UI/UI_Workflows.cpp @@ -17,11 +17,13 @@ namespace ImNodes = ax::NodeEditor; namespace { -class WorkflowCreationMenu { +class WorkflowCreationMenu +{ private: using WorkflowNodeConstructor = std::unique_ptr (*)(); - enum Category { + enum Category + { NumericCategory, TextCategory, DocumentsCategory, @@ -30,7 +32,8 @@ private: OutputCategory, }; - struct Candidate { + struct Candidate + { WorkflowNodeConstructor Constructor; std::string Name; Category Category; @@ -39,7 +42,10 @@ private: std::vector mCandidates; #define SUB_RANGE_ACCESS(Type, AccessorName, storage, begin, nextBegin) \ - std::span AccessorName() { return { &storage[begin], (size_t)(nextBegin - begin) }; } + std::span AccessorName() \ + { \ + return { &storage[begin], (size_t)(nextBegin - begin) }; \ + } int mTextOffset; int mDocumentOffset; @@ -57,12 +63,14 @@ private: #undef SUB_RANGE_ACCESS public: - WorkflowCreationMenu() { + WorkflowCreationMenu() + { SetupCandidates(); } private: - void SetupCandidates() { + void SetupCandidates() + { // Numeric nodes offset start at 0 mCandidates.push_back(Candidate{ .Constructor = []() -> std::unique_ptr { return std::make_unique(NumericOperationNode::Addition); }, @@ -127,21 +135,25 @@ private: } }; -class WorkflowUI { +class WorkflowUI +{ private: Workflow* mWorkflow; ImNodes::EditorContext* mContext; public: - WorkflowUI() { + WorkflowUI() + { mContext = ImNodes::CreateEditor(); } - ~WorkflowUI() { + ~WorkflowUI() + { ImNodes::DestroyEditor(mContext); } - void Draw() { + void Draw() + { ImNodes::SetCurrentEditor(mContext); ImNodes::Begin(""); @@ -164,7 +176,8 @@ public: }; } // namespace -void UI::WorkflowsTab() { +void UI::WorkflowsTab() +{ static std::unique_ptr openWorkflow; // TODO } -- cgit v1.2.3-70-g09d2