Skip to content

Commit f1844f3

Browse files
committed
Move default window positioning to Utility #2
1 parent bd37138 commit f1844f3

File tree

2 files changed

+18
-13
lines changed

2 files changed

+18
-13
lines changed

Assets/MicroEngineer/Code/UI/EntryWindowController.cs

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -52,19 +52,8 @@ public void Initialize()
5252
WindowRoot[0].RegisterCallback<PointerUpEvent>(UpdateWindowPosition);
5353

5454
// Handle initial window positioning. Set the position OnGeometryChangedEvent.
55-
EventCallback<GeometryChangedEvent> _positionCallBack = null;
56-
_positionCallBack = evt =>
57-
{
58-
if (evt.newRect.width == 0 || evt.newRect.height == 0)
59-
return;
60-
61-
WindowRoot[0].style.left = EntryWindow.FlightRect.position.x;
62-
WindowRoot[0].style.top = EntryWindow.FlightRect.position.y;
63-
64-
WindowRoot[0].UnregisterCallback(_positionCallBack);
65-
};
66-
WindowRoot[0].RegisterCallback<GeometryChangedEvent>(_positionCallBack);
67-
55+
Utility.SetDefaultWindowPosition(WindowRoot[0], EntryWindow.FlightRect.position.x, EntryWindow.FlightRect.position.y);
56+
6857
// Hide the settings button if window is not editable (Stage window)
6958
if (!EntryWindow.IsEditable)
7059
SettingsButton.style.display = DisplayStyle.None;

Assets/MicroEngineer/Code/Utilities/Utility.cs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -330,5 +330,21 @@ public static void DisableGameInputOnFocus(this VisualElement element)
330330
element.RegisterCallback<FocusOutEvent>(_ => GameManager.Instance?.Game?.Input.Enable());
331331
}
332332
*/
333+
334+
public static void SetDefaultWindowPosition(VisualElement root, float x, float y)
335+
{
336+
EventCallback<GeometryChangedEvent> _positionCallBack = null;
337+
_positionCallBack = evt =>
338+
{
339+
if (evt.newRect.width == 0 || evt.newRect.height == 0)
340+
return;
341+
342+
root.style.left = x;
343+
root.style.top = y;
344+
345+
root.UnregisterCallback(_positionCallBack);
346+
};
347+
root.RegisterCallback<GeometryChangedEvent>(_positionCallBack);
348+
}
333349
}
334350
}

0 commit comments

Comments
 (0)