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_Templates.cpp | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) (limited to 'core/src/UI/UI_Templates.cpp') 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) -- cgit v1.2.3-70-g09d2