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

Commit 5aef8dd

Browse files
committed
Fix UIPanels being broken after resolution changes, better checks on size/position
1 parent c134c17 commit 5aef8dd

File tree

11 files changed

+152
-111
lines changed

11 files changed

+152
-111
lines changed

src/UI/Inspectors/GameObjectInspector.cs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ public override GameObject CreateContent(GameObject parent)
226226

227227
var scrollObj = UIFactory.CreateScrollView(UIRoot, "GameObjectInspector", out Content, out var scrollbar,
228228
new Color(0.065f, 0.065f, 0.065f));
229-
UIFactory.SetLayoutElement(scrollObj, minHeight: 300, flexibleWidth: 9999, flexibleHeight: 1);
229+
UIFactory.SetLayoutElement(scrollObj, minHeight: 250, preferredHeight: 300, flexibleHeight: 0, flexibleWidth: 9999);
230230

231231
UIFactory.SetLayoutGroup<VerticalLayoutGroup>(Content, spacing: 3, padTop: 2, padBottom: 2, padLeft: 2, padRight: 2);
232232

@@ -244,10 +244,7 @@ private void ConstructLists()
244244
{
245245
var listHolder = UIFactory.CreateUIObject("ListHolders", UIRoot);
246246
UIFactory.SetLayoutGroup<HorizontalLayoutGroup>(listHolder, false, true, true, true, 8, 2, 2, 2, 2);
247-
UIFactory.SetLayoutElement(listHolder, minHeight: 350, flexibleWidth: 9999, flexibleHeight: 9999);
248-
//var listRect = listHolder.GetComponent<RectTransform>();
249-
//listRect.anchorMin = new Vector2(0, 1);
250-
//listRect.anchorMax = new Vector2(1, 1);
247+
UIFactory.SetLayoutElement(listHolder, minHeight: 150, flexibleWidth: 9999, flexibleHeight: 9999);
251248

252249
// Left group (Children)
253250

src/UI/Inspectors/InspectUnderMouse.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -155,8 +155,8 @@ internal void UpdatePosition(Vector2 mousePos)
155155
mousePos.x = 350;
156156
if (mousePos.x > Screen.width - 350)
157157
mousePos.x = Screen.width - 350;
158-
if (mousePos.y < mainPanelRect.rect.height)
159-
mousePos.y += mainPanelRect.rect.height + 10;
158+
if (mousePos.y < Rect.rect.height)
159+
mousePos.y += Rect.rect.height + 10;
160160
else
161161
mousePos.y -= 10;
162162

@@ -341,10 +341,10 @@ private static void StopUIInspect()
341341

342342
protected internal override void DoSetDefaultPosAndAnchors()
343343
{
344-
mainPanelRect.anchorMin = Vector2.zero;
345-
mainPanelRect.anchorMax = Vector2.zero;
346-
mainPanelRect.pivot = new Vector2(0.5f, 1);
347-
mainPanelRect.sizeDelta = new Vector2(700, 150);
344+
Rect.anchorMin = Vector2.zero;
345+
Rect.anchorMax = Vector2.zero;
346+
Rect.pivot = new Vector2(0.5f, 1);
347+
Rect.sizeDelta = new Vector2(700, 150);
348348
}
349349

350350
public override void ConstructPanelContent()

src/UI/Panels/CSConsolePanel.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -62,10 +62,10 @@ public override void DoSaveToConfigElement()
6262

6363
protected internal override void DoSetDefaultPosAndAnchors()
6464
{
65-
mainPanelRect.localPosition = Vector2.zero;
66-
mainPanelRect.pivot = new Vector2(0f, 1f);
67-
mainPanelRect.anchorMin = new Vector2(0.4f, 0.175f);
68-
mainPanelRect.anchorMax = new Vector2(0.85f, 0.925f);
65+
Rect.localPosition = Vector2.zero;
66+
Rect.pivot = new Vector2(0f, 1f);
67+
Rect.anchorMin = new Vector2(0.4f, 0.175f);
68+
Rect.anchorMax = new Vector2(0.85f, 0.925f);
6969
}
7070

7171
public override void ConstructPanelContent()

src/UI/Panels/InspectorPanel.cs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ public class InspectorPanel : UIPanel
2626
public GameObject ContentHolder;
2727
public RectTransform ContentRect;
2828

29-
public static float CurrentPanelWidth => Instance.mainPanelRect.rect.width;
30-
public static float CurrentPanelHeight => Instance.mainPanelRect.rect.height;
29+
public static float CurrentPanelWidth => Instance.Rect.rect.width;
30+
public static float CurrentPanelHeight => Instance.Rect.rect.height;
3131

3232
public override void Update()
3333
{
@@ -38,7 +38,7 @@ public override void OnFinishResize(RectTransform panel)
3838
{
3939
base.OnFinishResize(panel);
4040

41-
InspectorManager.PanelWidth = this.mainPanelRect.rect.width;
41+
InspectorManager.PanelWidth = this.Rect.rect.width;
4242
InspectorManager.OnPanelResized(panel.rect.width);
4343
}
4444

@@ -51,10 +51,10 @@ public override void DoSaveToConfigElement()
5151

5252
protected internal override void DoSetDefaultPosAndAnchors()
5353
{
54-
mainPanelRect.localPosition = Vector2.zero;
55-
mainPanelRect.pivot = new Vector2(0f, 1f);
56-
mainPanelRect.anchorMin = new Vector2(0.35f, 0.175f);
57-
mainPanelRect.anchorMax = new Vector2(0.8f, 0.925f);
54+
Rect.localPosition = Vector2.zero;
55+
Rect.pivot = new Vector2(0f, 1f);
56+
Rect.anchorMin = new Vector2(0.35f, 0.175f);
57+
Rect.anchorMax = new Vector2(0.8f, 0.925f);
5858
}
5959

6060
public override void ConstructPanelContent()

src/UI/Panels/LogPanel.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ public override void SetActive(bool active)
5151

5252
if (active && !DoneScrollPoolInit)
5353
{
54-
LayoutRebuilder.ForceRebuildLayoutImmediate(this.mainPanelRect);
54+
LayoutRebuilder.ForceRebuildLayoutImmediate(this.Rect);
5555
logScrollPool.Initialize(this);
5656
DoneScrollPoolInit = true;
5757
}
@@ -158,10 +158,10 @@ public override void DoSaveToConfigElement()
158158

159159
protected internal override void DoSetDefaultPosAndAnchors()
160160
{
161-
mainPanelRect.localPosition = Vector2.zero;
162-
mainPanelRect.pivot = new Vector2(0f, 1f);
163-
mainPanelRect.anchorMin = new Vector2(0.5f, 0.03f);
164-
mainPanelRect.anchorMax = new Vector2(0.9f, 0.2f);
161+
Rect.localPosition = Vector2.zero;
162+
Rect.pivot = new Vector2(0f, 1f);
163+
Rect.anchorMin = new Vector2(0.5f, 0.03f);
164+
Rect.anchorMax = new Vector2(0.9f, 0.2f);
165165
}
166166

167167
// UI Construction

src/UI/Panels/ObjectExplorerPanel.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -99,10 +99,10 @@ public override void ApplySaveData(string data)
9999

100100
protected internal override void DoSetDefaultPosAndAnchors()
101101
{
102-
mainPanelRect.localPosition = Vector2.zero;
103-
mainPanelRect.pivot = new Vector2(0f, 1f);
104-
mainPanelRect.anchorMin = new Vector2(0.125f, 0.175f);
105-
mainPanelRect.anchorMax = new Vector2(0.325f, 0.925f);
102+
Rect.localPosition = Vector2.zero;
103+
Rect.pivot = new Vector2(0f, 1f);
104+
Rect.anchorMin = new Vector2(0.125f, 0.175f);
105+
Rect.anchorMax = new Vector2(0.325f, 0.925f);
106106
//mainPanelRect.SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, 350);
107107
}
108108

src/UI/Panels/OptionsPanel.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -69,11 +69,11 @@ public override void DoSaveToConfigElement()
6969

7070
protected internal override void DoSetDefaultPosAndAnchors()
7171
{
72-
mainPanelRect.localPosition = Vector2.zero;
73-
mainPanelRect.pivot = new Vector2(0f, 1f);
74-
mainPanelRect.anchorMin = new Vector2(0.5f, 0.1f);
75-
mainPanelRect.anchorMax = new Vector2(0.5f, 0.85f);
76-
mainPanelRect.SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, 600f);
72+
Rect.localPosition = Vector2.zero;
73+
Rect.pivot = new Vector2(0f, 1f);
74+
Rect.anchorMin = new Vector2(0.5f, 0.1f);
75+
Rect.anchorMax = new Vector2(0.5f, 0.85f);
76+
Rect.SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, 600f);
7777
}
7878

