Kaynağa Gözat

Enforce min size on move splitter not Setup

tznind 2 yıl önce
ebeveyn
işleme
58eca0de07
2 değiştirilmiş dosya ile 29 ekleme ve 2 silme
  1. 27 2
      Terminal.Gui/Views/TileView.cs
  2. 2 0
      UICatalog/UICatalog.cs

+ 27 - 2
Terminal.Gui/Views/TileView.cs

@@ -470,6 +470,8 @@ namespace Terminal.Gui {
 		{
 		{
 			int newSize = value.Anchor (fullSpace);
 			int newSize = value.Anchor (fullSpace);
 			bool isGettingBigger = newSize > splitterDistances [idx].Anchor (fullSpace);
 			bool isGettingBigger = newSize > splitterDistances [idx].Anchor (fullSpace);
+			int lastSplitterOrBorder = HasBorder()?1:0;
+			int nextSplitterOrBorder = HasBorder() ? fullSpace-1:fullSpace;
 
 
 			// Cannot move off screen right
 			// Cannot move off screen right
 			if (newSize >= fullSpace - (HasBorder () ? 1 : 0)) {
 			if (newSize >= fullSpace - (HasBorder () ? 1 : 0)) {
@@ -488,13 +490,36 @@ namespace Terminal.Gui {
 				if (newSize <= posLeft) {
 				if (newSize <= posLeft) {
 					return false;
 					return false;
 				}
 				}
+				
+				lastSplitterOrBorder = posLeft;
 			}
 			}
 
 
 			// Do not allow splitter to move right of the one after
 			// Do not allow splitter to move right of the one after
 			if (idx + 1 < splitterDistances.Count) {
 			if (idx + 1 < splitterDistances.Count) {
-				int posLeft = splitterDistances [idx + 1].Anchor (fullSpace);
+				int posRight = splitterDistances [idx + 1].Anchor (fullSpace);
+
+				if (newSize >= posRight) {
+					return false;
+				}
+				nextSplitterOrBorder = posRight;
+			}
+			
+			if(isGettingBigger) {
+				var spaceForNext = nextSplitterOrBorder - newSize;
+				
+				// space required for the line itself
+				spaceForNext--;
+
+				// don't grow if it would take us below min size of right panel
+				if (spaceForNext < tiles [idx+1].MinSize) {
+					return false;
+				}
+			}
+			else {
+				var spaceForLast = newSize - lastSplitterOrBorder;
 
 
-				if (newSize >= posLeft) {
+				// don't shrink if it would take us below min size of left panel
+				if (spaceForLast < tiles [idx].MinSize) {
 					return false;
 					return false;
 				}
 				}
 			}
 			}

+ 2 - 0
UICatalog/UICatalog.cs

@@ -233,6 +233,7 @@ namespace UICatalog {
 				CategoryListView.SelectedItemChanged += CategoryListView_SelectedChanged;
 				CategoryListView.SelectedItemChanged += CategoryListView_SelectedChanged;
 
 
 				ContentPane.Tiles.ElementAt(0).Title = "Categories";
 				ContentPane.Tiles.ElementAt(0).Title = "Categories";
+				ContentPane.Tiles.ElementAt (0).MinSize = 2;
 				ContentPane.Tiles.ElementAt (0).View.Add (CategoryListView);
 				ContentPane.Tiles.ElementAt (0).View.Add (CategoryListView);
 
 
 				ScenarioListView = new ListView () {
 				ScenarioListView = new ListView () {
@@ -248,6 +249,7 @@ namespace UICatalog {
 
 
 				ContentPane.Tiles.ElementAt (1).Title = "Scenarios";
 				ContentPane.Tiles.ElementAt (1).Title = "Scenarios";
 				ContentPane.Tiles.ElementAt (1).View.Add (ScenarioListView);
 				ContentPane.Tiles.ElementAt (1).View.Add (ScenarioListView);
+				ContentPane.Tiles.ElementAt (1).MinSize = 2;
 
 
 				KeyDown += KeyDownHandler;
 				KeyDown += KeyDownHandler;
 				Add (MenuBar);
 				Add (MenuBar);