mirror of
https://github.com/gui-cs/Terminal.Gui.git
synced 2025-12-29 17:28:01 +01:00
Fixes #2222. RadioGroup first upper case and ProcessColdKey is not working well.
This commit is contained in:
@@ -3063,6 +3063,17 @@ namespace Terminal.Gui {
|
||||
return Enabled ? ColorScheme.Normal : ColorScheme.Disabled;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Determines the current <see cref="ColorScheme"/> based on the <see cref="Enabled"/> value.
|
||||
/// </summary>
|
||||
/// <returns><see cref="Terminal.Gui.ColorScheme.HotNormal"/> if <see cref="Enabled"/> is <see langword="true"/>
|
||||
/// or <see cref="Terminal.Gui.ColorScheme.Disabled"/> if <see cref="Enabled"/> is <see langword="false"/>.
|
||||
/// If it's overridden can return other values.</returns>
|
||||
public virtual Attribute GetHotNormalColor ()
|
||||
{
|
||||
return Enabled ? ColorScheme.HotNormal : ColorScheme.Disabled;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get the top superview of a given <see cref="View"/>.
|
||||
/// </summary>
|
||||
|
||||
@@ -67,6 +67,7 @@ namespace Terminal.Gui {
|
||||
Frame = rect;
|
||||
}
|
||||
CanFocus = true;
|
||||
HotKeySpecifier = new Rune ('_');
|
||||
|
||||
// Things this view knows how to do
|
||||
AddCommand (Command.LineUp, () => { MoveUp (); return true; });
|
||||
@@ -215,9 +216,36 @@ namespace Terminal.Gui {
|
||||
Move (horizontal [i].pos, 0);
|
||||
break;
|
||||
}
|
||||
var rl = radioLabels [i];
|
||||
Driver.SetAttribute (GetNormalColor ());
|
||||
Driver.AddStr (ustring.Make (new Rune [] { i == selected ? Driver.Selected : Driver.UnSelected, ' ' }));
|
||||
DrawHotString (radioLabels [i], HasFocus && i == cursor, ColorScheme);
|
||||
TextFormatter.FindHotKey (rl, HotKeySpecifier, true, out int hotPos, out Key hotKey);
|
||||
if (hotPos != -1 && (hotKey != Key.Null || hotKey != Key.Unknown)) {
|
||||
var rlRunes = rl.ToRunes ();
|
||||
for (int j = 0; j < rlRunes.Length; j++) {
|
||||
Rune rune = rlRunes [j];
|
||||
if (j == hotPos && i == cursor) {
|
||||
Application.Driver.SetAttribute (HasFocus ? ColorScheme.HotFocus : GetHotNormalColor ());
|
||||
} else if (j == hotPos && i != cursor) {
|
||||
Application.Driver.SetAttribute (GetHotNormalColor ());
|
||||
} else if (HasFocus && i == cursor) {
|
||||
Application.Driver.SetAttribute (ColorScheme.Focus);
|
||||
}
|
||||
if (rune == HotKeySpecifier && j + 1 < rlRunes.Length) {
|
||||
j++;
|
||||
rune = rlRunes [j];
|
||||
if (i == cursor) {
|
||||
Application.Driver.SetAttribute (HasFocus ? ColorScheme.HotFocus : GetHotNormalColor ());
|
||||
} else if (i != cursor) {
|
||||
Application.Driver.SetAttribute (GetHotNormalColor ());
|
||||
}
|
||||
}
|
||||
Application.Driver.AddRune (rune);
|
||||
Driver.SetAttribute (GetNormalColor ());
|
||||
}
|
||||
} else {
|
||||
DrawHotString (rl, HasFocus && i == cursor, ColorScheme);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -280,11 +308,12 @@ namespace Terminal.Gui {
|
||||
key = Char.ToUpper ((char)key);
|
||||
foreach (var l in radioLabels) {
|
||||
bool nextIsHot = false;
|
||||
foreach (var c in l) {
|
||||
if (c == '_')
|
||||
TextFormatter.FindHotKey (l, HotKeySpecifier, true, out _, out Key hotKey);
|
||||
foreach (Rune c in l) {
|
||||
if (c == HotKeySpecifier) {
|
||||
nextIsHot = true;
|
||||
else {
|
||||
if (nextIsHot && c == key) {
|
||||
} else {
|
||||
if ((nextIsHot && Rune.ToUpper (c) == key) || (key == (uint)hotKey)) {
|
||||
SelectedItem = i;
|
||||
cursor = i;
|
||||
if (!HasFocus)
|
||||
|
||||
@@ -172,5 +172,20 @@ namespace Terminal.Gui.Views {
|
||||
Assert.True (rg.ProcessKey (new KeyEvent (Key.Space, new KeyModifiers ())));
|
||||
Assert.Equal (1, rg.SelectedItem);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ProcessColdKey_HotKey ()
|
||||
{
|
||||
var rg = new RadioGroup (new NStack.ustring [] { "Left", "Right", "Cen_tered", "Justified" });
|
||||
|
||||
Assert.True (rg.ProcessColdKey (new KeyEvent (Key.t, new KeyModifiers ())));
|
||||
Assert.Equal (2, rg.SelectedItem);
|
||||
Assert.True (rg.ProcessColdKey (new KeyEvent (Key.L, new KeyModifiers ())));
|
||||
Assert.Equal (0, rg.SelectedItem);
|
||||
Assert.True (rg.ProcessColdKey (new KeyEvent (Key.J, new KeyModifiers ())));
|
||||
Assert.Equal (3, rg.SelectedItem);
|
||||
Assert.True (rg.ProcessColdKey (new KeyEvent (Key.R, new KeyModifiers ())));
|
||||
Assert.Equal (1, rg.SelectedItem);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4062,5 +4062,27 @@ This is a tes
|
||||
Assert.False (view.IsKeyPress);
|
||||
Assert.True (view.IsKeyUp);
|
||||
}
|
||||
|
||||
[Fact, AutoInitShutdown]
|
||||
public void GetNormalColor_ColorScheme ()
|
||||
{
|
||||
var view = new View { ColorScheme = Colors.Base };
|
||||
|
||||
Assert.Equal (view.ColorScheme.Normal, view.GetNormalColor ());
|
||||
|
||||
view.Enabled = false;
|
||||
Assert.Equal (view.ColorScheme.Disabled, view.GetNormalColor ());
|
||||
}
|
||||
|
||||
[Fact, AutoInitShutdown]
|
||||
public void GetHotNormalColor_ColorScheme ()
|
||||
{
|
||||
var view = new View { ColorScheme = Colors.Base };
|
||||
|
||||
Assert.Equal (view.ColorScheme.HotNormal, view.GetHotNormalColor ());
|
||||
|
||||
view.Enabled = false;
|
||||
Assert.Equal (view.ColorScheme.Disabled, view.GetHotNormalColor ());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user