-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathTable.cs
More file actions
101 lines (88 loc) · 3.03 KB
/
Table.cs
File metadata and controls
101 lines (88 loc) · 3.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
using Godot;
using System;
using System.Collections.Generic;
using PrimerTools;
using PrimerTools.LaTeX;
public partial class Table : Node3D
{
// int numColumns = 3;
// int numRows = 3;
// private bool hasHeaderRow = true;
// private bool hasHeaderColumn = true;
public int HorizontalSpacing = 4;
public int VerticalSpacing = 2;
public Vector3 HeaderLatexScale = Vector3.One * 0.5f;
public Vector3 CellLatexScale = Vector3.One * 1f;
public LatexNode.HorizontalAlignmentOptions DefaultHorizontalAlignment = LatexNode.HorizontalAlignmentOptions.Center;
public LatexNode.VerticalAlignmentOptions DefaultVerticalAlignment = LatexNode.VerticalAlignmentOptions.Center;
private List<List<Node3D>> cells = new();
public void AddNode3DToPosition(Node3D node, int row, int column)
{
AddChild(node);
node.Position = new Vector3(column * HorizontalSpacing, -row * VerticalSpacing, 0);
// Make sure the column exists
if (cells.Count <= column)
{
cells.Add(new List<Node3D>());
}
if (cells[column].Count <= row)
{
cells[column].Add(null);
}
if (cells[column][row] != null)
{
GD.PrintErr("Overwriting a cell in the table");
}
else
{
cells[column][row] = node;
}
}
public void AddLatexNodeToPositionWithDefaultSettingsForTheTable(string latexString, int row, int column)
{
var newLatexNode = new LatexNode();
newLatexNode.latex = latexString;
newLatexNode.UpdateCharacters();
newLatexNode.Scale = row == 0 || column == 0 ? HeaderLatexScale : CellLatexScale;
newLatexNode.HorizontalAlignment = DefaultHorizontalAlignment;
newLatexNode.VerticalAlignment = DefaultVerticalAlignment;
AddNode3DToPosition(newLatexNode, row, column);
}
public void SetScaleOfAllChildren(Vector3 scale)
{
foreach (var child in GetChildren())
{
if (child is Node3D node)
{
node.Scale = scale;
}
}
}
public Animation ScaleAllChildrenToDefault()
{
var animations = new List<Animation>();
for (var i = 0; i < cells.Count; i++)
{
for (var j = 0; j < cells[i].Count; j++)
{
if (cells[i][j] is not null)
{
animations.Add(ScaleCellToDefault(i, j));
}
}
}
return animations.RunInParallel();
}
public Animation ScaleCellToDefault(int row, int column)
{
if (cells[column][row] is not null)
return cells[column][row].ScaleTo(row == 0 || column == 0 ? HeaderLatexScale : CellLatexScale);
GD.PrintErr("No cell at that position");
return null;
}
// public void SetSpacing(int horizontal, int vertical)
// {
// horizontalSpacing = horizontal;
// verticalSpacing = vertical;
// }
}