Browse Source

Add SplitContainerNesting scaffolding

tznind 2 years ago
parent
commit
849775c258

+ 10 - 10
Terminal.Gui/Views/SplitContainer.cs

@@ -120,7 +120,7 @@ namespace Terminal.Gui {
 						contentArea.Height - 1);
 				}
 
-				Setup (this, contentArea);
+				Setup (contentArea);
 			}			
 
 			base.LayoutSubviews ();
@@ -175,17 +175,17 @@ namespace Terminal.Gui {
 
 				lc.AddLine(new Point(bounds.Width-1,bounds.Height-1),-bounds.Width + 1,Orientation.Horizontal,IntegratedBorder);
 				lc.AddLine(new Point(bounds.Width-1,bounds.Height-1),-bounds.Height + 1,Orientation.Vertical,IntegratedBorder);
-				
-				foreach(var line in GetAllChildSplitContainerLineViewRecursively(this))
+
+				foreach (var line in GetAllChildSplitContainerLineViewRecursively(this))
 				{
-					var lineScreen = line.ViewToScreen(line.Bounds);
-					var localOrigin = ScreenToView(lineScreen.X,lineScreen.Y);
+					line.ViewToScreen(0,0,out var x1,out var y1);
+					var localOrigin = ScreenToView(x1,y1);
 
 					lc.AddLine(
 						localOrigin,
 						line.Orientation == Orientation.Horizontal ?
-							line.Frame.Width:
-							line.Frame.Height,
+							line.Frame.Width+1:
+							line.Frame.Height+1,
 						line.Orientation,
 						IntegratedBorder);
 					
@@ -257,7 +257,7 @@ namespace Terminal.Gui {
 
 			return root;
 		}
-		private void Setup (SplitContainer splitContainer, Rect bounds)
+		private void Setup (Rect bounds)
 		{
 			splitterLine.Orientation = Orientation;
 			// splitterLine.Text = Panel2.Title;
@@ -296,14 +296,14 @@ namespace Terminal.Gui {
 					Panel2.Y = Pos.Bottom (splitterLine);
 					Panel2.X = bounds.X;
 					Panel2.Width = bounds.Width;
-					Panel2.Height = bounds.Height;
+					Panel2.Height = Dim.Fill(HasBorder () ? 1 : 0);
 					break;
 
 				case Orientation.Vertical:
 					splitterLine.X = splitterDistance;
 					splitterLine.Y = 0;
 					splitterLine.Width = 1;
-					splitterLine.Height = bounds.Height;
+					splitterLine.Height = Dim.Fill ();
 					splitterLine.LineRune = Driver.VLine;
 
 					Panel1.Height = Dim.Fill();

+ 0 - 2
UICatalog/Scenarios/SplitContainerExample.cs

@@ -1,8 +1,6 @@
 using Terminal.Gui;
-using System;
 using Terminal.Gui.Graphs;
 using NStack;
-using System.Linq;
 
 namespace UICatalog.Scenarios {
 	[ScenarioMetadata (Name: "Split Container", Description: "Demonstrates the SplitContainer functionality")]

+ 150 - 0
UICatalog/Scenarios/SplitContainerNesting.cs

@@ -0,0 +1,150 @@
+using System;
+using System.ComponentModel;
+using Terminal.Gui;
+
+namespace UICatalog.Scenarios {
+	[ScenarioMetadata (Name: "Split Container Nesting", Description: "Nest SplitContainers")]
+	[ScenarioCategory ("Controls")]
+	[ScenarioCategory ("LineView")]
+	public class SplitContainerNesting : Scenario {
+
+		private View workArea;
+		private TextField textField;
+		private CheckBox cbHorizontal;
+		private CheckBox cbBorder;
+		private CheckBox cbTitles;
+
+		bool loaded = false;
+
+		/// <summary>
+		/// Setup the scenario.
+		/// </summary>
+		public override void Setup ()
+		{
+			// Scenario Windows.
+			Win.Title = this.GetName ();
+			Win.Y = 1;
+
+			var lblPanels = new Label ("Number Of Panels:");
+			textField = new TextField {
+				X = Pos.Right (lblPanels),
+				Width = 10,
+				Text = "2",
+			};
+
+			textField.TextChanged += (s) => SetupSplitContainer ();
+
+
+			cbHorizontal = new CheckBox ("Horizontal") {
+				X = Pos.Right (textField) +1
+			};
+			cbHorizontal.Toggled += (s) => SetupSplitContainer ();
+
+			cbBorder = new CheckBox ("Border") {
+				X = Pos.Right (cbHorizontal)+1
+			};
+			cbBorder.Toggled += (s) => SetupSplitContainer ();
+			
+			cbTitles = new CheckBox ("Titles") {
+				X = Pos.Right (cbBorder)+1
+			};
+			cbTitles.Toggled += (s) => SetupSplitContainer ();
+
+			workArea = new View {
+				X = 0,
+				Y = 1,
+				Width = Dim.Fill (),
+				Height = Dim.Fill (),
+			};
+
+			var menu = new MenuBar (new MenuBarItem [] {
+			new MenuBarItem ("_File", new MenuItem [] {
+				new MenuItem ("_Quit", "", () => Quit()),
+			}) });
+
+			Win.Add (lblPanels);
+			Win.Add (textField);
+			Win.Add (cbHorizontal);
+			Win.Add (cbBorder);
+			Win.Add (cbTitles);
+			Win.Add (workArea);
+
+			SetupSplitContainer ();
+
+			Application.Top.Add (menu);
+
+			Win.Loaded += () => loaded = true;
+		}
+
+		private void SetupSplitContainer ()
+		{
+			int numberOfPanels = GetNumberOfPanels ();
+
+			bool titles = cbTitles.Checked;
+			bool border = cbBorder.Checked;
+			bool startHorizontal = cbHorizontal.Checked;
+
+			workArea.RemoveAll ();
+
+			if (numberOfPanels <= 0) {
+				return;
+			}
+
+			var root = new SplitContainer {
+				Width = Dim.Fill (),
+				Height = Dim.Fill (),
+				Orientation = startHorizontal ?
+					Terminal.Gui.Graphs.Orientation.Horizontal :
+					Terminal.Gui.Graphs.Orientation.Vertical,
+			};
+			root.Panel1.Add (new TextView {
+				Width = Dim.Fill (),
+				Height = Dim.Fill (),
+				Text = new string ('1', 10000),
+				AllowsTab = false,
+			});
+			root.Panel1Title = titles ? "Panel 1" : string.Empty;
+
+			root.Panel2.Add (new TextView {
+				Width = Dim.Fill (),
+				Height = Dim.Fill (),
+				Text = new string ('2', 10000),
+				AllowsTab = false,
+			});
+			root.Panel2Title = titles ? "Panel 2" : string.Empty;
+
+			root.IntegratedBorder = border ? BorderStyle.Rounded : BorderStyle.None;
+
+
+			workArea.Add (root);
+
+			if (numberOfPanels == 1) {
+				root.Panel2.Visible = false;
+			}
+
+			if (numberOfPanels > 2) {
+
+				// TODO: Add more
+			}
+
+			if (loaded) {
+				workArea.LayoutSubviews ();
+			}
+		}
+
+		private int GetNumberOfPanels ()
+		{
+			if (int.TryParse (textField.Text.ToString (), out var panels) && panels >= 0) {
+
+				return panels;
+			} else {
+				return 0;
+			}
+		}
+
+		private void Quit ()
+		{
+			Application.RequestStop ();
+		}
+	}
+}