- Use EndConditional

- Fix #132 (maybe)
This commit is contained in:
Infi
2024-11-21 13:59:45 +01:00
parent d0a55e80ea
commit 5bd6518e1a
4 changed files with 93 additions and 57 deletions
+21 -1
View File
@@ -583,6 +583,26 @@ internal static class ImGuiUtil
}
}
// Use end-function only on success.
private struct EndConditionally(Action endAction, bool success) : ImRaii.IEndObject
{
public bool Success { get; } = success;
private bool Disposed { get; set; } = false;
private Action EndAction { get; } = endAction;
public void Dispose()
{
if (Disposed)
return;
if (Success)
EndAction();
Disposed = true;
}
}
public static ImRaii.IEndObject TextWrapPos()
{
ImGui.PushTextWrapPos();
@@ -600,7 +620,7 @@ internal static class ImGuiUtil
public static ImRaii.IEndObject Menu(string label)
{
return new EndUnconditionally(ImGui.EndMenu, ImGui.BeginMenu(label));
return new EndConditionally(ImGui.EndMenu, ImGui.BeginMenu(label));
}
public static void ChannelSelector(string headerText, Dictionary<ChatType, ChatSource> chatCodes)