diff options
Diffstat (limited to 'app/source/Cplt/UI')
-rw-r--r-- | app/source/Cplt/UI/UI.hpp | 3 | ||||
-rw-r--r-- | app/source/Cplt/UI/UI_DatabaseView.cpp | 130 | ||||
-rw-r--r-- | app/source/Cplt/UI/UI_Items.cpp | 33 | ||||
-rw-r--r-- | app/source/Cplt/UI/UI_MainWindow.cpp | 9 | ||||
-rw-r--r-- | app/source/Cplt/UI/UI_Settings.cpp | 3 | ||||
-rw-r--r-- | app/source/Cplt/UI/UI_Templates.cpp | 135 | ||||
-rw-r--r-- | app/source/Cplt/UI/UI_Utils.cpp | 43 | ||||
-rw-r--r-- | app/source/Cplt/UI/UI_Workflows.cpp | 18 |
8 files changed, 123 insertions, 251 deletions
diff --git a/app/source/Cplt/UI/UI.hpp b/app/source/Cplt/UI/UI.hpp index 0a80b4c..64f1f9e 100644 --- a/app/source/Cplt/UI/UI.hpp +++ b/app/source/Cplt/UI/UI.hpp @@ -18,8 +18,7 @@ void ErrorMessage(const char* fmt, ...); void WarningIcon(); void WarningMessage(const char* fmt, ...); -enum class IconType -{ +enum class IconType { Flow, Circle, Square, diff --git a/app/source/Cplt/UI/UI_DatabaseView.cpp b/app/source/Cplt/UI/UI_DatabaseView.cpp index 1e58eb0..091e80d 100644 --- a/app/source/Cplt/UI/UI_DatabaseView.cpp +++ b/app/source/Cplt/UI/UI_DatabaseView.cpp @@ -23,35 +23,30 @@ constexpr int kMaxEntriesPerPage = 32; constexpr int kSummaryItemCount = 3; constexpr int kSummaryMaxLength = 25; -std::pair<int, int> SplitEntryIndex(int entryIdx) -{ +std::pair<int, int> SplitEntryIndex(int entryIdx) { int page = entryIdx / kMaxEntriesPerPage; int row = entryIdx % kMaxEntriesPerPage; return { page, row }; } -enum class DeliveryDirection -{ +enum class DeliveryDirection { FactoryToWarehouse, WarehouseToCustomer, }; -struct Item -{ +struct Item { int ItemId; int Count; }; -struct DeliveryEntry -{ +struct DeliveryEntry { std::vector<Item> Items; std::string ItemsSummary; std::string ShipmentTime; std::string ArriveTime; DeliveryDirection Direction; - const char* StringifyDirection() const - { + const char* StringifyDirection() const { switch (Direction) { case DeliveryDirection::FactoryToWarehouse: return "Factory to warehouse"; case DeliveryDirection::WarehouseToCustomer: return "Warehouse to customer"; @@ -59,8 +54,7 @@ struct DeliveryEntry } }; -struct SaleEntry -{ +struct SaleEntry { static constexpr auto kType = DeliveryDirection::WarehouseToCustomer; std::vector<DeliveryEntry> AssociatedDeliveries; @@ -73,8 +67,7 @@ struct SaleEntry bool DeliveriesCached = false; }; -struct PurchaseEntry -{ +struct PurchaseEntry { static constexpr auto kType = DeliveryDirection::FactoryToWarehouse; std::vector<DeliveryEntry> AssociatedDeliveries; @@ -88,27 +81,22 @@ struct PurchaseEntry }; template <class T> -class GenericTableView -{ +class GenericTableView { public: - // clang-format off - static constexpr bool kHasItems = requires(T t) - { - t.Items; - t.ItemsSummary; - }; + static constexpr bool kHasItems = requires(T t) { + t.Items; + t.ItemsSummary; + }; static constexpr bool kHasCustomer = requires(T t) { t.Customer; }; static constexpr bool kHasDeadline = requires(T t) { t.Deadline; }; static constexpr bool kHasFactory = requires(T t) { t.Factory; }; static constexpr bool kHasOrderTime = requires(T t) { t.OrderTime; }; static constexpr bool kHasCompletionTime = requires(T t) { t.DeliveryTime; }; static constexpr int kColumnCount = kHasItems + kHasCustomer + kHasDeadline + kHasFactory + kHasOrderTime + kHasCompletionTime; - // clang-format on using Page = std::vector<T>; - struct QueryStatements - { + struct QueryStatements { SQLite::Statement* GetRowCount; SQLite::Statement* GetRows; SQLite::Statement* GetItems; @@ -143,18 +131,15 @@ protected: public: /// Calculate the first visible row's entry index. - int GetFirstVisibleRowIdx() const - { + int GetFirstVisibleRowIdx() const { return mCurrentPageNumber * kMaxEntriesPerPage; } - Project* GetProject() const - { + Project* GetProject() const { return mProject; } - void OnProjectChanged(Project* newProject) - { + void OnProjectChanged(Project* newProject) { mProject = newProject; auto& stmt = *Statements.GetRowCount; @@ -176,17 +161,13 @@ public: mSelectRow = -1; } - TableRowsFilter* GetFilter() const - { + TableRowsFilter* GetFilter() const { return mActiveFilter.get(); } - void OnFilterChanged() - { + void OnFilterChanged() { auto& stmt = *Statements.FilterRows; - // clang-format off DEFER { stmt.reset(); }; - // clang-format on // TODO lazy loading when too many results mActiveEntries.clear(); @@ -201,14 +182,12 @@ public: mSelectRow = -1; } - void OnFilterChanged(std::unique_ptr<TableRowsFilter> filter) - { + void OnFilterChanged(std::unique_ptr<TableRowsFilter> filter) { mActiveFilter = std::move(filter); OnFilterChanged(); } - void Display() - { + void Display() { bool dummy = true; if (ImGui::Button(ICON_FA_ARROW_LEFT, mCurrentPageNumber == 0)) { @@ -260,29 +239,25 @@ public: ImGui::Columns(1); } - void SetPage(int page) - { + void SetPage(int page) { mCurrentPageNumber = page; mCurrentPage = &LoadAndGetPage(page); mSelectRow = -1; } private: - static int CalcPageForRowId(int64_t entryIdx) - { + static int CalcPageForRowId(int64_t entryIdx) { return entryIdx / 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<int64_t, int64_t> CalcRangeForPage(int page) - { + static std::pair<int64_t, int64_t> CalcRangeForPage(int page) { int begin = page * kMaxEntriesPerPage; return { begin, begin + kMaxEntriesPerPage }; } - void DisplayMainTable() - { + void DisplayMainTable() { if (ImGui::BeginTable("DataTable", kColumnCount, ImGuiTableFlags_Borders | ImGuiTableFlags_ScrollX)) { if constexpr (kHasCustomer) ImGui::TableSetupColumn(I18N_TEXT("Customer", L10N_DATABASE_COLUMN_CUSTOMER)); @@ -315,16 +290,14 @@ private: } } - void DisplayEntry(int rowIdx) - { + void DisplayEntry(int rowIdx) { // TODO // auto [pageNumber, pageEntry] = SplitRowIndex(rowIdx); // auto& entry = LoadAndGetPage(pageNumber)[pageEntry]; // DisplayEntry(entry, rowIdx); } - void DisplayEntry(T& entry, int rowIdx, int entryIdx) - { + void DisplayEntry(T& entry, int rowIdx, int entryIdx) { ImGui::PushID(rowIdx); ImGui::TableNextRow(); @@ -372,13 +345,11 @@ private: ImGui::PopID(); } - void EditEntry(T& entry, int rowIdx, int entryIdx) - { + void EditEntry(T& entry, int rowIdx, int entryIdx) { // TODO } - void DisplayDeliveriesTable() - { + void DisplayDeliveriesTable() { if (ImGui::BeginTable("DeliveriesTable", 3, ImGuiTableFlags_Borders | ImGuiTableFlags_ScrollX)) { ImGui::TableSetupColumn(I18N_TEXT("Shipment time", L10N_DATABASE_COLUMN_SHIPMENT_TIME)); @@ -408,11 +379,8 @@ private: } } - std::vector<Item> LoadItems(SQLite::Statement& stmt, int64_t id) - { - // clang-format off + std::vector<Item> LoadItems(SQLite::Statement& stmt, int64_t id) { DEFER { stmt.reset(); }; - // clang-format on stmt.bind(1, id); @@ -429,8 +397,7 @@ private: return entries; } - std::string CreateItemsSummary(const std::vector<Item>& items) - { + std::string CreateItemsSummary(const std::vector<Item>& items) { if (items.empty()) { return "<empty>"; } @@ -455,8 +422,7 @@ private: return result; } - std::vector<DeliveryEntry> LoadDeliveriesEntries(int64_t orderId, DeliveryDirection type) - { + std::vector<DeliveryEntry> LoadDeliveriesEntries(int64_t orderId, DeliveryDirection type) { bool outgoingFlag; switch (type) { case DeliveryDirection::FactoryToWarehouse: outgoingFlag = false; break; @@ -464,9 +430,7 @@ private: } auto& stmt = mProject->Database.GetDeliveries().FilterByTypeAndId; - // clang-format off DEFER { stmt.reset(); }; - // clang-format on stmt.bind(1, orderId); stmt.bind(2, outgoingFlag); @@ -493,17 +457,14 @@ private: return entries; } - Page& LoadAndGetPage(int page) - { + Page& LoadAndGetPage(int page) { auto iter = mPages.find(page); if (iter != mPages.end()) { return iter.value(); } auto& stmt = *Statements.GetRows; - // clang-format off DEFER { stmt.reset(); }; - // clang-format on stmt.bind(1, kMaxEntriesPerPage); stmt.bind(2, page * kMaxEntriesPerPage); @@ -575,34 +536,29 @@ private: return res.value(); } - void DrawItems(const std::vector<Item>& items) - { + void DrawItems(const std::vector<Item>& items) { for (auto& item : items) { auto& name = mProject->Products.Find(item.ItemId)->GetName(); ImGui::Text("%s × %d", name.c_str(), item.Count); } } - void UpdateLastPage() - { + void UpdateLastPage() { mLastPage = mActiveEntries.empty() ? CalcPageForRowId(mRowCount) : CalcPageForRowId(mActiveEntries.back()); } }; -class SalesTableView : public GenericTableView<SaleEntry> -{ +class SalesTableView : public GenericTableView<SaleEntry> { public: - SalesTableView() - { + SalesTableView() { mEditDialogTitle = I18N_TEXT("Edit sales entry", L10N_DATABASE_SALES_VIEW_EDIT_DIALOG_TITLE); } #pragma clang diagnostic push #pragma ide diagnostic ignored "HidingNonVirtualFunction" - void OnProjectChanged(Project* newProject) - { + void OnProjectChanged(Project* newProject) { auto& table = newProject->Database.GetSales(); Statements.GetRowCount = &table.GetRowCount; Statements.GetRows = &table.GetRows; @@ -615,18 +571,15 @@ public: #pragma clang diagnostic pop }; -class PurchasesTableView : public GenericTableView<PurchaseEntry> -{ +class PurchasesTableView : public GenericTableView<PurchaseEntry> { public: - PurchasesTableView() - { + PurchasesTableView() { mEditDialogTitle = I18N_TEXT("Edit purchase entry", L10N_DATABASE_PURCHASES_VIEW_EDIT_DIALOG_TITLE); } #pragma clang diagnostic push #pragma ide diagnostic ignored "HidingNonVirtualFunction" - void OnProjectChanged(Project* newProject) - { + void OnProjectChanged(Project* newProject) { auto& table = newProject->Database.GetPurchases(); Statements.GetRowCount = &table.GetRowCount; Statements.GetRows = &table.GetRows; @@ -640,8 +593,7 @@ public: }; } // namespace CPLT_UNITY_ID -void UI::DatabaseViewTab() -{ +void UI::DatabaseViewTab() { auto& gs = GlobalStates::GetInstance(); static Project* currentProject = nullptr; diff --git a/app/source/Cplt/UI/UI_Items.cpp b/app/source/Cplt/UI/UI_Items.cpp index 0170e1a..07787d5 100644 --- a/app/source/Cplt/UI/UI_Items.cpp +++ b/app/source/Cplt/UI/UI_Items.cpp @@ -10,8 +10,7 @@ namespace CPLT_UNITY_ID { -enum class ActionResult -{ +enum class ActionResult { Confirmed, Canceled, Pending, @@ -20,14 +19,11 @@ 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 <class T> -ActionResult ItemEditor(ItemList<T>& list, T* item) -{ - constexpr bool kHasDescription = requires(T t) - { +ActionResult ItemEditor(ItemList<T>& list, T* item) { + constexpr bool kHasDescription = requires(T t) { t.GetDescription(); }; - constexpr bool kHasEmail = requires(T t) - { + constexpr bool kHasEmail = requires(T t) { t.GetEmail(); }; @@ -93,22 +89,17 @@ ActionResult ItemEditor(ItemList<T>& list, T* item) } template <class T> -void ItemListEntries(ItemList<T>& list, int& selectedIdx) -{ - constexpr bool kHasDescription = requires(T t) - { +void ItemListEntries(ItemList<T>& list, int& selectedIdx) { + constexpr bool kHasDescription = requires(T t) { t.GetDescription(); }; - constexpr bool kHasEmail = requires(T t) - { + constexpr bool kHasEmail = requires(T t) { t.GetEmail(); }; - constexpr bool kHasStock = requires(T t) - { + constexpr bool kHasStock = requires(T t) { t.GetPrice(); }; - constexpr bool kHasPrice = requires(T t) - { + constexpr bool kHasPrice = requires(T t) { t.GetPrice(); }; constexpr int kColumns = 1 /* Name column */ + kHasDescription + kHasEmail + kHasStock + kHasPrice; @@ -163,8 +154,7 @@ void ItemListEntries(ItemList<T>& list, int& selectedIdx) } template <class T> -void ItemListEditor(ItemList<T>& list) -{ +void ItemListEditor(ItemList<T>& list) { bool opened = true; static int selectedIdx = -1; static T* editingItem = nullptr; @@ -230,8 +220,7 @@ void ItemListEditor(ItemList<T>& list) } } // namespace CPLT_UNITY_ID -void UI::ItemsTab() -{ +void UI::ItemsTab() { auto& gs = GlobalStates::GetInstance(); if (ImGui::BeginTabBar("ItemViewTabs")) { diff --git a/app/source/Cplt/UI/UI_MainWindow.cpp b/app/source/Cplt/UI/UI_MainWindow.cpp index 4653f79..c1c9dfc 100644 --- a/app/source/Cplt/UI/UI_MainWindow.cpp +++ b/app/source/Cplt/UI/UI_MainWindow.cpp @@ -14,8 +14,7 @@ namespace fs = std::filesystem; namespace CPLT_UNITY_ID { -void ProjectTab_Normal() -{ +void ProjectTab_Normal() { auto& gs = GlobalStates::GetInstance(); if (ImGui::Button(ICON_FA_TIMES " " I18N_TEXT("Close", L10N_CLOSE))) { @@ -31,8 +30,7 @@ void ProjectTab_Normal() ImGui::Text("%s %s", I18N_TEXT("Project path", L10N_PROJECT_PATH), gs.GetCurrentProject()->GetPathString().c_str()); } -void ProjectTab_NoProject() -{ +void ProjectTab_NoProject() { auto& gs = GlobalStates::GetInstance(); bool openedDummy = true; @@ -183,8 +181,7 @@ void ProjectTab_NoProject() } } // namespace CPLT_UNITY_ID -void UI::MainWindow() -{ +void UI::MainWindow() { auto& gs = GlobalStates::GetInstance(); auto windowSize = ImGui::GetMainViewport()->Size; diff --git a/app/source/Cplt/UI/UI_Settings.cpp b/app/source/Cplt/UI/UI_Settings.cpp index 71a752a..40da81d 100644 --- a/app/source/Cplt/UI/UI_Settings.cpp +++ b/app/source/Cplt/UI/UI_Settings.cpp @@ -2,7 +2,6 @@ #include <imgui.h> -void UI::SettingsTab() -{ +void UI::SettingsTab() { // TODO } diff --git a/app/source/Cplt/UI/UI_Templates.cpp b/app/source/Cplt/UI/UI_Templates.cpp index e01a97d..ae6c13e 100644 --- a/app/source/Cplt/UI/UI_Templates.cpp +++ b/app/source/Cplt/UI/UI_Templates.cpp @@ -19,8 +19,7 @@ #include <variant> namespace CPLT_UNITY_ID { -class TemplateUI -{ +class TemplateUI { public: static std::unique_ptr<TemplateUI> CreateByKind(std::unique_ptr<Template> tmpl); static std::unique_ptr<TemplateUI> CreateByKind(Template::Kind kind); @@ -34,28 +33,24 @@ public: constexpr ImU32 kSingleParamOutline = IM_COL32(255, 255, 0, 255); constexpr ImU32 kArrayGroupOutline = IM_COL32(255, 0, 0, 255); -class TableTemplateUI : public TemplateUI -{ +class TableTemplateUI : public TemplateUI { private: std::unique_ptr<TableTemplate> mTable; - struct UICell - { + struct UICell { bool Hovered = false; bool Held = false; bool Selected = false; }; std::vector<UICell> mUICells; - struct UIArrayGroup - { + struct UIArrayGroup { ImVec2 Pos; ImVec2 Size; }; std::vector<UIArrayGroup> mUIArrayGroups; - struct Sizer - { + struct Sizer { bool Hovered = false; bool Held = false; }; @@ -69,13 +64,11 @@ private: /* Selection states */ /// "CStates" stands for "Constant cell selection States" - struct CStates - { + struct CStates { }; /// "SStates" stands for "Singular parameter selection States". - struct SStates - { + struct SStates { std::string EditBuffer; bool ErrorDuplicateVarName; bool HasLeftAG; @@ -83,19 +76,16 @@ private: }; /// "AStates" stands for "Array group parameter selection States". - struct AStates - { + struct AStates { std::string EditBuffer; bool ErrorDuplicateVarName; }; // "RStates" stands for "Range selection States". - struct RStates - { + struct RStates { }; - union - { + union { // Initialize to this element std::monostate mIdleState{}; CStates mCS; @@ -109,8 +99,7 @@ private: int mNewTableHeight; /* Table states */ - enum EditMode - { + enum EditMode { ModeEditing, ModeColumnResizing, ModeRowResizing, @@ -128,14 +117,12 @@ public: TableTemplateUI(std::unique_ptr<TableTemplate> table) : mTable{ std::move(table) } , mSelectionTL{ -1, -1 } - , mSelectionBR{ -1, -1 } - { + , mSelectionBR{ -1, -1 } { // TODO debug code Resize(6, 5); } - ~TableTemplateUI() override - { + ~TableTemplateUI() override { // We can't move this to be a destructor of the union // because that way it would run after the destruction of mTable if (!IsSelected()) { @@ -164,8 +151,7 @@ public: } } - void Display() override - { + void Display() override { ImGui::Columns(2); if (mFirstDraw) { mFirstDraw = false; @@ -183,13 +169,11 @@ public: ImGui::Columns(1); } - void Close() override - { + void Close() override { // TODO } - void Resize(int width, int height) - { + void Resize(int width, int height) { mTable->Resize(width, height); mUICells.resize(width * height); mUIArrayGroups.resize(mTable->GetArrayGroupCount()); @@ -216,8 +200,7 @@ public: } private: - void DisplayInspector() - { + void DisplayInspector() { bool openedDummy = true; // This is an id, no need to localize @@ -269,21 +252,18 @@ private: } } - static char NthUppercaseLetter(int n) - { + static char NthUppercaseLetter(int n) { return (char)((int)'A' + n); } - static void ExcelRow(int row, char* bufferBegin, char* bufferEnd) - { + static void ExcelRow(int row, char* bufferBegin, char* bufferEnd) { auto res = std::to_chars(bufferBegin, bufferEnd, row); if (res.ec != std::errc()) { return; } } - static char* ExcelColumn(int column, char* bufferBegin, char* bufferEnd) - { + static char* ExcelColumn(int column, char* bufferBegin, char* bufferEnd) { // https://stackoverflow.com/a/182924/11323702 int dividend = column; @@ -311,8 +291,7 @@ private: return writeHead + 1; } - void DisplayCellProperties(Vec2i pos) - { + void DisplayCellProperties(Vec2i pos) { auto& cell = mTable->GetCell(pos); auto& uiCell = mUICells[pos.y * mTable->GetTableWidth() + pos.x]; @@ -472,13 +451,11 @@ private: } } - void DisplayRangeProperties(Vec2i tl, Vec2i br) - { + void DisplayRangeProperties(Vec2i tl, Vec2i br) { // TODO } - void DisplayTableContents() - { + void DisplayTableContents() { if (ImGui::TreeNode(ICON_FA_BONG " " I18N_TEXT("Parameters", L10N_TABLE_SINGLE_PARAMS))) { TableSingleParamsIter iter(*mTable); while (iter.HasNext()) { @@ -511,8 +488,7 @@ private: } } - void DisplayTableProperties() - { + void DisplayTableProperties() { ImGui::InputInt(I18N_TEXT("Width", L10N_TABLE_WIDTH), &mNewTableWidth); ImGui::InputInt(I18N_TEXT("Height", L10N_TABLE_HEIGHT), &mNewTableHeight); @@ -528,16 +504,13 @@ private: // TODO } - void DisplayTable() - { - struct CellPalette - { + void DisplayTable() { + struct CellPalette { ImU32 Regular; ImU32 Hovered; ImU32 Active; - ImU32 GetColorFor(const UICell& cell) const - { + ImU32 GetColorFor(const UICell& cell) const { if (cell.Held) { return Active; } else if (cell.Hovered) { @@ -689,8 +662,7 @@ private: std::type_identity_t<float ImVec2::*> vecCompGetter, std::type_identity_t<int (TableTemplate::*)() const> lenGetter, std::type_identity_t<int (TableTemplate::*)(int) const> dimGetter, - std::type_identity_t<void (TableTemplate::*)(int, int)> dimSetter) - { + std::type_identity_t<void (TableTemplate::*)(int, int)> dimSetter) { auto window = ImGui::GetCurrentWindow(); auto spacing = ImGui::GetStyle().ItemSpacing.*vecCompGetter; @@ -736,8 +708,7 @@ private: } } - void DisplayTableResizers(ImVec2 topLeftPixelPos) - { + void DisplayTableResizers(ImVec2 topLeftPixelPos) { constexpr float kExtraSideLength = 5.0f; constexpr float kExtraAxialLength = 2.0f; @@ -776,8 +747,7 @@ private: } } - float CalcTablePixelWidth() const - { + float CalcTablePixelWidth() const { float horizontalSpacing = ImGui::GetStyle().ItemSpacing.x; float width = 0; for (int x = 0; x < mTable->GetTableWidth(); ++x) { @@ -787,8 +757,7 @@ private: return width - horizontalSpacing; } - float CalcTablePixelHeight() const - { + float CalcTablePixelHeight() const { float verticalSpacing = ImGui::GetStyle().ItemSpacing.y; float height = 0; for (int y = 0; y < mTable->GetTableHeight(); ++y) { @@ -799,8 +768,7 @@ private: } template <class TFunction> - void ForeachSelectedCell(const TFunction& func) - { + void ForeachSelectedCell(const TFunction& func) { for (int y = mSelectionTL.y; y <= mSelectionBR.y; ++y) { for (int x = mSelectionTL.x; x <= mSelectionBR.x; ++x) { int i = y * mTable->GetTableWidth() + x; @@ -809,13 +777,11 @@ private: } } - bool IsSelected() const - { + bool IsSelected() const { return mSelectionTL.x != -1; } - void ClearSelection() - { + void ClearSelection() { if (IsSelected()) { ForeachSelectedCell([this](int i, int, int) { auto& uiCell = mUICells[i]; @@ -829,13 +795,11 @@ private: ResetIdleState(); } - void ResetIdleState() - { + void ResetIdleState() { mIdleState = {}; } - void SelectRange(Vec2i p1, Vec2i p2) - { + void SelectRange(Vec2i p1, Vec2i p2) { ClearSelection(); if (p2.x < p1.x) { @@ -856,13 +820,11 @@ private: ResetRS(); } - void ResetRS() - { + void ResetRS() { mRS = {}; } - void SelectCell(Vec2i pos) - { + void SelectCell(Vec2i pos) { ClearSelection(); mSelectionTL = pos; @@ -878,13 +840,11 @@ private: } } - void ResetCS() - { + void ResetCS() { mCS = {}; } - void ResetSS(Vec2i pos) - { + void ResetSS(Vec2i pos) { new (&mSS) SStates{ .EditBuffer = mTable->GetCell(pos).Content, .ErrorDuplicateVarName = false, @@ -893,8 +853,7 @@ private: }; } - void ResetAS(Vec2i pos) - { + void ResetAS(Vec2i pos) { new (&mAS) AStates{ .EditBuffer = mTable->GetCell(pos).Content, .ErrorDuplicateVarName = false, @@ -903,13 +862,11 @@ private: }; template <class TTarget> -static auto CastTemplateAs(std::unique_ptr<Template>& input) requires std::is_base_of_v<Template, TTarget> -{ +static auto CastTemplateAs(std::unique_ptr<Template>& input) requires std::is_base_of_v<Template, TTarget> { return std::unique_ptr<TTarget>(static_cast<TTarget*>(input.release())); } -std::unique_ptr<TemplateUI> TemplateUI::CreateByKind(std::unique_ptr<Template> tmpl) -{ +std::unique_ptr<TemplateUI> TemplateUI::CreateByKind(std::unique_ptr<Template> tmpl) { switch (tmpl->GetKind()) { case Template::KD_Table: return std::make_unique<TableTemplateUI>(CastTemplateAs<TableTemplate>(tmpl)); case Template::InvalidKind: break; @@ -917,8 +874,7 @@ std::unique_ptr<TemplateUI> TemplateUI::CreateByKind(std::unique_ptr<Template> t return nullptr; } -std::unique_ptr<TemplateUI> TemplateUI::CreateByKind(Template::Kind kind) -{ +std::unique_ptr<TemplateUI> TemplateUI::CreateByKind(Template::Kind kind) { switch (kind) { case Template::KD_Table: return std::make_unique<TableTemplateUI>(std::make_unique<TableTemplate>()); case Template::InvalidKind: break; @@ -927,8 +883,7 @@ std::unique_ptr<TemplateUI> TemplateUI::CreateByKind(Template::Kind kind) } } // namespace CPLT_UNITY_ID -void UI::TemplatesTab() -{ +void UI::TemplatesTab() { auto& project = *GlobalStates::GetInstance().GetCurrentProject(); static std::unique_ptr<CPLT_UNITY_ID::TemplateUI> openTemplate; diff --git a/app/source/Cplt/UI/UI_Utils.cpp b/app/source/Cplt/UI/UI_Utils.cpp index a2bf692..9fd645d 100644 --- a/app/source/Cplt/UI/UI_Utils.cpp +++ b/app/source/Cplt/UI/UI_Utils.cpp @@ -6,37 +6,31 @@ #define IMGUI_DEFINE_MATH_OPERATORS #include <imgui_internal.h> -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(); @@ -47,15 +41,13 @@ 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(); @@ -65,15 +57,13 @@ 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(); @@ -83,8 +73,7 @@ void ImGui::WarningMessage(const char* fmt, ...) va_end(args); } -void ImGui::DrawIcon(ImDrawList* drawList, const ImVec2& a, const ImVec2& b, IconType type, bool filled, ImU32 color, ImU32 innerColor) -{ +void ImGui::DrawIcon(ImDrawList* drawList, const ImVec2& a, const ImVec2& b, IconType type, bool filled, ImU32 color, ImU32 innerColor) { // Taken from https://github.com/thedmd/imgui-node-editor/blob/master/examples/blueprints-example/utilities/drawing.cpp // ax::NodeEditor::DrawIcon @@ -109,7 +98,7 @@ void ImGui::DrawIcon(ImDrawList* drawList, const ImVec2& a, const ImVec2& b, Ico const auto margin = 2.0f * origin_scale; const auto rounding = 0.1f * origin_scale; const auto tip_round = 0.7f; // percentage of triangle edge (for tip) - //const auto edge_round = 0.7f; // percentage of triangle edge (for corner) + // const auto edge_round = 0.7f; // percentage of triangle edge (for corner) const auto canvas = ImRect( rect.Min.x + margin + offset_x, rect.Min.y + margin + offset_y, @@ -125,7 +114,7 @@ void ImGui::DrawIcon(ImDrawList* drawList, const ImVec2& a, const ImVec2& b, Ico const auto top = canvas_y + canvas_h * 0.5f * 0.2f; const auto bottom = canvas_y + canvas_h - canvas_h * 0.5f * 0.2f; const auto center_y = (top + bottom) * 0.5f; - //const auto angle = AX_PI * 0.5f * 0.5f * 0.5f; + // const auto angle = AX_PI * 0.5f * 0.5f * 0.5f; const auto tip_top = ImVec2(canvas_x + canvas_w * 0.5f, top); const auto tip_right = ImVec2(right, center_y); @@ -285,8 +274,7 @@ void ImGui::DrawIcon(ImDrawList* drawList, const ImVec2& a, const ImVec2& b, Ico } } -void ImGui::Icon(const ImVec2& size, IconType type, bool filled, const ImVec4& color, const ImVec4& innerColor) -{ +void ImGui::Icon(const ImVec2& size, IconType type, bool filled, const ImVec4& color, const ImVec4& innerColor) { // Taken from https://github.com/thedmd/imgui-node-editor/blob/master/examples/blueprints-example/utilities/widgets.cpp // ax::NodeEditor::Icon @@ -300,8 +288,7 @@ void ImGui::Icon(const ImVec2& size, IconType type, bool filled, const ImVec4& c ImGui::Dummy(size); } -bool ImGui::Splitter(bool splitVertically, float thickness, float* size1, float* size2, float minSize1, float minSize2, float splitterLongAxisSize) -{ +bool ImGui::Splitter(bool splitVertically, float thickness, float* size1, float* size2, float minSize1, float minSize2, float splitterLongAxisSize) { // Taken from https://github.com/thedmd/imgui-node-editor/blob/master/examples/blueprints-example/blueprints-example.cpp // ::Splitter diff --git a/app/source/Cplt/UI/UI_Workflows.cpp b/app/source/Cplt/UI/UI_Workflows.cpp index 5eea53a..5d28372 100644 --- a/app/source/Cplt/UI/UI_Workflows.cpp +++ b/app/source/Cplt/UI/UI_Workflows.cpp @@ -21,8 +21,7 @@ namespace ImNodes = ax::NodeEditor; namespace CPLT_UNITY_ID { -class WorkflowUI -{ +class WorkflowUI { private: std::unique_ptr<Workflow> mWorkflow; @@ -34,18 +33,15 @@ private: public: WorkflowUI(std::unique_ptr<Workflow> workflow) - : mWorkflow{ std::move(workflow) } - { + : mWorkflow{ std::move(workflow) } { mContext = ImNodes::CreateEditor(); } - ~WorkflowUI() - { + ~WorkflowUI() { ImNodes::DestroyEditor(mContext); } - void Display() - { + void Display() { ImNodes::SetCurrentEditor(mContext); ImNodes::Begin(""); @@ -236,15 +232,13 @@ public: ImNodes::End(); } - void Close() - { + void Close() { // TODO } }; } // namespace CPLT_UNITY_ID -void UI::WorkflowsTab() -{ +void UI::WorkflowsTab() { auto& project = *GlobalStates::GetInstance().GetCurrentProject(); static std::unique_ptr<CPLT_UNITY_ID::WorkflowUI> openWorkflow; |