Browse Source

Prototype support for collapsed panels

tznind 2 years ago
parent
commit
e9a5c4913d
1 changed files with 44 additions and 0 deletions
  1. 44 0
      Terminal.Gui/Views/SplitContainer.cs

+ 44 - 0
Terminal.Gui/Views/SplitContainer.cs

@@ -31,6 +31,29 @@ namespace Terminal.Gui {
 
 
 			splitterLine.Orientation = Orientation;
 			splitterLine.Orientation = Orientation;
 
 
+			if(panel1Collapsed || panel2Collapsed) {
+				SetupForCollapsedPanel ();
+			}
+			else {
+				SetupForNormal ();
+			}
+		}
+
+		private void SetupForNormal ()
+		{
+			// Ensure all our component views are here
+			// (e.g. if we are transitioning from a collapsed state)
+
+			if (!this.Subviews.Contains (splitterLine)) {
+				this.Add (splitterLine);
+			}
+			if (!this.Subviews.Contains (Panel1)) {
+				this.Add (Panel1);
+			}
+			if (!this.Subviews.Contains (Panel2)) {
+				this.Add (Panel2);
+			}
+
 			switch (Orientation) {
 			switch (Orientation) {
 			case Orientation.Horizontal:
 			case Orientation.Horizontal:
 				splitterLine.X = 0;
 				splitterLine.X = 0;
@@ -74,6 +97,27 @@ namespace Terminal.Gui {
 			};
 			};
 		}
 		}
 
 
+		private void SetupForCollapsedPanel ()
+		{
+			View toRemove = panel1Collapsed ? Panel1 : Panel2;
+			View toFullSize = panel1Collapsed ? Panel2 : Panel1;
+			
+			if (this.Subviews.Contains (splitterLine)) {
+				this.Subviews.Remove (splitterLine);
+			}
+			if (this.Subviews.Contains(toRemove)) {
+				this.Subviews.Remove (toRemove);
+			}
+			if(!this.Subviews.Contains(toFullSize)) {
+				this.Add (toFullSize);
+			}
+
+			toFullSize.X = 0;
+			toFullSize.Y = 0;
+			toFullSize.Width = Dim.Fill ();
+			toFullSize.Height = Dim.Fill ();
+		}
+
 		/// <summary>
 		/// <summary>
 		/// The left or top panel of the <see cref="SplitContainer"/>
 		/// The left or top panel of the <see cref="SplitContainer"/>
 		/// (depending on <see cref="Orientation"/>).  Add panel contents
 		/// (depending on <see cref="Orientation"/>).  Add panel contents