mirror of
https://github.com/gui-cs/Terminal.Gui.git
synced 2025-12-26 15:57:56 +01:00
Merge pull request #960 from BDisp/position-cursor-hotkey
Fixes #959. CursorPosition with hotkeys.
This commit is contained in:
@@ -499,7 +499,7 @@ namespace Terminal.Gui {
|
||||
return new DimAbsolute (n);
|
||||
}
|
||||
|
||||
class DimCombine : Dim {
|
||||
internal class DimCombine : Dim {
|
||||
Dim left, right;
|
||||
bool add;
|
||||
public DimCombine (bool add, Dim left, Dim right)
|
||||
|
||||
@@ -102,6 +102,11 @@ namespace Terminal.Gui {
|
||||
/// </summary>HotKeyTagMask
|
||||
public uint HotKeyTagMask { get; set; } = 0x100000;
|
||||
|
||||
/// <summary>
|
||||
/// 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 CursorPosition { 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;
|
||||
CursorPosition = hotKeyPos;
|
||||
break;
|
||||
case TextAlignment.Right:
|
||||
x = bounds.Right - runes.Length;
|
||||
CursorPosition = bounds.Width - runes.Length + hotKeyPos;
|
||||
break;
|
||||
case TextAlignment.Centered:
|
||||
x = bounds.Left + (bounds.Width - runes.Length) / 2;
|
||||
CursorPosition = (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) {
|
||||
CursorPosition = col - bounds.Left;
|
||||
}
|
||||
Application.Driver?.SetAttribute (hotColor);
|
||||
Application.Driver?.AddRune ((Rune)((uint)rune & ~HotKeyTagMask));
|
||||
Application.Driver?.SetAttribute (normalColor);
|
||||
|
||||
@@ -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.CursorPosition, 0);
|
||||
} else {
|
||||
Move (frame.X, frame.Y);
|
||||
}
|
||||
|
||||
@@ -145,7 +145,10 @@ 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;
|
||||
if (Width is Dim.DimCombine) {
|
||||
// It's a Dim.DimCombine and so can't be assigned. Let it have it's own anchor.
|
||||
w = Width.Anchor (w);
|
||||
}
|
||||
Height = 1;
|
||||
Frame = new Rect (Frame.Location, new Size (w, 1));
|
||||
SetNeedsDisplay ();
|
||||
|
||||
@@ -259,6 +259,14 @@ namespace Terminal.Gui {
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Allow to invoke the <see cref="SelectedItemChanged"/> after their creation.
|
||||
/// </summary>
|
||||
public void Refresh ()
|
||||
{
|
||||
OnSelectedItemChanged (selected, -1);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Called whenever the current selected item changes. Invokes the <see cref="SelectedItemChanged"/> event.
|
||||
/// </summary>
|
||||
|
||||
@@ -266,6 +266,8 @@ namespace UICatalog {
|
||||
break;
|
||||
}
|
||||
};
|
||||
|
||||
Top.Ready += () => radioGroup.Refresh ();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user