7979
// UI Construction

src/UI/Panels/PanelDragger.cs

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -250,15 +250,9 @@ public void OnDrag()
250250
Vector2 diff = (Vector2)mousePos - m_lastDragPosition;
251251
m_lastDragPosition = mousePos;
252252

253-
var pos = Panel.localPosition + (Vector3)diff;
253+
Panel.localPosition = Panel.localPosition + (Vector3)diff;
254254

255-
// Prevent panel going oustide screen bounds
256-
var halfW = Screen.width * 0.5f;
257-
var halfH = Screen.height * 0.5f;
258-
pos.x = Math.Max(-halfW, Math.Min(pos.x, halfW - Panel.rect.width));
259-
pos.y = Math.Max(-halfH + Panel.rect.height, Math.Min(pos.y, halfH));
260-
261-
Panel.localPosition = pos;
255+
UIPanel.EnsureValidPosition(Panel);
262256
}
263257

264258
public void OnEndDrag()
@@ -425,6 +419,9 @@ public void OnResize()
425419
if ((Vector2)mousePos == m_lastResizePos)
426420
return;
427421

422+
if (mousePos.x < 0 || mousePos.y < 0 || mousePos.x > Screen.width || mousePos.y > Screen.height)
423+
return;
424+
428425
m_lastResizePos = mousePos;
429426

430427
float diffX = (float)((decimal)diff.x / Screen.width);

0 commit comments

Comments
 (0)