diff options
author | rtk0c <[email protected]> | 2022-11-27 12:04:31 -0800 |
---|---|---|
committer | rtk0c <[email protected]> | 2022-11-27 12:04:31 -0800 |
commit | 182c8f8357739f905bbd721006480502435b6b43 (patch) | |
tree | 082613a474d863182e2ad8f2167f1643f26e67a3 /app/source/Cplt/UI/UI_Templates.cpp | |
parent | b01ed99a1cd0c863c8709930658513c04dd70f61 (diff) |
Update brace style to match rest of my projectscplt-imgui
Diffstat (limited to 'app/source/Cplt/UI/UI_Templates.cpp')
-rw-r--r-- | app/source/Cplt/UI/UI_Templates.cpp | 135 |
1 files changed, 45 insertions, 90 deletions
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; |