-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathDialogHandler.cs
More file actions
131 lines (108 loc) · 3.91 KB
/
Copy pathDialogHandler.cs
File metadata and controls
131 lines (108 loc) · 3.91 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
using System;
using System.Collections.Generic;
using System.Numerics;
using System.Threading.Tasks;
using ImGuiNET;
namespace MapStudio.UI
{
public class DialogHandler
{
static string Name = "";
static Action DialogRender = null;
static bool open = false;
static bool isPopupOpen = true;
static Action<bool> Result;
static float Width;
static float Height;
static ImGuiWindowFlags Flags = ImGuiWindowFlags.None;
public static void RenderActiveWindows()
{
if (DialogRender == null)
return;
if (open)
{
ImGui.OpenPopup(Name);
isPopupOpen = true;
open = false;
}
if (!isPopupOpen) ClosePopup(false);
// Always center this window when appearing
var center = ImGui.GetMainViewport().GetCenter();
ImGui.SetNextWindowPos(center, ImGuiCond.Appearing, new System.Numerics.Vector2(0.5f, 0.5f));
if (Width != 0 && Height != 0)
ImGui.SetNextWindowSize(new System.Numerics.Vector2(Width, Height), ImGuiCond.Appearing);
if (ImGui.BeginPopupModal(Name, ref isPopupOpen, Flags))
{
DialogRender?.Invoke();
ImGui.EndPopup();
}
}
public static void ShowException(Exception ex)
{
string message = ex.Message.Replace("'", "");
Clipboard.SetText($"{ex.Message} \n{ex.StackTrace}");
TinyFileDialog.MessageBoxErrorOk($"{message} Details copied to clipboard!");
}
public static void Show(string name, float width, float height, Action dialogRender, Action<bool> dialogResult)
{
Width = width;
Height = height;
Name = name;
DialogRender = dialogRender;
open = true;
Result = dialogResult;
Flags = ImGuiWindowFlags.None;
}
public static void Show(string name, Action dialogRender, Action<bool> dialogResult, float width = 0, float height = 0)
{
//unconfigured. Defaults to ini settings
Width = width;
Height = height;
Name = name;
DialogRender = dialogRender;
open = true;
Result = dialogResult;
Flags = ImGuiWindowFlags.None;
}
//Todo this freezes
/* public static bool Show(string name, Action dialogRender) {
return Task.Run(() => ShowAsync(name, dialogRender)).Result;
}
public static async Task<bool> ShowAsync(string name, Action dialogRender)
{
Name = name;
DialogRender = dialogRender;
open = true;
var tcs = new TaskCompletionSource<bool>();
Result = (e) => { tcs.TrySetResult(e); };
return await tcs.Task.ConfigureAwait(false);
}*/
public static void DrawCancelOk(float width = 100, float height = 23)
{
ImGui.SetCursorPos(new Vector2(ImGui.GetWindowWidth() - 220, ImGui.GetWindowHeight() - 26));
var size = new Vector2(width, height);
if (ImGui.Button("Cancel", size))
DialogHandler.ClosePopup(false);
ImGui.SameLine();
if (ImGui.Button("Ok", size))
DialogHandler.ClosePopup(true);
}
public static void ClosePopup(bool isOk)
{
DialogRender = null;
ImGui.CloseCurrentPopup();
Result?.Invoke(isOk);
Result = null;
}
public static void ClosePopup()
{
DialogRender = null;
ImGui.CloseCurrentPopup();
}
public static void FinishTask(bool isOk)
{
Result?.Invoke(isOk);
Result = null;
}
}
}