Prechádzať zdrojové kódy

Fixes #1855. Window and Frame content view without the margin frame. (#1857)

BDisp 3 rokov pred
rodič
commit
40b661d531

+ 58 - 45
Terminal.Gui/Core/Border.cs

@@ -165,7 +165,6 @@ namespace Terminal.Gui {
 			{
 			{
 				ColorScheme = Colors.TopLevel;
 				ColorScheme = Colors.TopLevel;
 				Text = title ?? "";
 				Text = title ?? "";
-				Frame = frame;
 				if (border == null) {
 				if (border == null) {
 					Border = new Border () {
 					Border = new Border () {
 						BorderStyle = BorderStyle.Single,
 						BorderStyle = BorderStyle.Single,
@@ -174,26 +173,30 @@ namespace Terminal.Gui {
 				} else {
 				} else {
 					Border = border;
 					Border = border;
 				}
 				}
+				AdjustContentView (frame);
 			}
 			}
 
 
 			void AdjustContentView (Rect frame)
 			void AdjustContentView (Rect frame)
 			{
 			{
 				var borderLength = Border.DrawMarginFrame ? 1 : 0;
 				var borderLength = Border.DrawMarginFrame ? 1 : 0;
 				var sumPadding = Border.GetSumThickness ();
 				var sumPadding = Border.GetSumThickness ();
+				var wp = new Point ();
 				var wb = new Size ();
 				var wb = new Size ();
 				if (frame == Rect.Empty) {
 				if (frame == Rect.Empty) {
+					wp.X = borderLength + sumPadding.Left;
+					wp.Y = borderLength + sumPadding.Top;
 					wb.Width = borderLength + sumPadding.Right;
 					wb.Width = borderLength + sumPadding.Right;
 					wb.Height = borderLength + sumPadding.Bottom;
 					wb.Height = borderLength + sumPadding.Bottom;
 					if (Border.Child == null) {
 					if (Border.Child == null) {
 						Border.Child = new ChildContentView (this) {
 						Border.Child = new ChildContentView (this) {
-							X = borderLength + sumPadding.Left,
-							Y = borderLength + sumPadding.Top,
+							X = wp.X,
+							Y = wp.Y,
 							Width = Dim.Fill (wb.Width),
 							Width = Dim.Fill (wb.Width),
 							Height = Dim.Fill (wb.Height)
 							Height = Dim.Fill (wb.Height)
 						};
 						};
 					} else {
 					} else {
-						Border.Child.X = borderLength + sumPadding.Left;
-						Border.Child.Y = borderLength + sumPadding.Top;
+						Border.Child.X = wp.X;
+						Border.Child.Y = wp.Y;
 						Border.Child.Width = Dim.Fill (wb.Width);
 						Border.Child.Width = Dim.Fill (wb.Width);
 						Border.Child.Height = Dim.Fill (wb.Height);
 						Border.Child.Height = Dim.Fill (wb.Height);
 					}
 					}
@@ -207,7 +210,8 @@ namespace Terminal.Gui {
 						Border.Child.Frame = cFrame;
 						Border.Child.Frame = cFrame;
 					}
 					}
 				}
 				}
-				base.Add (Border.Child);
+				if (Subviews?.Count == 0)
+					base.Add (Border.Child);
 				Border.ChildContainer = this;
 				Border.ChildContainer = this;
 			}
 			}
 
 
@@ -249,7 +253,7 @@ namespace Terminal.Gui {
 			{
 			{
 				if (!NeedDisplay.IsEmpty) {
 				if (!NeedDisplay.IsEmpty) {
 					Driver.SetAttribute (GetNormalColor ());
 					Driver.SetAttribute (GetNormalColor ());
-					Border.DrawContent ();
+					Clear ();
 				}
 				}
 				var savedClip = Border.Child.ClipToBounds ();
 				var savedClip = Border.Child.ClipToBounds ();
 				Border.Child.Redraw (Border.Child.Bounds);
 				Border.Child.Redraw (Border.Child.Bounds);
@@ -258,10 +262,13 @@ namespace Terminal.Gui {
 				ClearLayoutNeeded ();
 				ClearLayoutNeeded ();
 				ClearNeedsDisplay ();
 				ClearNeedsDisplay ();
 
 
-				if (Border.BorderStyle != BorderStyle.None) {
-					Driver.SetAttribute (GetNormalColor ());
-					Border.DrawTitle (this, this.Frame);
-				}
+				Driver.SetAttribute (GetNormalColor ());
+				Border.DrawContent (this, false);
+				if (HasFocus)
+					Driver.SetAttribute (ColorScheme.HotNormal);
+				if (Border.DrawMarginFrame)
+					Border.DrawTitle (this, Frame);
+				Driver.SetAttribute (GetNormalColor ());
 
 
 				// Checks if there are any SuperView view which intersect with this window.
 				// Checks if there are any SuperView view which intersect with this window.
 				if (SuperView != null) {
 				if (SuperView != null) {
@@ -541,24 +548,26 @@ namespace Terminal.Gui {
 			driver.SetAttribute (savedAttribute);
 			driver.SetAttribute (savedAttribute);
 
 
 			// Draw margin frame
 			// Draw margin frame
-			if (Parent?.Border != null) {
-				var sumPadding = GetSumThickness ();
-				borderRect = new Rect () {
-					X = scrRect.X + sumPadding.Left,
-					Y = scrRect.Y + sumPadding.Top,
-					Width = Math.Max (scrRect.Width - sumPadding.Right - sumPadding.Left, 0),
-					Height = Math.Max (scrRect.Height - sumPadding.Bottom - sumPadding.Top, 0)
-				};
-			} else {
-				borderRect = new Rect () {
-					X = borderRect.X + padding.Left,
-					Y = borderRect.Y + padding.Top,
-					Width = Math.Max (borderRect.Width - padding.Right - padding.Left, 0),
-					Height = Math.Max (borderRect.Height - padding.Bottom - padding.Top, 0)
-				};
-			}
-			if (borderRect.Width > 0 && borderRect.Height > 0) {
-				driver.DrawWindowFrame (borderRect, 1, 1, 1, 1, BorderStyle != BorderStyle.None, fill: true, this);
+			if (DrawMarginFrame) {
+				if (Parent?.Border != null) {
+					var sumPadding = GetSumThickness ();
+					borderRect = new Rect () {
+						X = scrRect.X + sumPadding.Left,
+						Y = scrRect.Y + sumPadding.Top,
+						Width = Math.Max (scrRect.Width - sumPadding.Right - sumPadding.Left, 0),
+						Height = Math.Max (scrRect.Height - sumPadding.Bottom - sumPadding.Top, 0)
+					};
+				} else {
+					borderRect = new Rect () {
+						X = borderRect.X + padding.Left,
+						Y = borderRect.Y + padding.Top,
+						Width = Math.Max (borderRect.Width - padding.Right - padding.Left, 0),
+						Height = Math.Max (borderRect.Height - padding.Bottom - padding.Top, 0)
+					};
+				}
+				if (borderRect.Width > 0 && borderRect.Height > 0) {
+					driver.DrawWindowFrame (borderRect, 1, 1, 1, 1, BorderStyle != BorderStyle.None, fill: true, this);
+				}
 			}
 			}
 		}
 		}
 
 
@@ -659,14 +668,16 @@ namespace Terminal.Gui {
 			driver.SetAttribute (savedAttribute);
 			driver.SetAttribute (savedAttribute);
 
 
 			// Draw the MarginFrame
 			// Draw the MarginFrame
-			var rect = new Rect () {
-				X = frame.X - drawMarginFrame,
-				Y = frame.Y - drawMarginFrame,
-				Width = frame.Width + (2 * drawMarginFrame),
-				Height = frame.Height + (2 * drawMarginFrame)
-			};
-			if (rect.Width > 0 && rect.Height > 0) {
-				driver.DrawWindowFrame (rect, 1, 1, 1, 1, BorderStyle != BorderStyle.None, fill, this);
+			if (DrawMarginFrame) {
+				var rect = new Rect () {
+					X = frame.X - drawMarginFrame,
+					Y = frame.Y - drawMarginFrame,
+					Width = frame.Width + (2 * drawMarginFrame),
+					Height = frame.Height + (2 * drawMarginFrame)
+				};
+				if (rect.Width > 0 && rect.Height > 0) {
+					driver.DrawWindowFrame (rect, 1, 1, 1, 1, BorderStyle != BorderStyle.None, fill, this);
+				}
 			}
 			}
 
 
 			if (Effect3D) {
 			if (Effect3D) {
@@ -811,14 +822,16 @@ namespace Terminal.Gui {
 			driver.SetAttribute (savedAttribute);
 			driver.SetAttribute (savedAttribute);
 
 
 			// Draw the MarginFrame
 			// Draw the MarginFrame
-			var rect = new Rect () {
-				X = frame.X + sumThickness.Left,
-				Y = frame.Y + sumThickness.Top,
-				Width = Math.Max (frame.Width - sumThickness.Right - sumThickness.Left, 0),
-				Height = Math.Max (frame.Height - sumThickness.Bottom - sumThickness.Top, 0)
-			};
-			if (rect.Width > 0 && rect.Height > 0) {
-				driver.DrawWindowFrame (rect, 1, 1, 1, 1, BorderStyle != BorderStyle.None, fill, this);
+			if (DrawMarginFrame) {
+				var rect = new Rect () {
+					X = frame.X + sumThickness.Left,
+					Y = frame.Y + sumThickness.Top,
+					Width = Math.Max (frame.Width - sumThickness.Right - sumThickness.Left, 0),
+					Height = Math.Max (frame.Height - sumThickness.Bottom - sumThickness.Top, 0)
+				};
+				if (rect.Width > 0 && rect.Height > 0) {
+					driver.DrawWindowFrame (rect, 1, 1, 1, 1, BorderStyle != BorderStyle.None, fill, this);
+				}
 			}
 			}
 
 
 			if (Effect3D) {
 			if (Effect3D) {

+ 18 - 14
Terminal.Gui/Core/Window.cs

@@ -75,7 +75,6 @@ namespace Terminal.Gui {
 			AdjustContentView (frame);
 			AdjustContentView (frame);
 		}
 		}
 
 
-
 		/// <summary>
 		/// <summary>
 		/// ContentView is an internal implementation detail of Window. It is used to host Views added with <see cref="Add(View)"/>. 
 		/// ContentView is an internal implementation detail of Window. It is used to host Views added with <see cref="Add(View)"/>. 
 		/// Its ONLY reason for being is to provide a simple way for Window to expose to those SubViews that the Window's Bounds 
 		/// Its ONLY reason for being is to provide a simple way for Window to expose to those SubViews that the Window's Bounds 
@@ -186,26 +185,30 @@ namespace Terminal.Gui {
 			} else {
 			} else {
 				Border = border;
 				Border = border;
 			}
 			}
+			AdjustContentView (frame);
 		}
 		}
 
 
 		void AdjustContentView (Rect frame)
 		void AdjustContentView (Rect frame)
 		{
 		{
 			var borderLength = Border.DrawMarginFrame ? 1 : 0;
 			var borderLength = Border.DrawMarginFrame ? 1 : 0;
 			var sumPadding = Border.GetSumThickness ();
 			var sumPadding = Border.GetSumThickness ();
+			var wp = new Point ();
 			var wb = new Size ();
 			var wb = new Size ();
 			if (frame == Rect.Empty) {
 			if (frame == Rect.Empty) {
+				wp.X = borderLength + sumPadding.Left;
+				wp.Y = borderLength + sumPadding.Top;
 				wb.Width = borderLength + sumPadding.Right;
 				wb.Width = borderLength + sumPadding.Right;
 				wb.Height = borderLength + sumPadding.Bottom;
 				wb.Height = borderLength + sumPadding.Bottom;
 				if (contentView == null) {
 				if (contentView == null) {
 					contentView = new ContentView (this) {
 					contentView = new ContentView (this) {
-						X = borderLength + sumPadding.Left,
-						Y = borderLength + sumPadding.Top,
+						X = wp.X,
+						Y = wp.Y,
 						Width = Dim.Fill (wb.Width),
 						Width = Dim.Fill (wb.Width),
 						Height = Dim.Fill (wb.Height)
 						Height = Dim.Fill (wb.Height)
 					};
 					};
 				} else {
 				} else {
-					contentView.X = borderLength + sumPadding.Left;
-					contentView.Y = borderLength + sumPadding.Top;
+					contentView.X = wp.X;
+					contentView.Y = wp.Y;
 					contentView.Width = Dim.Fill (wb.Width);
 					contentView.Width = Dim.Fill (wb.Width);
 					contentView.Height = Dim.Fill (wb.Height);
 					contentView.Height = Dim.Fill (wb.Height);
 				}
 				}
@@ -219,7 +222,8 @@ namespace Terminal.Gui {
 					contentView.Frame = cFrame;
 					contentView.Frame = cFrame;
 				}
 				}
 			}
 			}
-			base.Add (contentView);
+			if (Subviews?.Count == 0)
+				base.Add (contentView);
 			Border.Child = contentView;
 			Border.Child = contentView;
 		}
 		}
 
 
@@ -289,15 +293,15 @@ namespace Terminal.Gui {
 
 
 			ClearLayoutNeeded ();
 			ClearLayoutNeeded ();
 			ClearNeedsDisplay ();
 			ClearNeedsDisplay ();
-			if (Border.BorderStyle != BorderStyle.None) {
-				Driver.SetAttribute (GetNormalColor ());
-				//Driver.DrawWindowFrame (scrRect, padding.Left + borderLength, padding.Top + borderLength, padding.Right + borderLength, padding.Bottom + borderLength,
-				//	Border.BorderStyle != BorderStyle.None, fill: true, Border.BorderStyle);
-				Border.DrawContent (this, false);
-				if (HasFocus)
-					Driver.SetAttribute (ColorScheme.HotNormal);
+
+			Driver.SetAttribute (GetNormalColor ());
+			//Driver.DrawWindowFrame (scrRect, padding.Left + borderLength, padding.Top + borderLength, padding.Right + borderLength, padding.Bottom + borderLength,
+			//	Border.BorderStyle != BorderStyle.None, fill: true, Border.BorderStyle);
+			Border.DrawContent (this, false);
+			if (HasFocus)
+				Driver.SetAttribute (ColorScheme.HotNormal);
+			if (Border.DrawMarginFrame)
 				Driver.DrawWindowTitle (scrRect, Title, padding.Left, padding.Top, padding.Right, padding.Bottom);
 				Driver.DrawWindowTitle (scrRect, Title, padding.Left, padding.Top, padding.Right, padding.Bottom);
-			}
 			Driver.SetAttribute (GetNormalColor ());
 			Driver.SetAttribute (GetNormalColor ());
 
 
 			// Checks if there are any SuperView view which intersect with this window.
 			// Checks if there are any SuperView view which intersect with this window.

+ 14 - 12
Terminal.Gui/Views/FrameView.cs

@@ -124,20 +124,23 @@ namespace Terminal.Gui {
 		{
 		{
 			var borderLength = Border.DrawMarginFrame ? 1 : 0;
 			var borderLength = Border.DrawMarginFrame ? 1 : 0;
 			var sumPadding = Border.GetSumThickness ();
 			var sumPadding = Border.GetSumThickness ();
+			var wp = new Point ();
 			var wb = new Size ();
 			var wb = new Size ();
 			if (frame == Rect.Empty) {
 			if (frame == Rect.Empty) {
+				wp.X = borderLength + sumPadding.Left;
+				wp.Y = borderLength + sumPadding.Top;
 				wb.Width = borderLength + sumPadding.Right;
 				wb.Width = borderLength + sumPadding.Right;
 				wb.Height = borderLength + sumPadding.Bottom;
 				wb.Height = borderLength + sumPadding.Bottom;
 				if (contentView == null) {
 				if (contentView == null) {
 					contentView = new ContentView () {
 					contentView = new ContentView () {
-						X = borderLength + sumPadding.Left,
-						Y = borderLength + sumPadding.Top,
+						X = wp.X,
+						Y = wp.Y,
 						Width = Dim.Fill (wb.Width),
 						Width = Dim.Fill (wb.Width),
 						Height = Dim.Fill (wb.Height)
 						Height = Dim.Fill (wb.Height)
 					};
 					};
 				} else {
 				} else {
-					contentView.X = borderLength + sumPadding.Left;
-					contentView.Y = borderLength + sumPadding.Top;
+					contentView.X = wp.X;
+					contentView.Y = wp.Y;
 					contentView.Width = Dim.Fill (wb.Width);
 					contentView.Width = Dim.Fill (wb.Width);
 					contentView.Height = Dim.Fill (wb.Height);
 					contentView.Height = Dim.Fill (wb.Height);
 				}
 				}
@@ -225,15 +228,14 @@ namespace Terminal.Gui {
 			Driver.Clip = savedClip;
 			Driver.Clip = savedClip;
 
 
 			ClearNeedsDisplay ();
 			ClearNeedsDisplay ();
-			if (Border.BorderStyle != BorderStyle.None) {
-				Driver.SetAttribute (GetNormalColor ());
-				//Driver.DrawWindowFrame (scrRect, padding + 1, padding + 1, padding + 1, padding + 1, border: true, fill: false);
-				Border.DrawContent (this, false);
-				if (HasFocus)
-					Driver.SetAttribute (ColorScheme.HotNormal);
-				//Driver.DrawWindowTitle (scrRect, Title, padding, padding, padding, padding);
+
+			Driver.SetAttribute (GetNormalColor ());
+			//Driver.DrawWindowFrame (scrRect, padding + 1, padding + 1, padding + 1, padding + 1, border: true, fill: false);
+			Border.DrawContent (this, false);
+			if (HasFocus)
+				Driver.SetAttribute (ColorScheme.HotNormal);
+			if (Border.DrawMarginFrame)
 				Driver.DrawWindowTitle (scrRect, Title, padding.Left, padding.Top, padding.Right, padding.Bottom);
 				Driver.DrawWindowTitle (scrRect, Title, padding.Left, padding.Top, padding.Right, padding.Bottom);
-			}
 			Driver.SetAttribute (GetNormalColor ());
 			Driver.SetAttribute (GetNormalColor ());
 		}
 		}