109 lines
2.5 KiB
C#
109 lines
2.5 KiB
C#
|
using ImGuiNET;
|
||
|
using Microsoft.VisualBasic;
|
||
|
|
||
|
namespace Shoko;
|
||
|
|
||
|
/// <summary>
|
||
|
/// This class mainly wraps ImGui calls to use lambdas instead of BeginX/EndX, or those that gives out a boolean as a return parameter
|
||
|
/// </summary>
|
||
|
static class Gui
|
||
|
{
|
||
|
public static void Window(ReadOnlySpan<char> name, Action f)
|
||
|
{
|
||
|
if(ImGui.Begin(name))
|
||
|
{
|
||
|
f();
|
||
|
}
|
||
|
ImGui.End();
|
||
|
}
|
||
|
public static void Window(ReadOnlySpan<char> name, ImGuiWindowFlags flags, Action f)
|
||
|
{
|
||
|
if(ImGui.Begin(name, flags))
|
||
|
{
|
||
|
f();
|
||
|
}
|
||
|
ImGui.End();
|
||
|
}
|
||
|
public static void Window(ReadOnlySpan<char> name, ref bool open, Action f)
|
||
|
{
|
||
|
if(ImGui.Begin(name, ref open))
|
||
|
{
|
||
|
f();
|
||
|
}
|
||
|
ImGui.End();
|
||
|
}
|
||
|
public static void Window(ReadOnlySpan<char> name, ref bool open, ImGuiWindowFlags flags, Action f)
|
||
|
{
|
||
|
if(ImGui.Begin(name, ref open, flags))
|
||
|
{
|
||
|
f();
|
||
|
}
|
||
|
ImGui.End();
|
||
|
}
|
||
|
public static void Menu(ReadOnlySpan<char> label, Action f)
|
||
|
{
|
||
|
if(ImGui.BeginMenu(label))
|
||
|
{
|
||
|
f();
|
||
|
ImGui.EndMenu();
|
||
|
}
|
||
|
}
|
||
|
public static void MainMenuBar(Action f)
|
||
|
{
|
||
|
if(ImGui.BeginMainMenuBar())
|
||
|
{
|
||
|
f();
|
||
|
ImGui.EndMainMenuBar();
|
||
|
}
|
||
|
}
|
||
|
public static void MenuItem(ReadOnlySpan<char> name, ReadOnlySpan<char> shortcut, Action f)
|
||
|
{
|
||
|
bool result = false;
|
||
|
ImGui.MenuItem(name, shortcut, ref result);
|
||
|
if(result) f();
|
||
|
}
|
||
|
public static void Button(ReadOnlySpan<char> label, Action f)
|
||
|
{
|
||
|
if(ImGui.Button(label)) f();
|
||
|
}
|
||
|
public static void MenuBar(Action f)
|
||
|
{
|
||
|
if(ImGui.BeginMenuBar())
|
||
|
{
|
||
|
f();
|
||
|
ImGui.EndMenuBar();
|
||
|
}
|
||
|
}
|
||
|
public static void TreeNode(ReadOnlySpan<char> label, Action f)
|
||
|
{
|
||
|
if(ImGui.TreeNode(label))
|
||
|
{
|
||
|
f();
|
||
|
ImGui.TreePop();
|
||
|
}
|
||
|
}
|
||
|
public static void Popup(ReadOnlySpan<char> str_id, Action f)
|
||
|
{
|
||
|
if(ImGui.BeginPopup(str_id))
|
||
|
{
|
||
|
f();
|
||
|
ImGui.EndPopup();
|
||
|
}
|
||
|
}
|
||
|
public static void Popup(ReadOnlySpan<char> str_id, ImGuiWindowFlags flags, Action f)
|
||
|
{
|
||
|
if(ImGui.BeginPopup(str_id, flags))
|
||
|
{
|
||
|
f();
|
||
|
ImGui.EndPopup();
|
||
|
}
|
||
|
}
|
||
|
public static void PopupModal(ReadOnlySpan<char> name, Action f)
|
||
|
{
|
||
|
if(ImGui.BeginPopupModal(name))
|
||
|
{
|
||
|
f();
|
||
|
ImGui.EndPopup();
|
||
|
}
|
||
|
}
|
||
|
}
|