forked from MasterScott/DevTree
-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathHelpers.cs
More file actions
68 lines (60 loc) · 1.9 KB
/
Helpers.cs
File metadata and controls
68 lines (60 loc) · 1.9 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
using System;
using System.Collections;
using System.Collections.Generic;
using System.Drawing;
using ExileCore.Shared.Helpers;
using GameOffsets.Native;
using ImGuiNET;
namespace DevTree;
public partial class DevPlugin
{
private static readonly HashSet<Type> PrimitiveTypes =
[
typeof(Enum),
typeof(string),
typeof(decimal),
typeof(DateTime),
typeof(TimeSpan),
typeof(Guid),
typeof(SharpDX.Vector2),
typeof(SharpDX.Vector3),
typeof(SharpDX.Vector4),
typeof(System.Numerics.Vector2),
typeof(System.Numerics.Vector3),
typeof(System.Numerics.Vector4),
typeof(Vector2i),
typeof(SharpDX.ColorBGRA),
];
public static bool IsEnumerable(Type type)
{
return type != typeof(string) && typeof(IEnumerable).IsAssignableFrom(type);
}
public static bool IsSimpleType(Type type)
{
return type.IsPrimitive ||
PrimitiveTypes.Contains(type) ||
Convert.GetTypeCode(type) != TypeCode.Object ||
type.BaseType == typeof(Enum) ||
type.IsGenericType &&
type.GetGenericTypeDefinition() == typeof(Nullable<>) &&
IsSimpleType(type.GetGenericArguments()[0]);
}
private bool ColoredTreeNode(string text, Color color, object entity, out bool isHovered)
{
ImGui.PushStyleColor(ImGuiCol.Text, color.ToImgui());
var result = TreeNode(text, entity, out isHovered);
ImGui.PopStyleColor();
return result;
}
private bool TreeNode(string text, object entity) => TreeNode(text, entity, out _);
private bool TreeNode(string text, object entity, out bool isHovered)
{
var result = ImGui.TreeNode(text);
isHovered = ImGui.IsItemHovered();
if (isHovered)
{
_lastHoveredMenuItem = entity;
}
return result;
}
}