forked from Ottermandias/OtterGui
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathImGuiTable.cs
41 lines (35 loc) · 1.36 KB
/
ImGuiTable.cs
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
using ImGuiNET;
using OtterGui.Raii;
namespace OtterGui;
public static class ImGuiTable
{
// Draw a simple table with the given data using the drawRow action.
// Headers and thus columns and column count are defined by columnTitles.
public static void DrawTable<T>(string label, IEnumerable<T> data, Action<T> drawRow, ImGuiTableFlags flags = ImGuiTableFlags.None,
params string[] columnTitles)
{
if (columnTitles.Length == 0)
return;
using var table = ImRaii.Table(label, columnTitles.Length, flags);
if (!table)
return;
foreach (var title in columnTitles)
{
ImGui.TableNextColumn();
ImGui.TableHeader(title);
}
foreach (var datum in data)
{
ImGui.TableNextRow();
drawRow(datum);
}
}
// Draw a simple table with the given data using the drawRow action inside a collapsing header.
// Headers and thus columns and column count are defined by columnTitles.
public static void DrawTabbedTable<T>(string label, IEnumerable<T> data, Action<T> drawRow, ImGuiTableFlags flags = ImGuiTableFlags.None,
params string[] columnTitles)
{
if (ImGui.CollapsingHeader(label))
DrawTable($"{label}##Table", data, drawRow, flags, columnTitles);
}
}