-
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathSampleSpreadsheetGrid.cs
More file actions
336 lines (287 loc) · 10.3 KB
/
SampleSpreadsheetGrid.cs
File metadata and controls
336 lines (287 loc) · 10.3 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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
using FishUI;
using FishUI.Controls;
using System;
using System.Numerics;
namespace FishUIDemos
{
/// <summary>
/// Demonstrates the SpreadsheetGrid control with cell editing and navigation.
/// </summary>
public class SampleSpreadsheetGrid : ISample
{
FishUI.FishUI FUI;
Label _statusLabel;
SpreadsheetGrid _mainGrid;
SpreadsheetGrid _heatMapGrid;
CheckBox _heatMapToggle;
SpreadsheetGrid _cursorGrid;
Slider _cursorXSlider;
Slider _cursorYSlider;
Label _cursorPosLabel;
public string Name => "SpreadsheetGrid";
public TakeScreenshotFunc TakeScreenshot { get; set; }
public FishUI.FishUI CreateUI(FishUISettings UISettings, IFishUIGfx Gfx, IFishUIInput Input, IFishUIEvents Events)
{
FUI = new FishUI.FishUI(UISettings, Gfx, Input, Events);
FUI.Init();
FishUITheme theme = UISettings.LoadTheme(ThemePreferences.LoadThemePath(), applyImmediately: true);
return FUI;
}
public void Init()
{
// === Title ===
Label titleLabel = new Label("SpreadsheetGrid Demo");
titleLabel.Position = new Vector2(20, 20);
titleLabel.Size = new Vector2(300, 30);
titleLabel.Alignment = Align.Left;
FUI.AddControl(titleLabel);
// Screenshot button
ImageRef iconCamera = FUI.Graphics.LoadImage("data/silk_icons/camera.png");
Button screenshotBtn = new Button();
screenshotBtn.Icon = iconCamera;
screenshotBtn.Position = new Vector2(330, 20);
screenshotBtn.Size = new Vector2(30, 30);
screenshotBtn.IsImageButton = true;
screenshotBtn.TooltipText = "Take a screenshot";
screenshotBtn.OnButtonPressed += (btn, mbtn, pos) => TakeScreenshot?.Invoke(GetType().Name);
FUI.AddControl(screenshotBtn);
float yPos = 55;
// Instructions
Label instructionsLabel = new Label("Click cell to select, double-click or Enter to edit, Tab to navigate");
instructionsLabel.Position = new Vector2(20, yPos);
instructionsLabel.Size = new Vector2(550, 20);
instructionsLabel.Alignment = Align.Left;
FUI.AddControl(instructionsLabel);
yPos += 25;
// === Main SpreadsheetGrid ===
_mainGrid = new SpreadsheetGrid();
_mainGrid.Position = new Vector2(20, yPos);
_mainGrid.Size = new Vector2(600, 300);
_mainGrid.RowCount = 20;
_mainGrid.ColumnCount = 10;
_mainGrid.CellWidth = 80;
_mainGrid.CellHeight = 24;
// Pre-populate sample sales data
_mainGrid.SetCell(0, 0, "Product");
_mainGrid.SetCell(0, 1, "Q1");
_mainGrid.SetCell(0, 2, "Q2");
_mainGrid.SetCell(0, 3, "Q3");
_mainGrid.SetCell(0, 4, "Q4");
_mainGrid.SetCell(0, 5, "Total");
_mainGrid.SetCell(0, 6, "Avg");
_mainGrid.SetCell(1, 0, "Widgets");
_mainGrid.SetCell(1, 1, "1200");
_mainGrid.SetCell(1, 2, "1350");
_mainGrid.SetCell(1, 3, "1100");
_mainGrid.SetCell(1, 4, "1450");
_mainGrid.SetCell(1, 5, "5100");
_mainGrid.SetCell(1, 6, "1275");
_mainGrid.SetCell(2, 0, "Gadgets");
_mainGrid.SetCell(2, 1, "800");
_mainGrid.SetCell(2, 2, "950");
_mainGrid.SetCell(2, 3, "1050");
_mainGrid.SetCell(2, 4, "900");
_mainGrid.SetCell(2, 5, "3700");
_mainGrid.SetCell(2, 6, "925");
_mainGrid.SetCell(3, 0, "Tools");
_mainGrid.SetCell(3, 1, "450");
_mainGrid.SetCell(3, 2, "500");
_mainGrid.SetCell(3, 3, "475");
_mainGrid.SetCell(3, 4, "525");
_mainGrid.SetCell(3, 5, "1950");
_mainGrid.SetCell(3, 6, "487");
_mainGrid.SetCell(4, 0, "Parts");
_mainGrid.SetCell(4, 1, "320");
_mainGrid.SetCell(4, 2, "380");
_mainGrid.SetCell(4, 3, "410");
_mainGrid.SetCell(4, 4, "390");
_mainGrid.SetCell(4, 5, "1500");
_mainGrid.SetCell(4, 6, "375");
_mainGrid.OnSelectionChanged += OnSelectionChanged;
_mainGrid.OnCellChanged += OnCellChanged;
FUI.AddControl(_mainGrid);
yPos += 310;
// Status label
_statusLabel = new Label("Selected: A1");
_statusLabel.Position = new Vector2(20, yPos);
_statusLabel.Size = new Vector2(600, 20);
_statusLabel.Alignment = Align.Left;
FUI.AddControl(_statusLabel);
yPos += 25;
// Action buttons
Button clearBtn = new Button();
clearBtn.Text = "Clear All";
clearBtn.Position = new Vector2(20, yPos);
clearBtn.Size = new Vector2(90, 28);
clearBtn.OnButtonPressed += (btn, mbtn, pos) =>
{
_mainGrid.ClearAll();
_statusLabel.Text = "All cells cleared";
};
FUI.AddControl(clearBtn);
Button fillBtn = new Button();
fillBtn.Text = "Fill Sample";
fillBtn.Position = new Vector2(120, yPos);
fillBtn.Size = new Vector2(100, 28);
fillBtn.OnButtonPressed += (btn, mbtn, pos) =>
{
for (int r = 0; r < 6; r++)
{
for (int c = 0; c < 6; c++)
{
_mainGrid.SetCell(r, c, $"R{r + 1}C{c + 1}");
}
}
_statusLabel.Text = "Sample data filled";
};
FUI.AddControl(fillBtn);
// Keyboard shortcuts help
Label helpLabel = new Label("Keys: Arrows=Navigate, Enter=Edit, Tab=Next, Esc=Cancel, Del=Clear");
helpLabel.Position = new Vector2(240, yPos + 4);
helpLabel.Size = new Vector2(400, 20);
helpLabel.Alignment = Align.Left;
FUI.AddControl(helpLabel);
yPos += 45;
// === Heat Map Demo ===
Label heatMapLabel = new Label("Heat Map Mode Demo:");
heatMapLabel.Position = new Vector2(20, yPos);
heatMapLabel.Size = new Vector2(200, 20);
heatMapLabel.Alignment = Align.Left;
FUI.AddControl(heatMapLabel);
_heatMapToggle = new CheckBox();
_heatMapToggle.Position = new Vector2(180, yPos);
_heatMapToggle.Size = new Vector2(20, 20);
_heatMapToggle.IsChecked = true;
_heatMapToggle.OnCheckedChanged += (cb, isChecked) =>
{
_heatMapGrid.HeatMapMode = isChecked;
_statusLabel.Text = isChecked ? "Heat map enabled" : "Heat map disabled";
};
FUI.AddControl(_heatMapToggle);
Label toggleLabel = new Label("Enable");
toggleLabel.Position = new Vector2(205, yPos);
toggleLabel.Size = new Vector2(60, 20);
toggleLabel.Alignment = Align.Left;
FUI.AddControl(toggleLabel);
yPos += 25;
// Heat map grid with linear data (tilted plane visualization)
_heatMapGrid = new SpreadsheetGrid();
_heatMapGrid.Position = new Vector2(20, yPos);
_heatMapGrid.Size = new Vector2(380, 200);
_heatMapGrid.RowCount = 8;
_heatMapGrid.ColumnCount = 10;
_heatMapGrid.CellWidth = 36;
_heatMapGrid.CellHeight = 24;
_heatMapGrid.HeatMapMode = true;
_heatMapGrid.HeatMapMinColor = new FishColor(50, 150, 255, 200);
_heatMapGrid.HeatMapMaxColor = new FishColor(255, 80, 50, 200);
// Fill with linear data creating a tilted plane effect
// Values increase from top-left (low) to bottom-right (high)
for (int r = 0; r < 8; r++)
{
for (int c = 0; c < 10; c++)
{
// Linear gradient: combine row and column contributions
int value = (r * 8) + (c * 6); // Creates a diagonal gradient
_heatMapGrid.SetCell(r, c, value.ToString());
}
}
FUI.AddControl(_heatMapGrid);
// Heat map legend
Label legendLabel = new Label("Tilted plane: Blue (0) at top-left, Red (110) at bottom-right");
legendLabel.Position = new Vector2(20, yPos + 205);
legendLabel.Size = new Vector2(380, 20);
legendLabel.Alignment = Align.Left;
FUI.AddControl(legendLabel);
// === Cursor Display Demo (right side) ===
float cursorDemoX = 420;
Label cursorLabel = new Label("Cursor Display Mode (ECU Editor Style):");
cursorLabel.Position = new Vector2(cursorDemoX, yPos);
cursorLabel.Size = new Vector2(280, 20);
cursorLabel.Alignment = Align.Left;
FUI.AddControl(cursorLabel);
// Cursor grid
_cursorGrid = new SpreadsheetGrid();
_cursorGrid.Position = new Vector2(cursorDemoX, yPos + 25);
_cursorGrid.Size = new Vector2(340, 170);
_cursorGrid.RowCount = 6;
_cursorGrid.ColumnCount = 6;
_cursorGrid.CellWidth = 52;
_cursorGrid.CellHeight = 26;
_cursorGrid.CursorMode = true;
_cursorGrid.CursorX = 0.5f;
_cursorGrid.CursorY = 0.5f;
_cursorGrid.CursorColor = new FishColor(255, 100, 0, 220);
_cursorGrid.CursorRadius = 10f;
_cursorGrid.CursorLineThickness = 2f;
// Fill with sample data (tilted plane like heat map)
for (int r = 0; r < 6; r++)
{
for (int c = 0; c < 6; c++)
{
int value = (r * 10) + (c * 8);
_cursorGrid.SetCell(r, c, value.ToString());
}
}
FUI.AddControl(_cursorGrid);
// X slider
Label xLabel = new Label("X:");
xLabel.Position = new Vector2(cursorDemoX, yPos + 200);
xLabel.Size = new Vector2(20, 20);
xLabel.Alignment = Align.Left;
FUI.AddControl(xLabel);
_cursorXSlider = new Slider();
_cursorXSlider.Position = new Vector2(cursorDemoX + 25, yPos + 200);
_cursorXSlider.Size = new Vector2(130, 20);
_cursorXSlider.Value = 50;
_cursorXSlider.OnValueChanged += (slider, value) =>
{
_cursorGrid.CursorX = value / 100f;
UpdateCursorPosLabel();
};
FUI.AddControl(_cursorXSlider);
// Y slider
Label yLabel = new Label("Y:");
yLabel.Position = new Vector2(cursorDemoX + 165, yPos + 200);
yLabel.Size = new Vector2(20, 20);
yLabel.Alignment = Align.Left;
FUI.AddControl(yLabel);
_cursorYSlider = new Slider();
_cursorYSlider.Position = new Vector2(cursorDemoX + 185, yPos + 200);
_cursorYSlider.Size = new Vector2(130, 20);
_cursorYSlider.Value = 50;
_cursorYSlider.OnValueChanged += (slider, value) =>
{
_cursorGrid.CursorY = value / 100f;
UpdateCursorPosLabel();
};
FUI.AddControl(_cursorYSlider);
// Cursor position label
_cursorPosLabel = new Label("Cursor: (0.50, 0.50)");
_cursorPosLabel.Position = new Vector2(cursorDemoX, yPos + 225);
_cursorPosLabel.Size = new Vector2(200, 20);
_cursorPosLabel.Alignment = Align.Left;
FUI.AddControl(_cursorPosLabel);
}
private void UpdateCursorPosLabel()
{
_cursorPosLabel.Text = $"Cursor: ({_cursorGrid.CursorX:F2}, {_cursorGrid.CursorY:F2})";
}
private void OnSelectionChanged(SpreadsheetGrid grid, int row, int column)
{
string cellRef = SpreadsheetGrid.GetColumnLetter(column) + (row + 1).ToString();
string value = grid.GetCell(row, column);
_statusLabel.Text = string.IsNullOrEmpty(value)
? $"Selected: {cellRef}"
: $"Selected: {cellRef} = \"{value}\"";
}
private void OnCellChanged(SpreadsheetGrid grid, int row, int column, string oldValue, string newValue)
{
string cellRef = SpreadsheetGrid.GetColumnLetter(column) + (row + 1).ToString();
_statusLabel.Text = $"Cell {cellRef} changed: \"{oldValue}\" -> \"{newValue}\"";
}
public void Update(float dt)
{
}
}
}