-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathWindowDrawHelpers.cs
More file actions
151 lines (129 loc) · 4.99 KB
/
WindowDrawHelpers.cs
File metadata and controls
151 lines (129 loc) · 4.99 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
using Dalamud.Utility;
using FFXIVClientStructs.FFXIV.Common.Math;
using Dalamud.Bindings.ImGui;
namespace DrahsidLib;
public delegate void DrawToolTipDelegate(string label);
/// <summary>
/// Some helper functions for ImGui.
/// </summary>
public static class WindowDrawHelpers {
/// <summary>
/// Lazily evaluated size of F character
/// </summary>
private static Vector2? _TextSizeF = null;
internal static Vector2 TextSizeF {
get {
return _TextSizeF ??= ImGui.CalcTextSize("F");
}
set {
_TextSizeF = value;
}
}
internal static float TextSizeFWidthx10 {
get {
return TextSizeF.X * 10.0f;
}
}
/// <summary>
/// Draw a tooltip if the most recent item is hovered.
/// </summary>
/// <param name="label">Tooltip text.</param>
public static void DrawTooltipDefaultImpl(string label) {
if (ImGui.IsItemHovered()) {
ImGui.SetTooltip(label);
}
}
/// <summary>
/// Allow the ability to override the default DrawTooltip function (for using hide tooltips)
/// </summary>
public static DrawToolTipDelegate DrawTooltip = DrawTooltipDefaultImpl;
/// <summary>
/// Draws both a float slider, and an input. Supports using a tooltip.
/// </summary>
/// <param name="label">Text used for the `label` parameter.</param>
/// <param name="cvar">Value to output to.</param>
/// <param name="tooltip">Tooltip to display for the float.</param>
/// <param name="min">Minimum float for the slider.</param>
/// <param name="max">Maximum float for the slider.</param>
/// <returns>True if cvar changed.</returns>
public static bool DrawFloatInputTooltip(string label, ref float cvar, string tooltip, float min = 0, float max = 1) {
bool result;
bool drawTooltip = tooltip.IsNullOrEmpty() == false;
ImGui.SetNextItemWidth(TextSizeFWidthx10 * 2);
result = ImGui.SliderFloat(label, ref cvar, min, max);
if (drawTooltip) {
DrawTooltip(tooltip);
}
ImGui.SameLine();
ImGui.SetNextItemWidth(TextSizeFWidthx10);
result |= ImGui.InputFloat($"##{label}sl", ref cvar);
if (drawTooltip) {
DrawTooltip(tooltip);
}
return result;
}
/// <summary>
/// Draws both a float slider, and an input.
/// </summary>
/// <param name="label">Text used for the `label` parameter.</param>
/// <param name="cvar">Value to output to.</param>
/// <param name="min">Minimum float for the slider.</param>
/// <param name="max">Maximum float for the slider.</param>
/// <returns>True if cvar changed.</returns>
public static bool DrawFloatInput(string label, ref float cvar, float min = 0, float max = 1) {
bool result;
ImGui.SetNextItemWidth(TextSizeFWidthx10 * 2);
result = ImGui.SliderFloat(label, ref cvar, min, max);
ImGui.SameLine();
ImGui.SetNextItemWidth(TextSizeFWidthx10);
result |= ImGui.InputFloat($"##{label}sl", ref cvar);
return result;
}
/// <summary>
/// Draw a checkbox with a tooltip.
/// </summary>
/// <param name="label">Text used for the `label` parameter.</param>
/// <param name="cvar">Value to output to.</param>
/// <param name="tooltip">Tooltip to display for the float.</param>
/// <returns>True if the checkbox was toggled.</returns>
public static bool DrawCheckboxTooltip(string label, ref bool cvar, string tooltip) {
bool ret = ImGui.Checkbox(label, ref cvar);
if (tooltip.IsNullOrEmpty() == false) {
DrawTooltip(tooltip);
}
return ret;
}
/// <summary>
/// Draw a button with a tooltip.
/// </summary>
/// <param name="label">Text used for the `label` parameter.</param>
/// <param name="tooltip">Tooltip to display for the float.</param>
/// <returns></returns>
public static bool DrawButtonTooltip(string label, string tooltip) {
bool ret = ImGui.Button(label);
if (tooltip.IsNullOrEmpty() == false) {
DrawTooltip(tooltip);
}
return ret;
}
/// <summary>
/// Draw input text with a tooltip.
/// </summary>
/// <param name="label">Text used for the `label` parameter.</param>
/// <param name="cvar">Value to output to.</param>
/// <param name="tooltip">Tooltip to display for the float.</param>
/// <returns></returns>
public static bool DrawInputTextTooltip(string label, ref string cvar, string tooltip, uint maxlength = 32) {
bool ret = ImGuiDL.InputText(label, ref cvar, maxlength);
if (tooltip.IsNullOrEmpty() == false) {
DrawTooltip(tooltip);
}
return ret;
}
public static uint ColorToUint(Vector4 color) {
return (uint)(((byte)(color.W * 255) << 24) |
((byte)(color.X * 255) << 16) |
((byte)(color.Y * 255) << 8) |
(byte)(color.Z * 255));
}
}