using ImGuiNET; using Microsoft.VisualBasic; namespace Shoko; /// /// This class mainly wraps ImGui calls to use lambdas instead of BeginX/EndX, or those that gives out a boolean as a return parameter /// static class Gui { public static void Window(ReadOnlySpan name, Action f) { if(ImGui.Begin(name)) { f(); } ImGui.End(); } public static void Window(ReadOnlySpan name, ImGuiWindowFlags flags, Action f) { if(ImGui.Begin(name, flags)) { f(); } ImGui.End(); } public static void Window(ReadOnlySpan name, ref bool open, Action f) { if(ImGui.Begin(name, ref open)) { f(); } ImGui.End(); } public static void Window(ReadOnlySpan name, ref bool open, ImGuiWindowFlags flags, Action f) { if(ImGui.Begin(name, ref open, flags)) { f(); } ImGui.End(); } public static void Menu(ReadOnlySpan 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 name, ReadOnlySpan shortcut, Action f) { bool result = false; ImGui.MenuItem(name, shortcut, ref result); if(result) f(); } public static void Button(ReadOnlySpan 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 label, Action f) { if(ImGui.TreeNode(label)) { f(); ImGui.TreePop(); } } public static void Popup(ReadOnlySpan str_id, Action f) { if(ImGui.BeginPopup(str_id)) { f(); ImGui.EndPopup(); } } public static void Popup(ReadOnlySpan str_id, ImGuiWindowFlags flags, Action f) { if(ImGui.BeginPopup(str_id, flags)) { f(); ImGui.EndPopup(); } } public static void PopupModal(ReadOnlySpan name, Action f) { if(ImGui.BeginPopupModal(name)) { f(); ImGui.EndPopup(); } } }