-
Notifications
You must be signed in to change notification settings - Fork 8
/
ImguiExt.cs
96 lines (82 loc) · 2.48 KB
/
ImguiExt.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
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
using System;
using System.Collections.Generic;
using System.Numerics;
using ImGuiNET;
namespace ReAgent;
public static class ImguiExt
{
public static bool? DrawDeleteConfirmationPopup(string id, string deletedItemName)
{
bool? rv = null;
if (ImGui.BeginPopup(id))
{
ImGui.TextUnformatted($"Really delete {deletedItemName}?");
if (ImGui.Button("Yes"))
{
ImGui.CloseCurrentPopup();
rv = true;
}
ImGui.SameLine();
if (ImGui.Button("No"))
{
ImGui.CloseCurrentPopup();
rv = false;
}
ImGui.EndPopup();
}
else
{
return false;
}
return rv;
}
public static unsafe bool SetDragDropPayload<T>(string id, T payload) where T : unmanaged
{
return ImGui.SetDragDropPayload(id, (IntPtr)(&payload), (uint)sizeof(T));
}
public static unsafe T? AcceptDragDropPayload<T>(string id) where T : unmanaged
{
var ptr = ImGui.AcceptDragDropPayload(id);
if (ptr.NativePtr != null)
{
var data = *(T*)ptr.Data;
return data;
}
return null;
}
public static void DrawLargeTransparentSelectable(string id, Vector2 start)
{
var cursor = ImGui.GetCursorPos();
ImGui.SetCursorPos(start);
ImGui.PushStyleColor(ImGuiCol.HeaderHovered, 0);
ImGui.PushStyleColor(ImGuiCol.HeaderActive, 0);
ImGui.Selectable(id, false, ImGuiSelectableFlags.SpanAllColumns, new Vector2(0, cursor.Y - start.Y));
ImGui.PopStyleColor(2);
ImGui.SetCursorPos(cursor);
}
public static bool EnumerableComboBox<T>(string displayText, IEnumerable<T> items, ref T current)
{
var picked = false;
if (ImGui.BeginCombo(displayText, $"{current}"))
{
var counter = 0;
foreach (var item in items)
{
var selected = item.Equals(current);
if (ImGui.IsWindowAppearing() && selected)
{
ImGui.SetScrollHereY();
}
if (ImGui.Selectable($"{item}###{counter}", selected))
{
current = item;
picked = true;
break;
}
counter++;
}
ImGui.EndCombo();
}
return picked;
}
}