From 4d3a377cb09770a139394b39cdfb46090c7c5804 Mon Sep 17 00:00:00 2001 From: Claude Date: Mon, 2 Nov 2026 23:28:46 +0000 Subject: [PATCH] [patch] Start the window where the last run left it WindowResized saved the window's size, position and layout to the options on every move or resize, but BuildConfig never passed them back, so every launch opened at the default 1280x720. BuildConfig now starts the window from the saved state. Fixes #523 Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_017vfJW5JsJWSEGD7D4Jhs1d --- ProjectDirector/ProjectDirector.cs | 3 ++ .../WindowStateTests.cs | 46 +++++++++++++++++++ 2 files changed, 49 insertions(+) create mode 100644 tests/ProjectDirector.UITests/WindowStateTests.cs diff --git a/ProjectDirector/ProjectDirector.cs b/ProjectDirector/ProjectDirector.cs index 5c400ef..b380ff7 100644 --- a/ProjectDirector/ProjectDirector.cs +++ b/ProjectDirector/ProjectDirector.cs @@ -77,6 +77,9 @@ internal sealed class ProjectDirector internal ImGuiAppConfig BuildConfig() => new() { Title = "Project Director", + + // The options are loaded by the constructor, so this is the state the last run saved. + InitialWindowState = Options.WindowState, OnAppMenu = ShowMenu, OnMoveOrResize = WindowResized, OnRender = Tick, diff --git a/tests/ProjectDirector.UITests/WindowStateTests.cs b/tests/ProjectDirector.UITests/WindowStateTests.cs new file mode 100644 index 0000000..37db40d --- /dev/null +++ b/tests/ProjectDirector.UITests/WindowStateTests.cs @@ -0,0 +1,46 @@ +// Copyright (c) 2023-2026 ktsu-dev contributors + +namespace ktsu.ProjectDirector.UITests; + +using System.IO.Abstractions.TestingHelpers; +using System.Numerics; + +using ktsu.AppDataStorage; +using ktsu.ImGui.App; + +using Silk.NET.Windowing; + +/// +/// The window's size, position and layout, which the application saves whenever the window moves +/// or resizes, and starts the next run with. +/// +[TestClass] +public sealed class WindowStateTests +{ + [TestMethod] + public void BuildConfig_StartsTheWindowWhereTheSavedOptionsLeftIt() + { + AppData.ConfigureForTesting(() => new MockFileSystem()); + try + { + ImGuiAppWindowState saved = new() + { + Size = new Vector2(1600, 1000), + Pos = new Vector2(2000, 150), + LayoutState = WindowState.Maximized, + }; + Assert.AreNotEqual(saved.LayoutState, new ImGuiAppWindowState().LayoutState, "The default layout is already maximized, so this would prove nothing."); + + using ProjectDirectorOptions options = new() { WindowState = saved }; + ImGuiAppConfig config = new ProjectDirector(options).BuildConfig(); + + Assert.AreEqual(saved.Size, config.InitialWindowState.Size); + Assert.AreEqual(saved.Pos, config.InitialWindowState.Pos); + Assert.AreEqual(saved.LayoutState, config.InitialWindowState.LayoutState); + } + finally + { + AppData.ResetFileSystem(); + } + } +}