0
mirror of https://github.com/sampletext32/ParkanPlayground.git synced 2025-05-18 19:31:17 +03:00
ParkanPlayground/NResUI/ImGuiUI/ImGuiModalPanel.cs
2024-11-15 20:29:02 +03:00

41 lines
1.1 KiB
C#

using System.Numerics;
using ImGuiNET;
using NResUI.Abstractions;
namespace NResUI.ImGuiUI;
public abstract class ImGuiModalPanel : IImGuiPanel
{
protected abstract string ImGuiId { get; }
protected Vector2 WindowSize { get; set; } = new Vector2(600, 400);
private bool _shouldOpen = false;
public virtual void Open()
{
_shouldOpen = true;
}
protected abstract void OnImGuiRenderContent();
public void OnImGuiRender()
{
// this is a ImGui stack fix. Because menubars and some other controls use their separate stack context,
// The panel gets rendered on it's own, at the root of the stack, and with _shouldOpen we control, if the panel should open this frame.
if (_shouldOpen)
{
ImGui.OpenPopup(ImGuiId, ImGuiPopupFlags.AnyPopupLevel);
_shouldOpen = false;
}
ImGui.SetNextWindowSize(WindowSize);
if (ImGui.BeginPopup(ImGuiId, ImGuiWindowFlags.NoResize))
{
OnImGuiRenderContent();
ImGui.EndPopup();
}
}
}