Skip to content

Commit

Permalink
#1 Track the state of the window when its in the Normal state
Browse files Browse the repository at this point in the history
  • Loading branch information
matt-edmondson committed Mar 28, 2024
1 parent ae4b957 commit b4b3c68
Showing 1 changed file with 17 additions and 3 deletions.
20 changes: 17 additions & 3 deletions ImGuiApp/ImGuiApp.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ namespace ktsu.io.ImGuiApp;
using Silk.NET.OpenGL.Extensions.ImGui;
using Silk.NET.Windowing;


public class ImGuiAppWindowState

{
Expand All @@ -23,12 +22,14 @@ public static partial class ImGuiApp
{
private static IWindow? window;

private static ImGuiAppWindowState LastNormalWindowState { get; set; } = new();

public static ImGuiAppWindowState WindowState
{
get => new()
{
Size = new(window?.Size.X ?? 1280, window?.Size.Y ?? 720),
Pos = new(window?.Position.X ?? 50, window?.Position.Y ?? 50),
Size = LastNormalWindowState.Size,
Pos = LastNormalWindowState.Pos,
LayoutState = window?.WindowState ?? Silk.NET.Windowing.WindowState.Normal
};
}
Expand Down Expand Up @@ -61,6 +62,7 @@ public static void Start(string windowTitle, ImGuiAppWindowState initialWindowSt
options.Size = new((int)initialWindowState.Size.X, (int)initialWindowState.Size.Y);
options.Position = new((int)initialWindowState.Pos.X, (int)initialWindowState.Pos.Y);
options.WindowState = initialWindowState.LayoutState;
LastNormalWindowState = initialWindowState;

// Adapted from: https://github.com/dotnet/Silk.NET/blob/main/examples/CSharp/OpenGL%20Demos/ImGui/Program.cs

Expand Down Expand Up @@ -91,11 +93,23 @@ public static void Start(string windowTitle, ImGuiAppWindowState initialWindowSt
{
// Adjust the viewport to the new window size
gl?.Viewport(s);
if (window?.WindowState == Silk.NET.Windowing.WindowState.Normal)
{
LastNormalWindowState.Size = new(window.Size.X, window.Size.Y);
LastNormalWindowState.Pos = new(window.Position.X, window.Position.Y);
LastNormalWindowState.LayoutState = Silk.NET.Windowing.WindowState.Normal;
}
onWindowResized?.Invoke();
};

window.Move += (p) =>
{
if (window?.WindowState == Silk.NET.Windowing.WindowState.Normal)
{
LastNormalWindowState.Size = new(window.Size.X, window.Size.Y);
LastNormalWindowState.Pos = new(window.Position.X, window.Position.Y);
LastNormalWindowState.LayoutState = Silk.NET.Windowing.WindowState.Normal;
}
onWindowResized?.Invoke();
};

Expand Down

0 comments on commit b4b3c68

Please sign in to comment.