From 43cd2bd879d529fcbd0a0f64eccd4ce1eb872ab4 Mon Sep 17 00:00:00 2001 From: rtk0c Date: Mon, 21 Jun 2021 18:30:38 -0700 Subject: Implement array group conversion logic --- core/src/UI/UI.hpp | 2 -- core/src/UI/UI_Templates.cpp | 24 +++++++++++++++--------- core/src/UI/UI_Utils.cpp | 9 --------- 3 files changed, 15 insertions(+), 20 deletions(-) (limited to 'core/src/UI') diff --git a/core/src/UI/UI.hpp b/core/src/UI/UI.hpp index b0f0a6f..0a80b4c 100644 --- a/core/src/UI/UI.hpp +++ b/core/src/UI/UI.hpp @@ -13,8 +13,6 @@ void PopDisabled(); bool Button(const char* label, bool disabled); bool Button(const char* label, const ImVec2& sizeArg, bool disabled); -bool MenuItemConditional(const char* name, bool disabled); - void ErrorIcon(); void ErrorMessage(const char* fmt, ...); void WarningIcon(); diff --git a/core/src/UI/UI_Templates.cpp b/core/src/UI/UI_Templates.cpp index e77bef3..5255b6a 100644 --- a/core/src/UI/UI_Templates.cpp +++ b/core/src/UI/UI_Templates.cpp @@ -170,23 +170,29 @@ private: ImGui::OpenPopup("ConvertCtxMenu"); } if (ImGui::BeginPopup("ConvertCtxMenu")) { - if (ImGui::MenuItem(I18N_TEXT("Single parameter", L10N_TABLE_CELL_CONV_PARAM))) { + bool constantDisabled = cell.Type == TableCell::ConstantCell; + if (ImGui::MenuItem(I18N_TEXT("Convert to regular cell", L10N_TABLE_CELL_CONV_CONST), nullptr, false, constantDisabled)) { + mTable->SetCellType(pos, TableCell::ConstantCell); + } + + bool singleDisabled = cell.Type == TableCell::SingularParametricCell; + if (ImGui::MenuItem(I18N_TEXT("Convert to parameter cell", L10N_TABLE_CELL_CONV_PARAM), nullptr, false, singleDisabled)) { mTable->SetCellType(pos, TableCell::SingularParametricCell); } - bool createDisabled = cell.Type == TableCell::ArrayParametricCell; - if (ImGui::MenuItemConditional(I18N_TEXT("Create array group", L10N_TABLE_CELL_CONV_CREATE_AG), createDisabled)) { + bool arrayDisabled = cell.Type == TableCell::ArrayParametricCell; + if (ImGui::MenuItem(I18N_TEXT("Add to a new array group", L10N_TABLE_CELL_CONV_CREATE_AG), nullptr, false, arrayDisabled)) { mTable->AddArrayGroup(pos.x, pos.x, pos.y); } - bool leftDisabled = !mSS.HasLeftAG || cell.Type == TableCell::ArrayParametricCell; - if (ImGui::MenuItemConditional(I18N_TEXT("Add to array group to the left", L10N_TABLE_CELL_CONV_ADD_AG_LEFT), leftDisabled)) { + bool leftDisabled = !mSS.HasLeftAG || arrayDisabled; + if (ImGui::MenuItem(I18N_TEXT("Add to the array group to the left", L10N_TABLE_CELL_CONV_ADD_AG_LEFT), nullptr, false, leftDisabled)) { auto& leftCell = mTable->GetCell((Vec2i){ pos.x - 1, pos.y }); mTable->ExtendArrayGroupRight(leftCell.DataId, 1); } - bool rightDisabled = !mSS.HasRightAG || cell.Type == TableCell::ArrayParametricCell; - if (ImGui::MenuItemConditional(I18N_TEXT("Add to array group to the right", L10N_TABLE_CELL_CONV_ADD_AG_RIGHT), rightDisabled)) { + bool rightDisabled = !mSS.HasRightAG || arrayDisabled; + if (ImGui::MenuItem(I18N_TEXT("Add to the array group to the right", L10N_TABLE_CELL_CONV_ADD_AG_RIGHT), nullptr, false, rightDisabled)) { auto& rightCell = mTable->GetCell((Vec2i){ pos.x + 1, pos.y }); mTable->ExtendArrayGroupLeft(rightCell.DataId, 1); } @@ -472,8 +478,8 @@ private: { mSS = {}; mSS.ErrorDuplicateVarName = false; - mSS.HasLeftAG = pos.x >= 1; - mSS.HasRightAG = pos.x < mTable->GetTableWidth(); + mSS.HasLeftAG = pos.x > 1 && mTable->GetCell({ pos.x - 1, pos.y }).Type == TableCell::ArrayParametricCell; + mSS.HasRightAG = pos.x < mTable->GetTableWidth() - 1 && mTable->GetCell({ pos.x + 1, pos.y }).Type == TableCell::ArrayParametricCell; } void SelectCell(Vec2i cell) diff --git a/core/src/UI/UI_Utils.cpp b/core/src/UI/UI_Utils.cpp index 0dcde8f..e3ac097 100644 --- a/core/src/UI/UI_Utils.cpp +++ b/core/src/UI/UI_Utils.cpp @@ -44,15 +44,6 @@ bool ImGui::Button(const char* label, const ImVec2& sizeArg, bool disabled) return res; } -bool ImGui::MenuItemConditional(const char* name, bool disabled) -{ - if (disabled) PushDisabled(); - bool res = MenuItem(name, nullptr, false, disabled); - if (disabled) PopDisabled(); - - return res; -} - void ImGui::ErrorIcon() { ImGui::PushStyleColor(ImGuiCol_Text, ImVec4{ 237 / 255.0f, 67 / 255.0f, 55 / 255.0f, 1.0f }); // #ED4337 -- cgit v1.2.3-70-g09d2