Skip to content

Commit 5ebcc80

Browse files
committed
Fix Flight windows initial positioning
1 parent 37f8cc6 commit 5ebcc80

File tree

2 files changed

+28
-2
lines changed

2 files changed

+28
-2
lines changed

Assets/MicroEngineer/Code/UI/EntryWindowController.cs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,20 @@ public void Initialize()
5050
Collapse();
5151

5252
WindowRoot[0].RegisterCallback<PointerUpEvent>(UpdateWindowPosition);
53-
WindowRoot[0].transform.position = EntryWindow.FlightRect.position;
53+
54+
// 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);
5467

5568
// Hide the settings button if window is not editable (Stage window)
5669
if (!EntryWindow.IsEditable)

Assets/MicroEngineer/Code/UI/MainGuiController.cs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,20 @@ public void OnEnable()
3434
Root[0].RegisterCallback<PointerUpEvent>(UpdateWindowPosition);
3535

3636
MainGuiWindow = (MainGuiWindow)Manager.Instance.Windows.Find(w => w is MainGuiWindow);
37-
Root[0].transform.position = MainGuiWindow.FlightRect.position;
37+
38+
// Handle initial window positioning. Set the position OnGeometryChangedEvent.
39+
EventCallback<GeometryChangedEvent> _positionCallBack = null;
40+
_positionCallBack = evt =>
41+
{
42+
if (evt.newRect.width == 0 || evt.newRect.height == 0)
43+
return;
44+
45+
Root[0].style.left = MainGuiWindow.FlightRect.position.x;
46+
Root[0].style.top = MainGuiWindow.FlightRect.position.y;
47+
48+
Root[0].UnregisterCallback(_positionCallBack);
49+
};
50+
Root[0].RegisterCallback<GeometryChangedEvent>(_positionCallBack);
3851
}
3952

4053
private void UpdateWindowPosition(PointerUpEvent evt)

0 commit comments

Comments
 (0)