2
0
Эх сурвалжийг харах

Changed to CursorPosition and improving Button LayoutStyle.Computed.

BDisp 4 жил өмнө
parent
commit
9e9de9c121

+ 6 - 6
Terminal.Gui/Core/TextFormatter.cs

@@ -103,9 +103,9 @@ namespace Terminal.Gui {
 		public uint HotKeyTagMask { get; set; } = 0x100000;
 
 		/// <summary>
-		/// Gets the position cursor from <see cref="HotKey"/>. If the <see cref="HotKey"/> is defined, the cursor will be positioned over it.
+		/// Gets the cursor position from <see cref="HotKey"/>. If the <see cref="HotKey"/> is defined, the cursor will be positioned over it.
 		/// </summary>
-		public int PositionCursor { get; set; }
+		public int CursorPosition { get; set; }
 
 		/// <summary>
 		/// Gets the formatted lines. 
@@ -574,15 +574,15 @@ namespace Terminal.Gui {
 				case TextAlignment.Left:
 				case TextAlignment.Justified:
 					x = bounds.Left;
-					PositionCursor = hotKeyPos;
+					CursorPosition = hotKeyPos;
 					break;
 				case TextAlignment.Right:
 					x = bounds.Right - runes.Length;
-					PositionCursor = bounds.Width - runes.Length + hotKeyPos;
+					CursorPosition = bounds.Width - runes.Length + hotKeyPos;
 					break;
 				case TextAlignment.Centered:
 					x = bounds.Left + (bounds.Width - runes.Length) / 2;
-					PositionCursor = (bounds.Width - runes.Length) / 2 + hotKeyPos;
+					CursorPosition = (bounds.Width - runes.Length) / 2 + hotKeyPos;
 					break;
 				default:
 					throw new ArgumentOutOfRangeException ();
@@ -595,7 +595,7 @@ namespace Terminal.Gui {
 					}
 					if ((rune & HotKeyTagMask) == HotKeyTagMask) {
 						if (textAlignment == TextAlignment.Justified) {
-							PositionCursor = col - bounds.Left;
+							CursorPosition = col - bounds.Left;
 						}
 						Application.Driver?.SetAttribute (hotColor);
 						Application.Driver?.AddRune ((Rune)((uint)rune & ~HotKeyTagMask));

+ 1 - 1
Terminal.Gui/Core/View.cs

@@ -1086,7 +1086,7 @@ namespace Terminal.Gui {
 				focused.PositionCursor ();
 			} else {
 				if (CanFocus && HasFocus && Visible) {
-					Move (textFormatter.HotKeyPos == -1 ? 0 : textFormatter.PositionCursor, 0);
+					Move (textFormatter.HotKeyPos == -1 ? 0 : textFormatter.CursorPosition, 0);
 				} else {
 					Move (frame.X, frame.Y);
 				}

+ 7 - 3
Terminal.Gui/Views/Button.cs

@@ -147,10 +147,14 @@ namespace Terminal.Gui {
 			int w = base.Text.RuneCount - (base.Text.Contains (HotKeySpecifier) ? 1 : 0);
 			try {
 				Width = w;
-#pragma warning disable RCS1075 // Avoid empty catch clause that catches System.Exception.
 			} catch (Exception) {
-#pragma warning restore RCS1075 // Avoid empty catch clause that catches System.Exception.
-			       // It's a Dim.DimCombine and so can't be assigned. Let it have it's own anchor.
+				// It's a Dim.DimCombine and so can't be assigned. Let it have it's own anchor.
+				var width = Width;
+				LayoutStyle = LayoutStyle.Absolute;
+				Width = w;
+				LayoutStyle = LayoutStyle.Computed;
+				Width = width;
+				w = width.Anchor (w);
 			}
 			Height = 1;
 			Frame = new Rect (Frame.Location, new Size (w, 1));