summaryrefslogtreecommitdiff
path: root/core/src/UI
diff options
context:
space:
mode:
authorrtk0c <[email protected]>2021-06-28 21:53:17 -0700
committerrtk0c <[email protected]>2021-06-28 21:53:17 -0700
commitdf1a386b067a62c879b48b1eeca50b2982b4f92d (patch)
tree4213511f7f74779ea1e80abc030cb1272e3b9dee /core/src/UI
parent43cd2bd879d529fcbd0a0f64eccd4ce1eb872ab4 (diff)
Add table content list, cell status indicator
Diffstat (limited to 'core/src/UI')
-rw-r--r--core/src/UI/UI_Items.cpp1
-rw-r--r--core/src/UI/UI_Templates.cpp129
2 files changed, 124 insertions, 6 deletions
diff --git a/core/src/UI/UI_Items.cpp b/core/src/UI/UI_Items.cpp
index a557eb4..2685c82 100644
--- a/core/src/UI/UI_Items.cpp
+++ b/core/src/UI/UI_Items.cpp
@@ -1,4 +1,5 @@
#include "UI.hpp"
+#include "UI.hpp"
#include "Model/GlobalStates.hpp"
#include "Model/Project.hpp"
diff --git a/core/src/UI/UI_Templates.cpp b/core/src/UI/UI_Templates.cpp
index 5255b6a..b612662 100644
--- a/core/src/UI/UI_Templates.cpp
+++ b/core/src/UI/UI_Templates.cpp
@@ -3,13 +3,16 @@
#include "Model/GlobalStates.hpp"
#include "Model/Project.hpp"
#include "Model/Template/TableTemplate.hpp"
+#include "Model/Template/TableTemplateIterator.hpp"
#include "Model/Template/Template.hpp"
#include "Utils/I18n.hpp"
#include <IconsFontAwesome.h>
#include <imgui.h>
#include <imgui_extra_math.h>
+#include <imgui_internal.h>
#include <imgui_stdlib.h>
+#include <charconv>
#include <fstream>
#include <iostream>
#include <utility>
@@ -138,6 +141,8 @@ public:
private:
void DisplayInspector()
{
+ bool openedDummy = true;
+
// This is an id, no need to localize
if (ImGui::BeginTabBar("Inspector")) {
if (ImGui::BeginTabItem(I18N_TEXT("Cell", L10N_TABLE_CELL))) {
@@ -153,46 +158,124 @@ private:
}
if (ImGui::BeginTabItem(I18N_TEXT("Table", L10N_TABLE))) {
- DisplayTableProperties();
+ // Table properties
+ if (ImGui::Button(I18N_TEXT("Configure table properties...", L10N_TABLE_CONFIGURE_PROPERTIES))) {
+ // Act as if ImGui::OpenPopup is executed in the previous id stack frame (tab bar level)
+ // Note: we can't simply use ImGui::GetItemID() here, because that would return the id of the ImGui::Button
+ auto tabBar = ImGui::GetCurrentContext()->CurrentTabBar;
+ auto id = tabBar->Tabs[tabBar->LastTabItemIdx].ID;
+ ImGui::PopID();
+ ImGui::OpenPopup(I18N_TEXT("Table properties", L10N_TABLE_PROPERTIES));
+ ImGui::PushOverrideID(id);
+ }
+
+ // Table contents
+ DisplayTableContents();
+
ImGui::EndTabItem();
}
+ if (ImGui::BeginPopupModal(I18N_TEXT("Table properties", L10N_TABLE_PROPERTIES), &openedDummy, ImGuiWindowFlags_AlwaysAutoResize)) {
+ DisplayTableProperties();
+ ImGui::EndPopup();
+ }
ImGui::EndTabBar();
}
}
+ static char NthUppercaseLetter(int n)
+ {
+ return (char)((int)'A' + n);
+ }
+
+ 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)
+ {
+ // https://stackoverflow.com/a/182924/11323702
+
+ int dividend = column;
+ int modulo;
+
+ char* lastChar = bufferEnd - 1;
+ *lastChar = '\0';
+ char* writeHead = lastChar - 1;
+
+ while (dividend > 0) {
+ if (writeHead < bufferBegin) {
+ return nullptr;
+ }
+
+ modulo = (dividend - 1) % 26;
+
+ *writeHead = NthUppercaseLetter(modulo);
+ --writeHead;
+
+ dividend = (dividend - modulo) / 26;
+ }
+
+ // `writeHead` at this point would be a one-past-the-bufferEnd reverse iterator (i.e. one-past-the-(text)beginning in the bufferBegin)
+ // add 1 to get to the actual beginning of the text
+ return writeHead + 1;
+ }
+
void DisplayCellProperties(Vec2i pos)
{
auto& cell = mTable->GetCell(pos);
auto& uiCell = mUICells[pos.y * mTable->GetTableWidth() + pos.x];
+ char colStr[8]; // 2147483647 -> FXSHRXW, len == 7, along with \0
+ char* colBegin = ExcelColumn(pos.x + 1, std::begin(colStr), std::end(colStr));
+ char rowStr[11]; // len(2147483647) == 10, along with \0
+ ExcelRow(pos.y + 1, std::begin(rowStr), std::end(rowStr));
+ ImGui::Text(I18N_TEXT("Location: %s%s", L10N_TABLE_CELL_POS), colBegin, rowStr);
+
+ switch (cell.Type)
+ {
+ case TableCell::ConstantCell:
+ ImGui::Text(I18N_TEXT("Type: Constant", L10N_TABLE_CELL_TYPE_CONST));
+ break;
+ case TableCell::SingularParametricCell:
+ ImGui::Text(I18N_TEXT("Type: Single parameter", L10N_TABLE_CELL_TYPE_PARAM));
+ break;
+ case TableCell::ArrayParametricCell:
+ ImGui::Text(I18N_TEXT("Type: Array group", L10N_TABLE_CELL_TYPE_CREATE_AG));
+ break;
+ }
+
if (ImGui::Button(I18N_TEXT("Convert to...", L10N_TABLE_CELL_CONV))) {
ImGui::OpenPopup("ConvertCtxMenu");
}
if (ImGui::BeginPopup("ConvertCtxMenu")) {
bool constantDisabled = cell.Type == TableCell::ConstantCell;
- if (ImGui::MenuItem(I18N_TEXT("Convert to regular cell", L10N_TABLE_CELL_CONV_CONST), nullptr, false, constantDisabled)) {
+ 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)) {
+ if (ImGui::MenuItem(I18N_TEXT("Convert to parameter cell", L10N_TABLE_CELL_CONV_PARAM), nullptr, false, !singleDisabled)) {
mTable->SetCellType(pos, TableCell::SingularParametricCell);
}
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)) {
+ 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 || arrayDisabled;
- if (ImGui::MenuItem(I18N_TEXT("Add to the array group to the left", L10N_TABLE_CELL_CONV_ADD_AG_LEFT), nullptr, false, leftDisabled)) {
+ 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 || arrayDisabled;
- if (ImGui::MenuItem(I18N_TEXT("Add to the array group to the right", L10N_TABLE_CELL_CONV_ADD_AG_RIGHT), nullptr, false, rightDisabled)) {
+ 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);
}
@@ -291,6 +374,40 @@ private:
// TODO
}
+ void DisplayTableContents()
+ {
+ if (ImGui::TreeNode(ICON_FA_BONG " " I18N_TEXT("Parameters", L10N_TABLE_SINGLE_PARAMS))) {
+ TableSingleParamsIter iter(*mTable);
+ while (iter.HasNext()) {
+ auto& cell = iter.Next();
+ if (ImGui::Selectable(cell.Content.c_str())) {
+ SelectCell(cell.Location);
+ }
+ }
+ ImGui::TreePop();
+ }
+ if (ImGui::TreeNode(ICON_FA_LIST " " I18N_TEXT("Array groups", L10N_TABLE_ARRAY_GROUPS))) {
+ TableArrayGroupsIter iter(*mTable);
+ // For each array group
+ while (iter.HasNext()) {
+ if (ImGui::TreeNode(iter.PeekNameCStr())) {
+ auto& ag = iter.Peek();
+ // For each cell in the array group
+ for (int x = ag.LeftCell; x <= ag.RightCell; ++x) {
+ Vec2i pos{ x, ag.Row };
+ auto& cell = mTable->GetCell(pos);
+ if (ImGui::Selectable(cell.Content.c_str())) {
+ SelectCell(pos);
+ }
+ }
+ ImGui::TreePop();
+ }
+ iter.Next();
+ }
+ ImGui::TreePop();
+ }
+ }
+
void DisplayTableProperties()
{
// TODO