Skip to content
This repository was archived by the owner on May 9, 2023. It is now read-only.

Commit 91bb58b

Browse files
committed
Fix panel resizing on alternate monitors
1 parent d67507e commit 91bb58b

File tree

5 files changed

+31
-22
lines changed

5 files changed

+31
-22
lines changed

src/UI/DisplayManager.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,11 @@ public static class DisplayManager
1313
public static int ActiveDisplayIndex { get; private set; }
1414
public static Display ActiveDisplay => Display.displays[ActiveDisplayIndex];
1515

16+
public static int Width => ActiveDisplay.renderingWidth;
17+
public static int Height => ActiveDisplay.renderingHeight;
18+
19+
public static Vector3 MousePosition => Display.RelativeMouseAt(InputManager.MousePosition);
20+
1621
private static Camera canvasCamera;
1722

1823
internal static void Init()
@@ -21,8 +26,6 @@ internal static void Init()
2126
ConfigManager.Target_Display.OnValueChanged += SetDisplay;
2227
}
2328

24-
public static Vector3 MousePosition => Display.RelativeMouseAt(InputManager.MousePosition);
25-
2629
public static void SetDisplay(int display)
2730
{
2831
if (ActiveDisplayIndex == display)

src/UI/Panels/PanelDragger.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,7 @@ public void OnEndDrag()
260260

261261
#region RESIZE
262262

263-
private readonly Dictionary<ResizeTypes, Rect> m_resizeMask = new Dictionary<ResizeTypes, Rect>
263+
private readonly Dictionary<ResizeTypes, Rect> m_resizeMask = new()
264264
{
265265
{ ResizeTypes.Top, default },
266266
{ ResizeTypes.Left, default },
@@ -413,13 +413,13 @@ public void OnResize()
413413
if ((Vector2)mousePos == lastResizePos)
414414
return;
415415

416-
if (mousePos.x < 0 || mousePos.y < 0 || mousePos.x > Screen.width || mousePos.y > Screen.height)
416+
if (mousePos.x < 0 || mousePos.y < 0 || mousePos.x > DisplayManager.Width || mousePos.y > DisplayManager.Height)
417417
return;
418418

419419
lastResizePos = mousePos;
420420

421-
float diffX = (float)((decimal)diff.x / Screen.width);
422-
float diffY = (float)((decimal)diff.y / Screen.height);
421+
float diffX = (float)((decimal)diff.x / DisplayManager.Width);
422+
float diffY = (float)((decimal)diff.y / DisplayManager.Height);
423423

424424
Vector2 anchorMin = Panel.anchorMin;
425425
Vector2 anchorMax = Panel.anchorMax;

src/UI/Panels/UIPanel.cs

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
using UniverseLib.UI.Models;
1212
using UniverseLib.UI;
1313
using UniverseLib;
14+
using System.Collections;
1415

1516
namespace UnityExplorer.UI.Panels
1617
{
@@ -150,8 +151,8 @@ public static void EnsureValidPosition(RectTransform panel)
150151
var pos = panel.localPosition;
151152

152153
// Prevent panel going oustide screen bounds
153-
var halfW = Screen.width * 0.5f;
154-
var halfH = Screen.height * 0.5f;
154+
var halfW = DisplayManager.Width * 0.5f;
155+
var halfH = DisplayManager.Height * 0.5f;
155156

156157
pos.x = Math.Max(-halfW - panel.rect.width + 50, Math.Min(pos.x, halfW - 50));
157158
pos.y = Math.Max(-halfH + 50, Math.Min(pos.y, halfH));
@@ -309,14 +310,7 @@ public void ConstructUI()
309310
SetTransformDefaults();
310311
}
311312

312-
LayoutRebuilder.ForceRebuildLayoutImmediate(this.Rect);
313-
314-
// ensure initialized position is valid
315-
EnsureValidSize();
316-
EnsureValidPosition(this.Rect);
317-
318-
// update dragger and save data
319-
Dragger.OnEndResize();
313+
RuntimeProvider.Instance.StartCoroutine(LateSetupCoroutine());
320314

321315
// simple listener for saving enabled state
322316
this.OnToggleEnabled += (bool val) =>
@@ -327,6 +321,18 @@ public void ConstructUI()
327321
ApplyingSaveData = false;
328322
}
329323

324+
private IEnumerator LateSetupCoroutine()
325+
{
326+
yield return null;
327+
328+
// ensure initialized position is valid
329+
EnsureValidSize();
330+
EnsureValidPosition(this.Rect);
331+
332+
// update dragger and save data
333+
Dragger.OnEndResize();
334+
}
335+
330336
public override void ConstructUI(GameObject parent) => ConstructUI();
331337
}
332338

@@ -381,7 +387,7 @@ internal static string RectPositionToString(this RectTransform rect)
381387

382388
return string.Format(CultureInfo.InvariantCulture, "{0},{1}", new object[]
383389
{
384-
rect.localPosition.x, rect.localPosition.y
390+
rect.anchoredPosition.x, rect.anchoredPosition.y
385391
});
386392
}
387393

@@ -399,10 +405,10 @@ internal static void SetPositionFromString(this RectTransform rect, string strin
399405
if (split.Length != 2)
400406
throw new Exception($"stringPosition split is unexpected length: {split.Length}");
401407

402-
Vector3 vector = rect.localPosition;
408+
Vector3 vector = rect.anchoredPosition;
403409
vector.x = float.Parse(split[0], CultureInfo.InvariantCulture);
404410
vector.y = float.Parse(split[1], CultureInfo.InvariantCulture);
405-
rect.localPosition = vector;
411+
rect.anchoredPosition = vector;
406412
}
407413
}
408414

src/UnityExplorer.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -175,13 +175,13 @@
175175
<Private>False</Private>
176176
</Reference>
177177
<Reference Include="UniverseLib.Mono">
178-
<HintPath>packages\UniverseLib.1.0.6\lib\net35\UniverseLib.Mono.dll</HintPath>
178+
<HintPath>packages\UniverseLib.1.1.0\lib\net35\UniverseLib.Mono.dll</HintPath>
179179
</Reference>
180180
</ItemGroup>
181181
<!-- Il2Cpp refs -->
182182
<ItemGroup Condition="'$(IsCpp)'=='true'">
183183
<Reference Include="UniverseLib.IL2CPP">
184-
<HintPath>packages\UniverseLib.1.0.6\lib\net472\UniverseLib.IL2CPP.dll</HintPath>
184+
<HintPath>packages\UniverseLib.1.1.0\lib\net472\UniverseLib.IL2CPP.dll</HintPath>
185185
</Reference>
186186
<Reference Include="UnhollowerBaseLib">
187187
<HintPath>..\lib\Il2CppAssemblyUnhollower\UnhollowerBaseLib\bin\Release\net4.7.2\UnhollowerBaseLib.dll</HintPath>

src/packages.config

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,5 @@
44
<package id="ILRepack.Lib.MSBuild.Task" version="2.0.18.2" targetFramework="net35" />
55
<package id="Mono.Cecil" version="0.10.4" targetFramework="net35" />
66
<package id="Samboy063.Tomlet" version="3.1.3" targetFramework="net472" />
7-
<package id="UniverseLib" version="1.0.6" targetFramework="net35" />
7+
<package id="UniverseLib" version="1.1.0" targetFramework="net35" />
88
</packages>

0 commit comments

Comments
 (0)