Skip to content

Commit

Permalink
Implement custom MessageBox with customizable options
Browse files Browse the repository at this point in the history
  • Loading branch information
shibbo committed Nov 7, 2023
1 parent 3348f58 commit fb67cb9
Show file tree
Hide file tree
Showing 2 changed files with 80 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Fushigi/ui/widgets/CourseScene.cs
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ public void DrawUI(GL gl)
{
CourseErrorList();
}

ulong selectionVersionBefore = activeViewport.mEditContext.SelectionVersion;

bool status = ImGui.Begin("Viewports");
Expand Down
79 changes: 79 additions & 0 deletions Fushigi/util/MessageBox.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
using ImGuiNET;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Numerics;
using System.Text;
using System.Threading.Tasks;

namespace Fushigi.util
{
public class MessageBox
{
public enum MessageBoxType
{
YesNo = 0,
Ok = 1
}

public enum MessageBoxResult
{
Waiting = -1,
Ok = 0,
No = 1,
Yes = 2,
Closed = 3
}

public MessageBox(MessageBoxType type)
{
mType = type;
}

public MessageBoxResult Show(string header, string message)
{
MessageBoxResult res = MessageBoxResult.Waiting;

bool needsClose = true;
bool status = ImGui.Begin(header, ref needsClose);
ImGui.Text(message);

switch (mType)
{
case MessageBoxType.Ok:
if (ImGui.Button("OK"))
{
res = MessageBoxResult.Ok;
}
break;
case MessageBoxType.YesNo:
if (ImGui.Button("Yes"))
{
res = MessageBoxResult.Yes;
}

ImGui.SameLine();

if (ImGui.Button("No"))
{
res = MessageBoxResult.No;
}
break;
}

if (!needsClose)
{
res = MessageBoxResult.Closed;
}

if (status)
{
ImGui.End();
}

return res;
}

MessageBoxType mType;
}
}

0 comments on commit fb67cb9

Please sign in to comment.