Browse Source

Draw caption

Thomas 2 years ago
parent
commit
9f6e382f58
1 changed files with 24 additions and 1 deletions
  1. 24 1
      Terminal.Gui/Views/TextField.cs

+ 24 - 1
Terminal.Gui/Views/TextField.cs

@@ -34,7 +34,7 @@ namespace Terminal.Gui {
 		/// been entered yet and the <see cref="View"/> does not yet have
 		/// input focus.
 		/// </summary>
-		public string Caption {get;set;}
+		public ustring Caption {get;set;}
 
 		/// <summary>
 		/// Gets or sets the foreground <see cref="Color"/> to use when 
@@ -471,6 +471,8 @@ namespace Terminal.Gui {
 
 			PositionCursor ();
 
+			RenderCaption();
+			
 			if (SelectedLength > 0)
 				return;
 
@@ -483,6 +485,27 @@ namespace Terminal.Gui {
 			Autocomplete.RenderOverlay (renderAt);
 		}
 
+		private void RenderCaption ()
+		{
+			
+			if (HasFocus || Caption == null || Caption.Length == 0
+				|| Text?.Length > 0) {
+				return;
+			}
+
+			var color = new Attribute (CaptionColor, GetNormalColor ().Background);
+			Driver.SetAttribute (color);
+
+			Move (0, 0);
+			var render = Caption;
+
+			if (render.ConsoleWidth > Bounds.Width) {
+				render = render.RuneSubstring (0, Bounds.Width);
+			}
+
+			Driver.AddStr (render);
+		}
+
 		/// <inheritdoc/>
 		public override Attribute GetNormalColor ()
 		{