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

Fixes #959. PositionCursor with hotkeys.

BDisp 4 жил өмнө
parent
commit
4073019554

+ 11 - 2
Terminal.Gui/Core/TextFormatter.cs

@@ -102,6 +102,11 @@ namespace Terminal.Gui {
 		/// </summary>HotKeyTagMask
 		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.
+		/// </summary>
+		public int PositionCursor { get; set; }
+
 		/// <summary>
 		/// Gets the formatted lines. 
 		/// </summary>
@@ -567,16 +572,17 @@ namespace Terminal.Gui {
 				int x;
 				switch (textAlignment) {
 				case TextAlignment.Left:
-					x = bounds.Left;
-					break;
 				case TextAlignment.Justified:
 					x = bounds.Left;
+					PositionCursor = hotKeyPos;
 					break;
 				case TextAlignment.Right:
 					x = bounds.Right - runes.Length;
+					PositionCursor = bounds.Width - runes.Length + hotKeyPos;
 					break;
 				case TextAlignment.Centered:
 					x = bounds.Left + (bounds.Width - runes.Length) / 2;
+					PositionCursor = (bounds.Width - runes.Length) / 2 + hotKeyPos;
 					break;
 				default:
 					throw new ArgumentOutOfRangeException ();
@@ -588,6 +594,9 @@ namespace Terminal.Gui {
 						rune = runes [col - x];
 					}
 					if ((rune & HotKeyTagMask) == HotKeyTagMask) {
+						if (textAlignment == TextAlignment.Justified) {
+							PositionCursor = col - bounds.Left;
+						}
 						Application.Driver?.SetAttribute (hotColor);
 						Application.Driver?.AddRune ((Rune)((uint)rune & ~HotKeyTagMask));
 						Application.Driver?.SetAttribute (normalColor);

+ 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.HotKeyPos, 0);
+					Move (textFormatter.HotKeyPos == -1 ? 0 : textFormatter.PositionCursor, 0);
 				} else {
 					Move (frame.X, frame.Y);
 				}

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

@@ -145,7 +145,13 @@ namespace Terminal.Gui {
 				base.Text = ustring.Make (_leftBracket) + " " + text + " " + ustring.Make (_rightBracket);
 
 			int w = base.Text.RuneCount - (base.Text.Contains (HotKeySpecifier) ? 1 : 0);
-			Width = w;
+			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.
+			}
 			Height = 1;
 			Frame = new Rect (Frame.Location, new Size (w, 1));
 			SetNeedsDisplay ();

+ 5 - 0
Terminal.Gui/Views/RadioGroup.cs

@@ -259,6 +259,11 @@ namespace Terminal.Gui {
 			}
 		}
 
+		public void Refresh ()
+		{
+			OnSelectedItemChanged (selected, -1);
+		}
+
 		/// <summary>
 		/// Called whenever the current selected item changes. Invokes the <see cref="SelectedItemChanged"/> event.
 		/// </summary>

+ 2 - 0
UICatalog/Scenarios/Buttons.cs

@@ -266,6 +266,8 @@ namespace UICatalog {
 					break;
 				}
 			};
+
+			Top.Ready += () => radioGroup.Refresh ();
 		}
 	}
 }