Browse Source

Merge branch 'develop' of tig:gui-cs/Terminal.Gui into develop

Tig Kindel 3 years ago
parent
commit
9697f9d4e1

+ 1 - 1
Terminal.Gui/ConsoleDrivers/WindowsDriver.cs

@@ -1125,7 +1125,7 @@ namespace Terminal.Gui {
 			} else if (mouseEvent.EventFlags == WindowsConsole.EventFlags.MouseMoved) {
 				if (mouseEvent.MousePosition.X != pointMove.X || mouseEvent.MousePosition.Y != pointMove.Y) {
 					mouseFlag = MouseFlags.ReportMousePosition;
-					pointMove = new Point ();
+					pointMove = new Point (mouseEvent.MousePosition.X, mouseEvent.MousePosition.Y);
 				} else {
 					mouseFlag = 0;
 				}

+ 86 - 17
Terminal.Gui/Core/Border.cs

@@ -1,4 +1,5 @@
-using System;
+using NStack;
+using System;
 
 namespace Terminal.Gui {
 	/// <summary>
@@ -138,7 +139,7 @@ namespace Terminal.Gui {
 			/// <summary>
 			/// Initializes with default null values.
 			/// </summary>
-			public ToplevelContainer () : this (null, null) { }
+			public ToplevelContainer () : this (null, string.Empty) { }
 
 			/// <summary>
 			/// Initializes a <see cref="ToplevelContainer"/> with a <see cref="LayoutStyle.Computed"/>
@@ -147,7 +148,7 @@ namespace Terminal.Gui {
 			/// <param name="title">The title.</param>
 			public ToplevelContainer (Border border, string title = null)
 			{
-				Initialize (Rect.Empty, border, title);
+				Initialize (Rect.Empty, border, title ?? string.Empty);
 			}
 
 			/// <summary>
@@ -158,17 +159,17 @@ namespace Terminal.Gui {
 			/// <param name="title">The title.</param>
 			public ToplevelContainer (Rect frame, Border border, string title = null) : base (frame)
 			{
-				Initialize (frame, border, title);
+				Initialize (frame, border, title ?? string.Empty);
 			}
 
-			private void Initialize (Rect frame, Border border, string title = null)
+			private void Initialize (Rect frame, Border border, string title)
 			{
 				ColorScheme = Colors.TopLevel;
-				Text = title ?? "";
 				if (border == null) {
 					Border = new Border () {
 						BorderStyle = BorderStyle.Single,
-						BorderBrush = ColorScheme.Normal.Background
+						BorderBrush = ColorScheme.Normal.Background,
+						Title = (ustring)title
 					};
 				} else {
 					Border = border;
@@ -266,8 +267,12 @@ namespace Terminal.Gui {
 				Border.DrawContent (this, false);
 				if (HasFocus)
 					Driver.SetAttribute (ColorScheme.HotNormal);
-				if (Border.DrawMarginFrame)
-					Border.DrawTitle (this, Frame);
+				if (Border.DrawMarginFrame) {
+					if (!ustring.IsNullOrEmpty (Border.Title))
+						Border.DrawTitle (this);
+					else
+						Border.DrawTitle (this, Frame);
+				}
 				Driver.SetAttribute (GetNormalColor ());
 
 				// Checks if there are any SuperView view which intersect with this window.
@@ -306,16 +311,20 @@ namespace Terminal.Gui {
 		}
 
 		/// <summary>
-		/// Event to be invoked when any border property change.
+		/// Invoked when any property of Border changes (except <see cref="Child"/>).
 		/// </summary>
 		public event Action<Border> BorderChanged;
 
 		private BorderStyle borderStyle;
 		private bool drawMarginFrame;
 		private Thickness borderThickness;
+		private Color borderBrush;
+		private Color background;
 		private Thickness padding;
 		private bool effect3D;
 		private Point effect3DOffset = new Point (1, 1);
+		private Attribute? effect3DBrush;
+		private ustring title = ustring.Empty;
 
 		/// <summary>
 		/// Specifies the <see cref="Gui.BorderStyle"/> for a view.
@@ -363,12 +372,24 @@ namespace Terminal.Gui {
 		/// <summary>
 		/// Gets or sets the <see cref="Color"/> that draws the outer border color.
 		/// </summary>
-		public Color BorderBrush { get; set; }
+		public Color BorderBrush {
+			get => borderBrush;
+			set {
+				borderBrush = value;
+				OnBorderChanged ();
+			}
+		}
 
 		/// <summary>
 		/// Gets or sets the <see cref="Color"/> that fills the area between the bounds of a <see cref="Border"/>.
 		/// </summary>
-		public Color Background { get; set; }
+		public Color Background {
+			get => background;
+			set {
+				background = value;
+				OnBorderChanged ();
+			}
+		}
 
 		/// <summary>
 		/// Gets or sets a <see cref="Thickness"/> value that describes the amount of space between a
@@ -448,7 +469,24 @@ namespace Terminal.Gui {
 		/// <summary>
 		/// Gets or sets the color for the <see cref="Border"/>
 		/// </summary>
-		public Attribute? Effect3DBrush { get; set; }
+		public Attribute? Effect3DBrush {
+			get => effect3DBrush;
+			set {
+				effect3DBrush = value;
+				OnBorderChanged ();
+			}
+		}
+
+		/// <summary>
+		/// The title to be displayed for this view.
+		/// </summary>
+		public ustring Title {
+			get => title;
+			set {
+				title = value;
+				OnBorderChanged ();
+			}
+		}
 
 		/// <summary>
 		/// Calculate the sum of the <see cref="Padding"/> and the <see cref="BorderThickness"/>
@@ -677,6 +715,7 @@ namespace Terminal.Gui {
 				};
 				if (rect.Width > 0 && rect.Height > 0) {
 					driver.DrawWindowFrame (rect, 1, 1, 1, 1, BorderStyle != BorderStyle.None, fill, this);
+					DrawTitle (Child);
 				}
 			}
 
@@ -831,6 +870,7 @@ namespace Terminal.Gui {
 				};
 				if (rect.Width > 0 && rect.Height > 0) {
 					driver.DrawWindowFrame (rect, 1, 1, 1, 1, BorderStyle != BorderStyle.None, fill, this);
+					DrawTitle (Parent);
 				}
 			}
 
@@ -900,18 +940,47 @@ namespace Terminal.Gui {
 		}
 
 		/// <summary>
-		/// Drawn the view text from a <see cref="View"/>.
+		/// Draws the view <see cref="Title"/> to the screen.
 		/// </summary>
+		/// <param name="view">The view.</param>
+		public void DrawTitle (View view)
+		{
+			var driver = Application.Driver;
+			if (DrawMarginFrame) {
+				driver.SetAttribute (Child.GetNormalColor ());
+				if (Child.HasFocus)
+					driver.SetAttribute (Child.ColorScheme.HotNormal);
+				var padding = view.Border.GetSumThickness ();
+				Rect scrRect;
+				if (view == Child) {
+					scrRect = view.ViewToScreen (new Rect (0, 0, view.Frame.Width + 2, view.Frame.Height + 2));
+					scrRect = new Rect (scrRect.X - 1, scrRect.Y - 1, scrRect.Width, scrRect.Height);
+					driver.DrawWindowTitle (scrRect, Title, 0, 0, 0, 0);
+				} else {
+					scrRect = view.ViewToScreen (new Rect (0, 0, view.Frame.Width, view.Frame.Height));
+					driver.DrawWindowTitle (scrRect, Title,
+						padding.Left, padding.Top, padding.Right, padding.Bottom);
+				}
+			}
+			driver.SetAttribute (Child.GetNormalColor ());
+		}
+
+		/// <summary>
+		/// Draws the <see cref="View.Text"/> to the screen.
+		/// </summary>
+		/// <param name="view">The view.</param>
+		/// <param name="rect">The frame.</param>
 		public void DrawTitle (View view, Rect rect)
 		{
 			var driver = Application.Driver;
-			if (BorderStyle != BorderStyle.None) {
+			if (DrawMarginFrame) {
 				driver.SetAttribute (view.GetNormalColor ());
 				if (view.HasFocus) {
 					driver.SetAttribute (view.ColorScheme.HotNormal);
 				}
-				var padding = GetSumThickness ();
-				driver.DrawWindowTitle (rect, view.Text,
+				var padding = Parent.Border.GetSumThickness ();
+				var scrRect = Parent.ViewToScreen (new Rect (0, 0, rect.Width, rect.Height));
+				driver.DrawWindowTitle (scrRect, view.Text,
 					padding.Left, padding.Top, padding.Right, padding.Bottom);
 			}
 			driver.SetAttribute (view.GetNormalColor ());

+ 1 - 0
Terminal.Gui/Views/PanelView.cs

@@ -236,6 +236,7 @@ namespace Terminal.Gui {
 		{
 			if (!NeedDisplay.IsEmpty) {
 				Driver.SetAttribute (Child.GetNormalColor ());
+				Clear ();
 				Child.Border.DrawContent (Border.Child);
 			}
 			var savedClip = childContentView.ClipToBounds ();

+ 1 - 1
Terminal.Gui/Windows/MessageBox.cs

@@ -242,7 +242,7 @@ namespace Terminal.Gui {
 			const int defaultWidth = 50;
 			int textWidth = TextFormatter.MaxWidth (message, width == 0 ? defaultWidth : width);
 			int textHeight = TextFormatter.MaxLines (message, textWidth); // message.Count (ustring.Make ('\n')) + 1;
-			int msgboxHeight = Math.Max (1, textHeight) + 3; // textHeight + (top + top padding + buttons + bottom)
+			int msgboxHeight = Math.Max (1, textHeight) + 4; // textHeight + (top + top padding + buttons + bottom)
 
 			// Create button array for Dialog
 			int count = 0;

+ 3 - 1
Terminal.Gui/Windows/Wizard.cs

@@ -204,7 +204,9 @@ namespace Terminal.Gui {
 				base.Add (contentView);
 
 				helpTextView.ColorScheme = new ColorScheme () {  
-					Normal = new Attribute(Color.Gray, Color.DarkGray)
+					Normal = new Attribute(Color.Gray, Color.DarkGray),
+					Focus = new Attribute(Color.DarkGray, Color.Gray),
+					HotFocus = new Attribute(Color.White, Color.DarkGray)
 				};
 				helpTextView.ReadOnly = true;
 				helpTextView.WordWrap = true;

+ 5 - 2
UICatalog/Scenarios/Borders.cs

@@ -30,8 +30,10 @@ namespace UICatalog.Scenarios {
 					BorderBrush = borderBrush,
 					Padding = padding,
 					Background = background,
-					Effect3D = effect3D
+					Effect3D = effect3D,
+					Title = "Panel"
 				},
+				ColorScheme = Colors.TopLevel
 			};
 			smartPanel.Add (new Label () { // Or smartPanel.Child = 
 				X = 0,
@@ -79,7 +81,8 @@ namespace UICatalog.Scenarios {
 					BorderBrush = borderBrush,
 					Padding = padding,
 					Background = background,
-					Effect3D = effect3D
+					Effect3D = effect3D,
+					Title = "Label"
 				},
 				ColorScheme = Colors.TopLevel,
 				Text = "This is a test\nwithout a \nPanelView",

+ 3 - 3
UICatalog/Scenarios/BordersComparisons.cs

@@ -65,9 +65,9 @@ namespace UICatalog.Scenarios {
 					BorderBrush = borderBrush,
 					Padding = padding,
 					Background = background,
-					Effect3D = effect3D
-				},
-				"Test2") {
+					Effect3D = effect3D,
+					Title = "Test2"
+				}) {
 				ColorScheme = Colors.Base,
 			};
 

+ 2 - 1
UICatalog/Scenarios/BordersOnFrameView.cs

@@ -30,7 +30,8 @@ namespace UICatalog.Scenarios {
 					BorderBrush = borderBrush,
 					Padding = padding,
 					Background = background,
-					Effect3D = effect3D
+					Effect3D = effect3D,
+					Title = "Frame"
 				},
 				ColorScheme = Colors.TopLevel
 			};

+ 2 - 1
UICatalog/Scenarios/BordersOnToplevel.cs

@@ -30,7 +30,8 @@ namespace UICatalog.Scenarios {
 					BorderBrush = borderBrush,
 					Padding = padding,
 					Background = background,
-					Effect3D = effect3D
+					Effect3D = effect3D,
+					Title = "Toplevel"
 				},
 				ColorScheme = Colors.TopLevel
 			};

+ 2 - 1
UICatalog/Scenarios/BordersOnWindow.cs

@@ -30,7 +30,8 @@ namespace UICatalog.Scenarios {
 					BorderBrush = borderBrush,
 					Padding = padding,
 					Background = background,
-					Effect3D = effect3D
+					Effect3D = effect3D,
+					Title = "Window"
 				},
 				ColorScheme = Colors.TopLevel
 			};

+ 1 - 0
UnitTests/BorderTests.cs

@@ -26,6 +26,7 @@ namespace Terminal.Gui.Core {
 			Assert.False (b.Effect3D);
 			Assert.Equal (new Point (1, 1), b.Effect3DOffset);
 			Assert.Null (b.Effect3DBrush);
+			Assert.Equal (NStack.ustring.Empty, b.Title);
 		}
 
 		[Fact]