Browse Source

Working on layout

Thomas 2 years ago
parent
commit
f3d6d92629

+ 70 - 40
Terminal.Gui/Views/SplitContainer.cs

@@ -12,6 +12,16 @@ namespace Terminal.Gui {
 
 
 		private SplitContainerLineView splitterLine;
 		private SplitContainerLineView splitterLine;
 		SplitContainer parentSplitPanel;
 		SplitContainer parentSplitPanel;
+		
+		/// TODO: Might be able to make Border virtual and override here
+		/// To make this more API friendly
+
+		/// <summary>
+		/// Use this field instead of Border to create an integrated
+		/// Border in which lines connect with subpanels and splitters
+		/// seamlessly
+		/// </summary>
+		public BorderStyle IntegratedBorder {get;set;}
 
 
 		/// <summary>
 		/// <summary>
 		/// The <see cref="View"/> showing in the left hand pane of a
 		/// The <see cref="View"/> showing in the left hand pane of a
@@ -24,7 +34,7 @@ namespace Terminal.Gui {
 
 
 		
 		
 		public int Panel1MinSize { get; set; }
 		public int Panel1MinSize { get; set; }
-		public ustring Panel1Title { get; set; }
+		public ustring Panel1Title { get; set; } = string.Empty;
 
 
 		/// <summary>
 		/// <summary>
 		/// The <see cref="View"/> showing in the right hand pane of a
 		/// The <see cref="View"/> showing in the right hand pane of a
@@ -36,7 +46,7 @@ namespace Terminal.Gui {
 		public View Panel2 { get; private set; }
 		public View Panel2 { get; private set; }
 
 
 		public int Panel2MinSize { get; set; }
 		public int Panel2MinSize { get; set; }
-		public ustring Panel2Title { get; set; }
+		public ustring Panel2Title { get; set; } = string.Empty;
 
 
 		private Pos splitterDistance = Pos.Percent (50);
 		private Pos splitterDistance = Pos.Percent (50);
 		private Orientation orientation = Orientation.Vertical;
 		private Orientation orientation = Orientation.Vertical;
@@ -83,8 +93,33 @@ namespace Terminal.Gui {
 
 
 		public override void LayoutSubviews ()
 		public override void LayoutSubviews ()
 		{
 		{
+
+			splitterLine.moveRuneRenderLocation = null;
+
 			if(this.IsRootSplitContainer()) {
 			if(this.IsRootSplitContainer()) {
-				Setup (this, Bounds);
+
+				var contentArea = Bounds;
+
+				if(HasBorder())
+				{
+					// TODO: Bound with Max/Min
+					contentArea = new Rect(
+						contentArea.X + 1,
+						contentArea.Y + 1,
+						contentArea.Width - 2,
+						contentArea.Height - 2);
+				}
+				else if(HasAnyTitles())
+				{
+					// TODO: Bound with Max/Min
+					contentArea = new Rect(
+						contentArea.X,
+						contentArea.Y + 1,
+						contentArea.Width,
+						contentArea.Height - 1);
+				}
+
+				Setup (this, contentArea);
 			}			
 			}			
 
 
 			base.LayoutSubviews ();
 			base.LayoutSubviews ();
@@ -126,35 +161,35 @@ namespace Terminal.Gui {
 			Clear ();
 			Clear ();
 			base.Redraw (bounds);
 			base.Redraw (bounds);
 
 
-			// Draw Splitter over Border (to get Ts)
-			if (splitterLine.Visible) {
-				splitterLine.Redraw (bounds);
-			}
+			// TODO : Gather ALL splitters
+
+			// TODO : Draw borders and splitter lines into LineCanvas
 
 
-			// TODO: 
 			// Draw Titles over Border
 			// Draw Titles over Border
 			var screen = ViewToScreen (bounds);
 			var screen = ViewToScreen (bounds);
 			if (Panel1.Visible && Panel1Title.Length > 0) {
 			if (Panel1.Visible && Panel1Title.Length > 0) {
 				Driver.SetAttribute (Panel1.HasFocus ? ColorScheme.HotNormal : ColorScheme.Normal);
 				Driver.SetAttribute (Panel1.HasFocus ? ColorScheme.HotNormal : ColorScheme.Normal);
-				Driver.DrawWindowTitle (new Rect (screen.X, screen.Y, Panel1.Frame.Width, 1), Panel1Title, 0, 0, 0, 0);
+				Driver.DrawWindowTitle (new Rect (screen.X, screen.Y, Panel1.Frame.Width, 0), Panel1Title, 0, 0, 0, 0);
 			}
 			}
 
 
 			if (splitterLine.Visible) {
 			if (splitterLine.Visible) {
 				screen = ViewToScreen (splitterLine.Frame);
 				screen = ViewToScreen (splitterLine.Frame);
 			} else {
 			} else {
+				
 				screen.X--;
 				screen.X--;
-				screen.Y--;
+				//screen.Y--;
 			}
 			}
+
 			if (Orientation == Orientation.Horizontal) {
 			if (Orientation == Orientation.Horizontal) {
 				if (Panel2.Visible && Panel2Title?.Length > 0) {
 				if (Panel2.Visible && Panel2Title?.Length > 0) {
 
 
 					Driver.SetAttribute (Panel2.HasFocus ? ColorScheme.HotNormal : ColorScheme.Normal);
 					Driver.SetAttribute (Panel2.HasFocus ? ColorScheme.HotNormal : ColorScheme.Normal);
-					Driver.DrawWindowTitle (new Rect (screen.X + 1, screen.Y + 1, Panel2.Bounds.Width, 1), Panel2Title, 0, 0, 0, 0);
+					Driver.DrawWindowTitle (new Rect (screen.X + 1, screen.Y, Panel2.Bounds.Width, 1), Panel2Title, 0, 0, 0, 0);
 				}
 				}
 			} else {
 			} else {
 				if (Panel2.Visible && Panel2Title?.Length > 0) {
 				if (Panel2.Visible && Panel2Title?.Length > 0) {
 					Driver.SetAttribute (Panel2.HasFocus ? ColorScheme.HotNormal : ColorScheme.Normal);
 					Driver.SetAttribute (Panel2.HasFocus ? ColorScheme.HotNormal : ColorScheme.Normal);
-					Driver.DrawWindowTitle (new Rect (screen.X + 1, screen.Y + 1, Panel2.Bounds.Width, 1), Panel2Title, 0, 0, 0, 0);
+					Driver.DrawWindowTitle (new Rect (screen.X + 1, screen.Y, Panel2.Bounds.Width, 1), Panel2Title, 0, 0, 0, 0);
 				}
 				}
 			}
 			}
 		}
 		}
@@ -186,50 +221,51 @@ namespace Terminal.Gui {
 
 
 				splitterLine.Visible = false;
 				splitterLine.Visible = false;
 
 
-				toFullSize.X = 0;
-				toFullSize.Y = 0;
-				toFullSize.Width = Dim.Fill ();
-				toFullSize.Height = Dim.Fill ();
+				toFullSize.X = bounds.X;
+				toFullSize.Y = bounds.Y;
+				toFullSize.Width = bounds.Width;
+				toFullSize.Height = bounds.Height;
 			} else {
 			} else {
 				splitterLine.Visible = true;
 				splitterLine.Visible = true;
 
 
 				splitterDistance = BoundByMinimumSizes (splitterDistance);
 				splitterDistance = BoundByMinimumSizes (splitterDistance);
 
 
-				Panel1.X = 0;
-				Panel1.Y = 0;
-
-				Panel2.Width = Dim.Fill ();
-				Panel2.Height = Dim.Fill ();
+				Panel1.X = bounds.X;
+				Panel1.Y = bounds.Y;
 
 
 				switch (Orientation) {
 				switch (Orientation) {
 				case Orientation.Horizontal:
 				case Orientation.Horizontal:
 					splitterLine.X = 0;
 					splitterLine.X = 0;
 					splitterLine.Y = splitterDistance;
 					splitterLine.Y = splitterDistance;
-					splitterLine.Width = Dim.Fill () + 1;
+					splitterLine.Width = Dim.Fill ();
 					splitterLine.Height = 1;
 					splitterLine.Height = 1;
 					splitterLine.LineRune = Driver.HLine;
 					splitterLine.LineRune = Driver.HLine;
 
 
-					Panel1.Width = Dim.Fill ();
+					Panel1.Width = Dim.Fill (HasBorder()? 1:0);
 					Panel1.Height = new Dim.DimFunc (() =>
 					Panel1.Height = new Dim.DimFunc (() =>
 					splitterDistance.Anchor (Bounds.Height));
 					splitterDistance.Anchor (Bounds.Height));
 
 
 					Panel2.Y = Pos.Bottom (splitterLine);
 					Panel2.Y = Pos.Bottom (splitterLine);
-					Panel2.X = 0;
+					Panel2.X = bounds.X;
+					Panel2.Width = bounds.Width;
+					Panel2.Height = bounds.Height;
 					break;
 					break;
 
 
 				case Orientation.Vertical:
 				case Orientation.Vertical:
 					splitterLine.X = splitterDistance;
 					splitterLine.X = splitterDistance;
 					splitterLine.Y = 0;
 					splitterLine.Y = 0;
 					splitterLine.Width = 1;
 					splitterLine.Width = 1;
-					splitterLine.Height = Dim.Fill () + 1;
+					splitterLine.Height = bounds.Height;
 					splitterLine.LineRune = Driver.VLine;
 					splitterLine.LineRune = Driver.VLine;
 
 
-					Panel1.Height = Dim.Fill ();
+					Panel1.Height = Dim.Fill();
 					Panel1.Width = new Dim.DimFunc (() =>
 					Panel1.Width = new Dim.DimFunc (() =>
 					splitterDistance.Anchor (Bounds.Width));
 					splitterDistance.Anchor (Bounds.Width));
 
 
 					Panel2.X = Pos.Right (splitterLine);
 					Panel2.X = Pos.Right (splitterLine);
-					Panel2.Y = 0;
+					Panel2.Y = bounds.Y;
+					Panel2.Height = bounds.Height;
+					Panel2.Width = Dim.Fill(HasBorder()? 1:0);
 					break;
 					break;
 
 
 				default: throw new ArgumentOutOfRangeException (nameof (orientation));
 				default: throw new ArgumentOutOfRangeException (nameof (orientation));
@@ -333,7 +369,7 @@ namespace Terminal.Gui {
 
 
 			Point? dragPosition;
 			Point? dragPosition;
 			Pos dragOrignalPos;
 			Pos dragOrignalPos;
-			Point? moveRuneRenderLocation;
+			public Point? moveRuneRenderLocation;
 
 
 			public SplitContainerLineView (SplitContainer parent)
 			public SplitContainerLineView (SplitContainer parent)
 			{
 			{
@@ -362,17 +398,6 @@ namespace Terminal.Gui {
 				AddKeyBinding (Key.CursorLeft, Command.Left);
 				AddKeyBinding (Key.CursorLeft, Command.Left);
 				AddKeyBinding (Key.CursorUp, Command.LineUp);
 				AddKeyBinding (Key.CursorUp, Command.LineUp);
 				AddKeyBinding (Key.CursorDown, Command.LineDown);
 				AddKeyBinding (Key.CursorDown, Command.LineDown);
-
-				LayoutStarted += (e) => {
-					moveRuneRenderLocation = null;
-					if (Orientation == Orientation.Horizontal) {
-						StartingAnchor = parent.HasBorder () ? Driver.LeftTee : (Rune?)null;
-						EndingAnchor = parent.HasBorder () ? Driver.RightTee : (Rune?)null;
-					} else {
-						StartingAnchor = parent.HasBorder () ? Driver.TopTee : (Rune?)null;
-						EndingAnchor = parent.HasBorder () ? Driver.BottomTee : (Rune?)null;
-					}
-				};
 			}
 			}
 
 
 			public override bool ProcessKey (KeyEvent kb)
 			public override bool ProcessKey (KeyEvent kb)
@@ -557,7 +582,12 @@ namespace Terminal.Gui {
 
 
 		private bool HasBorder ()
 		private bool HasBorder ()
 		{
 		{
-			return Border != null && Border.BorderStyle != BorderStyle.None;
+			return IntegratedBorder != BorderStyle.None;
+		}
+		private bool HasAnyTitles()
+		{
+			return Panel1Title.Length > 0 || Panel2Title.Length > 0;
+
 		}
 		}
 	}
 	}
 
 

+ 5 - 8
UICatalog/Scenarios/SplitContainerExample.cs

@@ -67,8 +67,7 @@ namespace UICatalog.Scenarios {
 				WordWrap = true,
 				WordWrap = true,
 			 });
 			 });
 
 
-			nestedSplitContainer.Border.BorderStyle = BorderStyle.None;
-			nestedSplitContainer.Border.DrawMarginFrame = false;
+			nestedSplitContainer.IntegratedBorder = BorderStyle.None;
 			
 			
 			nestedSplitContainer.Panel2.Add (lbl2 = new Label ("Type Here Too:") { Y = 0 });
 			nestedSplitContainer.Panel2.Add (lbl2 = new Label ("Type Here Too:") { Y = 0 });
 			nestedSplitContainer.Panel2.Add (new TextField () { Width = Dim.Fill (), Y = 0, X = Pos.Right (lbl2) + 1 });
 			nestedSplitContainer.Panel2.Add (new TextField () { Width = Dim.Fill (), Y = 0, X = Pos.Right (lbl2) + 1 });
@@ -89,12 +88,12 @@ namespace UICatalog.Scenarios {
 				},
 				},
 				miSplitContainer1Border = new MenuItem ("_Outer Panel Border", "", () => ToggleBorder(miSplitContainer1Border, splitContainer))
 				miSplitContainer1Border = new MenuItem ("_Outer Panel Border", "", () => ToggleBorder(miSplitContainer1Border, splitContainer))
 				{
 				{
-					Checked = splitContainer.Border.BorderStyle == BorderStyle.Single,
+					Checked = splitContainer.IntegratedBorder == BorderStyle.Single,
 					CheckType = MenuItemCheckStyle.Checked
 					CheckType = MenuItemCheckStyle.Checked
 				},
 				},
 				minestedSplitContainerBorder = new MenuItem ("_Inner Panel Border", "", () => ToggleBorder(minestedSplitContainerBorder,nestedSplitContainer))
 				minestedSplitContainerBorder = new MenuItem ("_Inner Panel Border", "", () => ToggleBorder(minestedSplitContainerBorder,nestedSplitContainer))
 				{
 				{
-					Checked = nestedSplitContainer.Border.BorderStyle == BorderStyle.Single,
+					Checked = nestedSplitContainer.IntegratedBorder == BorderStyle.Single,
 					CheckType = MenuItemCheckStyle.Checked
 					CheckType = MenuItemCheckStyle.Checked
 				},
 				},
 				new MenuBarItem ("_Show", new MenuItem [] {
 				new MenuBarItem ("_Show", new MenuItem [] {
@@ -159,11 +158,9 @@ namespace UICatalog.Scenarios {
 			menuItem.Checked = !menuItem.Checked;
 			menuItem.Checked = !menuItem.Checked;
 			
 			
 			if(menuItem.Checked) {
 			if(menuItem.Checked) {
-				splitContainer.Border.BorderStyle = BorderStyle.Single;
-				splitContainer.Border.DrawMarginFrame = true;
+				splitContainer.IntegratedBorder = BorderStyle.Single;
 			} else {
 			} else {
-				splitContainer.Border.BorderStyle = BorderStyle.None;
-				splitContainer.Border.DrawMarginFrame = false;
+				splitContainer.IntegratedBorder = BorderStyle.None;
 			}
 			}
 		}
 		}
 
 

+ 2 - 1
UICatalog/UICatalog.cs

@@ -214,7 +214,8 @@ namespace UICatalog {
 					Height = Dim.Fill (1),
 					Height = Dim.Fill (1),
 					CanFocus = true,
 					CanFocus = true,
 					Shortcut = Key.CtrlMask | Key.C,
 					Shortcut = Key.CtrlMask | Key.C,
-					SplitterDistance = 25
+					SplitterDistance = 25,
+					IntegratedBorder = BorderStyle.Rounded,
 				};
 				};
 				ContentPane.ShortcutAction = () => ContentPane.SetFocus ();
 				ContentPane.ShortcutAction = () => ContentPane.SetFocus ();