From b4b3c68d900db1293b2a9a5b6135535123ef353e Mon Sep 17 00:00:00 2001 From: matt-edmondson Date: Fri, 29 Mar 2024 08:08:46 +1100 Subject: [PATCH] #1 Track the state of the window when its in the Normal state --- ImGuiApp/ImGuiApp.cs | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/ImGuiApp/ImGuiApp.cs b/ImGuiApp/ImGuiApp.cs index 3303862..133ac9b 100644 --- a/ImGuiApp/ImGuiApp.cs +++ b/ImGuiApp/ImGuiApp.cs @@ -10,7 +10,6 @@ namespace ktsu.io.ImGuiApp; using Silk.NET.OpenGL.Extensions.ImGui; using Silk.NET.Windowing; - public class ImGuiAppWindowState { @@ -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 }; } @@ -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 @@ -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(); };