Skip to content

Commit ae27cb3

Browse files
authored
Added parent closed check to utility window workaround (#433)
- Added parent closed check to utility window workaround - This is fix proposal for #429
2 parents 01af9c6 + 9ef3405 commit ae27cb3

File tree

4 files changed

+13
-8
lines changed

4 files changed

+13
-8
lines changed

Yafc.UI/Core/Ui.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,7 @@ public static void ProcessEvents() {
151151
window.FocusLost();
152152
break;
153153
case SDL.SDL_WindowEventID.SDL_WINDOWEVENT_FOCUS_GAINED:
154+
window.FocusGained();
154155
window.Rebuild();
155156
break;
156157
case SDL.SDL_WindowEventID.SDL_WINDOWEVENT_MINIMIZED:

Yafc.UI/Core/Window.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ public abstract class Window : IDisposable {
4040

4141
public event OnFocusLost? onFocusLost;
4242

43+
public Window? ChildWindow { get; set; }
44+
4345
internal void Create() {
4446
if (surface is null) {
4547
throw new InvalidOperationException($"surface must be set by a derived class before calling {nameof(Create)}.");
@@ -166,6 +168,7 @@ public void Repaint() {
166168
protected internal virtual void Close() {
167169
visible = false;
168170
closed = true;
171+
ChildWindow?.Close();
169172
surface?.Dispose();
170173
SDL.SDL_DestroyWindow(window);
171174
Dispose();
@@ -183,6 +186,8 @@ private void Focus() {
183186

184187
public virtual void FocusLost() => onFocusLost?.Invoke();
185188

189+
internal void FocusGained() => ChildWindow?.Focus();
190+
186191
public virtual void Minimized() { }
187192

188193
public void SetNextRepaint(long nextRepaintTime) {

Yafc.UI/Core/WindowUtility.cs

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@ protected void Create(string? title, float width, Window? parent) {
1414
}
1515

1616
this.parent = parent;
17+
if (parent != null) {
18+
parent.ChildWindow = this;
19+
}
1720
contentSize.X = width;
1821
int display = parent == null ? 0 : SDL.SDL_GetWindowDisplayIndex(parent.window);
1922
pixelsPerUnit = CalculateUnitsToPixels(display);
@@ -59,18 +62,13 @@ protected override void MainRender() {
5962
}
6063

6164
protected internal override void Close() {
65+
if (parent != null && !parent.closed) {
66+
parent.ChildWindow = null;
67+
}
6268
base.Close();
6369
parent = null;
6470
}
6571

66-
// TODO this is work-around for inability to create utility or modal window in SDL2
67-
// Fake utility windows are closed on focus lost
68-
public override void FocusLost() {
69-
if (parent != null) {
70-
Close();
71-
}
72-
base.FocusLost();
73-
}
7472
}
7573

7674
internal class UtilityWindowDrawingSurface : SoftwareDrawingSurface {

changelog.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ Date:
2929
- Hide fluid temperature options when not part of a recipe or not accepted by that recipe.
3030
- Modify text colors for highlighted rows in dark mode to improve readability.
3131
- Don't draw table intermediates as <1μ ingredients/products.
32+
- The file-picker on the Welcome Screen no longer closes by itself right after being opened.
3233
Internal changes:
3334
- Enable mod-fixes for the data, data-updates, and data-final-fixes files.
3435
- Recompile the lua lib for linux (PR 515). The script now uses CFLAGS and LDFLAGS.

0 commit comments

Comments
 (0)