瀏覽代碼

Refactor to use new method IsValidNewSplitterPos

tznind 2 年之前
父節點
當前提交
8c766a183b
共有 1 個文件被更改,包括 37 次插入30 次删除
  1. 37 30
      Terminal.Gui/Views/TileView.cs

+ 37 - 30
Terminal.Gui/Views/TileView.cs

@@ -315,36 +315,8 @@ namespace Terminal.Gui {
 
 
 			var fullSpace = orientation == Orientation.Vertical ? Bounds.Width : Bounds.Height;
 			var fullSpace = orientation == Orientation.Vertical ? Bounds.Width : Bounds.Height;
 
 
-			if(fullSpace != 0) {
-				int posUs = value.Anchor (fullSpace);
-				
-				// Cannot move off screen right
-				if (posUs >= fullSpace) {
-					return false;
-				}
-
-				// Cannot move off screen left
-				if (posUs <= 0) {
-					return false;
-				}
-
-				// Do not allow splitter to move left of the one before
-				if (idx > 0) {
-					int posLeft = splitterDistances [idx - 1].Anchor (fullSpace);
-
-					if (posUs <= posLeft) {
-						return false;
-					}
-				}
-
-				// Do not allow splitter to move right of the one after
-				if (idx+1 < splitterDistances.Count) {
-					int posLeft = splitterDistances [idx + 1].Anchor (fullSpace);
-
-					if (posUs >= posLeft) {
-						return false;
-					}
-				}
+			if(fullSpace != 0 && !IsValidNewSplitterPos(idx,value,fullSpace)) {
+				return false;
 			}
 			}
 
 
 			splitterDistances [idx] = value;
 			splitterDistances [idx] = value;
@@ -494,6 +466,41 @@ namespace Terminal.Gui {
 			return true;
 			return true;
 		}
 		}
 
 
+		private bool IsValidNewSplitterPos (int idx, Pos value, int fullSpace)
+		{
+			int newSize = value.Anchor (fullSpace);
+			bool isGettingBigger = newSize > splitterDistances [idx].Anchor (fullSpace);
+
+			// Cannot move off screen right
+			if (newSize >= fullSpace - (HasBorder () ? 1 : 0)) {
+				return false;
+			}
+
+			// Cannot move off screen left
+			if (newSize < (HasBorder()?1:0)) {
+				return false;
+			}
+
+			// Do not allow splitter to move left of the one before
+			if (idx > 0) {
+				int posLeft = splitterDistances [idx - 1].Anchor (fullSpace);
+
+				if (newSize <= posLeft) {
+					return false;
+				}
+			}
+
+			// Do not allow splitter to move right of the one after
+			if (idx + 1 < splitterDistances.Count) {
+				int posLeft = splitterDistances [idx + 1].Anchor (fullSpace);
+
+				if (newSize >= posLeft) {
+					return false;
+				}
+			}
+
+			return true;
+		}
 
 
 		private List<TileViewLineView> GetAllLineViewsRecursively (View v)
 		private List<TileViewLineView> GetAllLineViewsRecursively (View v)
 		{
 		{