EditorHUD: Improved 'snap to left' behaviour.
[VOID.git] / VOID_EditorHUD.cs
blob:a/VOID_EditorHUD.cs -> blob:b/VOID_EditorHUD.cs
--- a/VOID_EditorHUD.cs
+++ b/VOID_EditorHUD.cs
@@ -48,6 +48,9 @@
 		protected HUDWindow ehudWindow;
 		protected EditorVesselOverlays _vesselOverlays;
 
+		[AVOID_SaveValue("snapToLeft")]
+		protected VOID_SaveValue<bool> snapToLeft;
+
 		/*
 		 * Properties
 		 * */
@@ -101,6 +104,8 @@
 
 			this.toggleActive = true;
 
+			this.snapToLeft.value = true;
+
 			this.ehudWindow = new HUDWindow(
 				this.ehudWindowFunc,
 				new Rect(EditorPanels.Instance.partsPanelWidth + 10f, 125f, 300f, 64f)
@@ -189,8 +194,6 @@
 			{
 				return;
 			}
-
-			bool snapToEdge = Mathf.Abs(this.ehudWindowPos.value.xMin - hudLeft) < 15f;
 
 			Tools.PostDebugMessage(this,
 				"EditorPartList topLeft.parent.parent.position: {0}\n" +
@@ -200,20 +203,29 @@
 				EditorPartList.Instance.transformTopLeft.parent.parent.position,
 				EditorPartList.Instance.transformTopLeft.parent.position,
 				EditorPartList.Instance.transformTopLeft.position,
-				snapToEdge, this.ehudWindowPos.value.xMin, hudLeft
+				this.snapToLeft, this.ehudWindowPos.value.xMin, hudLeft
 			);
 
 			base.DrawGUI();
 
 			Rect hudPos = this.ehudWindow.WindowPos;
 
-			hudPos.xMin = hudLeft;
+			if (this.snapToLeft && this.positionsLocked)
+			{
+				hudPos.xMin = hudLeft;
+			}
+			else
+			{
+				hudPos.xMin = Mathf.Max(hudLeft, hudPos.xMin);
+			}
+
 			hudPos.width = this.ehudWindow.defaultWindowPos.width;
 
 			this.ehudWindowPos.value = hudPos;
 
 			this.ehudWindow.WindowPos = this.ehudWindowPos;
 
+			this.snapToLeft = Mathf.Abs(this.ehudWindowPos.value.xMin - hudLeft) < 15f;
 		}
 	}
 }