Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#1 Track the state of the window when its in the Normal state #2

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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