summaryrefslogtreecommitdiff
path: root/core/src
diff options
context:
space:
mode:
authorrtk0c <[email protected]>2021-06-14 22:28:34 -0700
committerrtk0c <[email protected]>2021-06-14 22:28:34 -0700
commiteec8dfd8a21b8bb37f6acac1da84cde8fbf7ace7 (patch)
treed6368d4157a1d850f135f441dfa381ad26f8eac3 /core/src
parentd3a9d7565b18404b2042c9dc025cc690250cb50c (diff)
Table cell text rendering and inspector
Diffstat (limited to 'core/src')
-rw-r--r--core/src/Locale/zh_CN.h4
-rw-r--r--core/src/UI/UI_Templates.cpp48
2 files changed, 52 insertions, 0 deletions
diff --git a/core/src/Locale/zh_CN.h b/core/src/Locale/zh_CN.h
index 367a9d1..8e0e3e3 100644
--- a/core/src/Locale/zh_CN.h
+++ b/core/src/Locale/zh_CN.h
@@ -124,6 +124,10 @@
#define L10N_TEMPLATE_TABLE "表格模板"
#define L10N_TABLE_CELL_HORIZONTAL_ALIGNMENT "水平对齐"
+#define L10N_TABLE_CELL_CONTENT "内容"
+#define L10N_TABLE_CELL_VAR_NAME "变量名"
+#define L10N_TABLE_CELL_VAR_TOOLTIP "参数单元格的唯一名称(表格内不得重复)。"
+#define L10N_TABLE_CELL_ARRAY_VAR_TOOLTIP "列表参数组内单个参数单元格的名称,在组内唯一(不同的参数组可以包含相同的参数名)。"
#define L10N_TABLE_CELL_VERTICAL_ALIGNMENT "垂直对齐"
#define L10N_TABLE_CELL_ALIGN_LEFT "左对齐"
#define L10N_TABLE_CELL_ALIGN_CENTER "居中"
diff --git a/core/src/UI/UI_Templates.cpp b/core/src/UI/UI_Templates.cpp
index 48393dc..ab9c317 100644
--- a/core/src/UI/UI_Templates.cpp
+++ b/core/src/UI/UI_Templates.cpp
@@ -154,6 +154,30 @@ private:
}
ImGui::EndCombo();
}
+
+ switch (cell.Type) {
+ case TableCell::ConstantCell:
+ ImGui::InputText(I18N_TEXT("Content", L10N_TABLE_CELL_CONTENT), &cell.Content);
+ break;
+
+ case TableCell::SingularParametricCell:
+ if (ImGui::InputText(I18N_TEXT("Variable name", L10N_TABLE_CELL_VAR_NAME), &cell.Content)) {
+ // TODO validate if name is repeat
+ }
+ if (ImGui::IsItemHovered()) {
+ ImGui::SetTooltip(I18N_TEXT("Name of the parameter link to this cell.", L10N_TABLE_CELL_VAR_TOOLTIP));
+ }
+ break;
+
+ case TableCell::ArrayParametricCell:
+ if (ImGui::InputText(I18N_TEXT("Variable name", L10N_TABLE_CELL_VAR_NAME), &cell.Content)) {
+ // TODO validate if name is repeat
+ }
+ if (ImGui::IsItemHovered()) {
+ ImGui::SetTooltip(I18N_TEXT("Name of the parameter lnk to this cell; local within the array group.", L10N_TABLE_CELL_ARRAY_VAR_TOOLTIP));
+ }
+ break;
+ }
}
void DisplayRangeProperties(Vec2i tl, Vec2i br)
@@ -198,6 +222,9 @@ private:
window->DC.CursorPos + ImGui::CalcItemSize(size, 0.0f, 0.0f),
};
+ // TODO draw indicator for parameter cells
+ /* Draw cell body */
+
if (uiCell.Selected) {
window->DrawList->AddRectFilled(
rect.Min - ImVec2(2, 1),
@@ -215,6 +242,27 @@ private:
window->DrawList->AddRectFilled(rect.Min, rect.Max, color);
}
+ /* Draw cell content */
+
+ auto content = cell.Content.c_str();
+ auto contentEnd = content + cell.Content.size();
+ auto textSize = ImGui::CalcTextSize(content, contentEnd);
+
+ ImVec2 textRenderPos;
+ switch (cell.HorizontalAlignment) {
+ case TableCell::AlignAxisMin: textRenderPos.x = rect.Min.x; break;
+ case TableCell::AlignCenter: textRenderPos.x = rect.Min.x + colWidth / 2 - textSize.x / 2; break;
+ case TableCell::AlignAxisMax: textRenderPos.x = rect.Max.x - textSize.x; break;
+ }
+ switch (cell.VerticalAlignment) {
+ case TableCell::AlignAxisMin: textRenderPos.y = rect.Min.y; break;
+ case TableCell::AlignCenter: textRenderPos.y = rect.Min.y + rowHeight / 2 - textSize.y / 2; break;
+ case TableCell::AlignAxisMax: textRenderPos.y = rect.Max.y - textSize.y; break;
+ }
+ window->DrawList->AddText(textRenderPos, IM_COL32(0, 0, 0, 255), content, contentEnd);
+
+ /* Update ImGui cursor */
+
ImGui::ItemSize(size);
if (!ImGui::ItemAdd(rect, id)) {
continue;