summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--core/src/Model/Template/TableTemplate.cpp21
-rw-r--r--core/src/UI/UI_Templates.cpp176
2 files changed, 128 insertions, 69 deletions
diff --git a/core/src/Model/Template/TableTemplate.cpp b/core/src/Model/Template/TableTemplate.cpp
index ce1d6a5..adf79fe 100644
--- a/core/src/Model/Template/TableTemplate.cpp
+++ b/core/src/Model/Template/TableTemplate.cpp
@@ -276,7 +276,26 @@ TableArrayGroup* TableTemplate::AddArrayGroup(std::string_view name, int row, in
.LeftCell = left,
.RightCell = right,
});
- return &mArrayGroups.back();
+ auto& ag = mArrayGroups.back();
+
+ for (int x = left; x <= right; x++) {
+ auto& cell = GetCell({ x, row });
+
+ // Update type
+ cell.Type = TableCell::ArrayParametricCell;
+
+ // Insert parameter name lookup
+ while (true) {
+ auto [DISCARD, inserted] = ag.mName2Cell.insert(cell.Content, x);
+ if (inserted) {
+ break;
+ }
+
+ cell.Content += "-";
+ }
+ }
+
+ return &ag;
}
bool TableTemplate::UpdateArrayGroupName(std::string_view oldName, std::string_view newName)
diff --git a/core/src/UI/UI_Templates.cpp b/core/src/UI/UI_Templates.cpp
index 0320ea0..e140add 100644
--- a/core/src/UI/UI_Templates.cpp
+++ b/core/src/UI/UI_Templates.cpp
@@ -58,36 +58,41 @@ private:
Vec2i mSelectionBR;
/* Selection states */
- union
+
+ /// "CStates" stands for "Constant cell selection States"
+ struct CStates
{
- // Initialize to this element
- std::monostate mIdleState{};
+ };
- /// "CS" stands for "Constant cell selection States"
- struct
- {
- } mCS;
+ /// "SStates" stands for "Singular parameter selection States".
+ struct SStates
+ {
+ std::string EditBuffer;
+ bool ErrorDuplicateVarName;
+ bool HasLeftAG;
+ bool HasRightAG;
+ };
- /// "SS" stands for "Singular parameter selection States".
- struct
- {
- std::string EditBuffer;
- bool ErrorDuplicateVarName;
- bool HasLeftAG;
- bool HasRightAG;
- } mSS;
+ /// "AStates" stands for "Array group parameter selection States".
+ struct AStates
+ {
+ std::string EditBuffer;
+ bool ErrorDuplicateVarName;
+ };
- /// "AS" stands for "Array group parameter selection States".
- struct
- {
- std::string EditBuffer;
- bool ErrorDuplicateVarName;
- } mAS;
+ // "RStates" stands for "Range selection States".
+ struct RStates
+ {
+ };
- // "RS" stands for "Range selection States".
- struct
- {
- } mRS;
+ union
+ {
+ // Initialize to this element
+ std::monostate mIdleState{};
+ CStates mCS;
+ SStates mSS;
+ AStates mAS;
+ RStates mRS;
};
/* Table resizer dialog states */
@@ -181,6 +186,9 @@ public:
uag.Size.y += mTable->GetColumnWidth(x);
}
}
+
+ mSelectionTL = { 0, 0 };
+ mSelectionBR = { 0, 0 };
}
private:
@@ -322,7 +330,7 @@ private:
bool arrayEnabled = cell.Type != TableCell::ArrayParametricCell;
if (ImGui::MenuItem(I18N_TEXT("Add to a new array group", L10N_TABLE_CELL_CONV_CREATE_AG), nullptr, false, arrayEnabled)) {
- mTable->AddArrayGroup(pos.x, pos.x, pos.y); // Use automatically generated name
+ mTable->AddArrayGroup(pos.y, pos.x, pos.x); // Use automatically generated name
ResetAS(pos);
}
@@ -502,13 +510,37 @@ private:
void DisplayTable()
{
- ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, ImVec2(8, 8));
- ImGui::PushStyleVar(ImGuiStyleVar_ItemSpacing, ImVec2(8, 8));
- ImGui::BeginChild("TableTemplate");
+ struct CellPalette
+ {
+ ImU32 Regular;
+ ImU32 Hovered;
+ ImU32 Active;
+
+ ImU32 GetColorFor(const UICell& cell) const
+ {
+ if (cell.Held) {
+ return Active;
+ } else if (cell.Hovered) {
+ return Hovered;
+ } else {
+ return Regular;
+ }
+ }
+ };
+
+ CellPalette constantPalette{
+ .Regular = ImGui::GetColorU32(ImGuiCol_Button),
+ .Hovered = ImGui::GetColorU32(ImGuiCol_ButtonHovered),
+ .Active = ImGui::GetColorU32(ImGuiCol_ButtonActive),
+ };
+ CellPalette paramPalette{
+ .Regular = IM_COL32(0, 214, 4, 102),
+ .Hovered = IM_COL32(0, 214, 4, 255),
+ .Active = IM_COL32(0, 191, 2, 255),
+ };
+
+ // TODO array group color
- auto regularColor = ImGui::GetColorU32(ImGuiCol_Button);
- auto hoveredColor = ImGui::GetColorU32(ImGuiCol_ButtonHovered);
- auto activeColor = ImGui::GetColorU32(ImGuiCol_ButtonActive);
auto navHighlight = ImGui::GetColorU32(ImGuiCol_NavHighlight);
int colCount = mTable->GetTableWidth();
@@ -533,41 +565,50 @@ private:
window->DC.CursorPos + ImGui::CalcItemSize(size, 0.0f, 0.0f),
};
- /* Draw cell body */
+ /* Draw cell selection */
if (uiCell.Selected) {
- window->DrawList->AddRectFilled(
- rect.Min - ImVec2(2, 1),
- rect.Max + ImVec2(2, 1),
- navHighlight);
- } else {
- ImU32 color;
- if (uiCell.Held) {
- color = activeColor;
- } else if (uiCell.Hovered) {
- color = hoveredColor;
- } else {
- color = regularColor;
- }
- window->DrawList->AddRectFilled(rect.Min, rect.Max, color);
+ constexpr int mt = 2; // Marker Thickness
+ constexpr int ms = 8; // Marker Size
+
+ ImVec2 outerTL(rect.Min - ImVec2(mt, mt));
+ ImVec2 outerBR(rect.Max + ImVec2(mt, mt));
+
+ // Top left
+ window->DrawList->AddRectFilled(outerTL + ImVec2(0, 0), outerTL + ImVec2(ms, mt), navHighlight);
+ window->DrawList->AddRectFilled(outerTL + ImVec2(0, mt), outerTL + ImVec2(mt, ms), navHighlight);
+
+ // Top right
+ ImVec2 outerTR(outerBR.x, outerTL.y);
+ window->DrawList->AddRectFilled(outerTR + ImVec2(-ms, 0), outerTR + ImVec2(0, mt), navHighlight);
+ window->DrawList->AddRectFilled(outerTR + ImVec2(-mt, mt), outerTR + ImVec2(0, ms), navHighlight);
+
+ // Bottom right
+ window->DrawList->AddRectFilled(outerBR + ImVec2(-ms, -mt), outerBR + ImVec2(0, 0), navHighlight);
+ window->DrawList->AddRectFilled(outerBR + ImVec2(-mt, -ms), outerBR + ImVec2(0, -mt), navHighlight);
+
+ // Bottom left
+ ImVec2 outerBL(outerTL.x, outerBR.y);
+ window->DrawList->AddRectFilled(outerBL + ImVec2(0, -mt), outerBL + ImVec2(ms, 0), navHighlight);
+ window->DrawList->AddRectFilled(outerBL + ImVec2(0, -ms), outerBL + ImVec2(mt, -mt), navHighlight);
}
- /* Draw cell type indicator */
+ /* Draw cell body */
+
+ CellPalette* palette;
switch (cell.Type) {
- // No indicator
- case TableCell::ConstantCell: break;
+ case TableCell::ConstantCell:
+ palette = &constantPalette;
+ break;
case TableCell::SingularParametricCell:
- window->DrawList->AddRect(
- rect.Min - ImVec2(1, 1),
- rect.Max + ImVec2(1, 1),
- kSingleParamOutline);
+ case TableCell::ArrayParametricCell:
+ palette = &paramPalette;
break;
-
- // Drawn separately in loop below
- case TableCell::ArrayParametricCell: break;
}
+ window->DrawList->AddRectFilled(rect.Min, rect.Max, palette->GetColorFor(uiCell));
+
/* Draw cell content */
auto content = cell.Content.c_str();
@@ -615,9 +656,6 @@ private:
uag.Pos + uag.Size + ImVec2(1, 1),
kArrayGroupOutline);
}
-
- ImGui::EndChild();
- ImGui::PopStyleVar(2);
}
template <class TFunction>
@@ -707,18 +745,20 @@ private:
void ResetSS(Vec2i pos)
{
- mSS = {};
- mSS.EditBuffer = mTable->GetCell(pos).Content;
- mSS.ErrorDuplicateVarName = false;
- 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;
+ new (&mSS) SStates{
+ .EditBuffer = mTable->GetCell(pos).Content,
+ .ErrorDuplicateVarName = false,
+ .HasLeftAG = pos.x > 1 && mTable->GetCell({ pos.x - 1, pos.y }).Type == TableCell::ArrayParametricCell,
+ .HasRightAG = pos.x < mTable->GetTableWidth() - 1 && mTable->GetCell({ pos.x + 1, pos.y }).Type == TableCell::ArrayParametricCell,
+ };
}
void ResetAS(Vec2i pos)
{
- mAS = {};
- mAS.EditBuffer = mTable->GetCell(pos).Content;
- mAS.ErrorDuplicateVarName = false;
+ new (&mAS) AStates{
+ .EditBuffer = mTable->GetCell(pos).Content,
+ .ErrorDuplicateVarName = false,
+ };
}
};