feat: add Window.BringToFront()

This commit is contained in:
goat 2023-01-26 23:26:40 +01:00
parent 261d8a167f
commit 636a6ae775
No known key found for this signature in database
GPG key ID: 49E2AA8C6A76498B

View file

@ -15,6 +15,7 @@ public abstract class Window
private bool internalLastIsOpen = false;
private bool internalIsOpen = false;
private bool nextFrameBringToFront = false;
/// <summary>
/// Initializes a new instance of the <see cref="Window"/> class.
@ -126,6 +127,17 @@ public abstract class Window
this.IsOpen ^= true;
}
/// <summary>
/// Bring this window to the front.
/// </summary>
public void BringToFront()
{
if (!this.IsOpen)
return;
this.nextFrameBringToFront = true;
}
/// <summary>
/// Code to always be executed before the open-state of the window is checked.
/// </summary>
@ -241,6 +253,12 @@ public abstract class Window
ImGui.PushStyleColor(ImGuiCol.TitleBgCollapsed, focusedHeaderColor);
}
if (this.nextFrameBringToFront)
{
ImGui.SetNextWindowFocus();
this.nextFrameBringToFront = false;
}
if (this.ShowCloseButton ? ImGui.Begin(this.WindowName, ref this.internalIsOpen, this.Flags) : ImGui.Begin(this.WindowName, this.Flags))
{
// Draw the actual window contents