diff --git a/Terminal.Gui/View/View.Attribute.cs b/Terminal.Gui/View/View.Attribute.cs index 20e201b66..8e9173bfc 100644 --- a/Terminal.Gui/View/View.Attribute.cs +++ b/Terminal.Gui/View/View.Attribute.cs @@ -1,4 +1,6 @@ #nullable enable +using System.ComponentModel; + namespace Terminal.Gui; public partial class View @@ -80,8 +82,17 @@ public partial class View /// public virtual Attribute GetNormalColor () { - ColorScheme? cs = ColorScheme ?? new (); + Attribute currAttribute = ColorScheme?.Normal ?? Attribute.Default; + Attribute newAttribute = new Attribute (); + CancelEventArgs args = new CancelEventArgs (in currAttribute, ref newAttribute); + GettingNormalColor?.Invoke (this, args); + if (args.Cancel) + { + return args.NewValue; + } + + ColorScheme? cs = ColorScheme ?? new (); Attribute disabled = new (cs.Disabled.Foreground, cs.Disabled.Background); if (Diagnostics.HasFlag (ViewDiagnosticFlags.Hover) && _hovering) @@ -92,6 +103,8 @@ public partial class View return Enabled ? GetColor (cs.Normal) : disabled; } + public event EventHandler>? GettingNormalColor; + private Attribute GetColor (Attribute inputAttribute) { Attribute attr = inputAttribute; diff --git a/Terminal.Gui/Views/FlagSelector.cs b/Terminal.Gui/Views/FlagSelector.cs index fbffb6e68..a07b1c0fe 100644 --- a/Terminal.Gui/Views/FlagSelector.cs +++ b/Terminal.Gui/Views/FlagSelector.cs @@ -302,13 +302,22 @@ public class FlagSelector : View, IOrientation, IDesignable var checkbox = new CheckBox { - CanFocus = false, + CanFocus = true, Title = nameWithHotKey, Id = name, Data = flag, - HighlightStyle = HighlightStyle + // HighlightStyle = HighlightStyle }; + checkbox.GettingNormalColor += (_, e) => + { + if (SuperView is {HasFocus: true}) + { + e.Cancel = true; + e.NewValue = GetFocusColor (); + } + }; + checkbox.Selecting += (sender, args) => { RaiseSelecting (args.Context); }; checkbox.CheckedStateChanged += (sender, args) => diff --git a/Terminal.Gui/Views/Shortcut.cs b/Terminal.Gui/Views/Shortcut.cs index 7f98a9400..d32d4f02d 100644 --- a/Terminal.Gui/Views/Shortcut.cs +++ b/Terminal.Gui/Views/Shortcut.cs @@ -90,11 +90,11 @@ public class Shortcut : View, IOrientation, IDesignable Title = commandText ?? string.Empty; HelpView.Id = "_helpView"; - HelpView.CanFocus = false; + //HelpView.CanFocus = false; HelpView.Text = helpText ?? string.Empty; KeyView.Id = "_keyView"; - KeyView.CanFocus = false; + //KeyView.CanFocus = false; key ??= Key.Empty; Key = key; @@ -437,7 +437,7 @@ public class Shortcut : View, IOrientation, IDesignable // The default behavior is for CommandView to not get focus. I // If you want it to get focus, you need to set it. - _commandView.CanFocus = false; + // _commandView.CanFocus = false; _commandView.HotKeyChanged += (s, e) => { @@ -492,9 +492,19 @@ public class Shortcut : View, IOrientation, IDesignable CommandView.VerticalTextAlignment = Alignment.Center; CommandView.TextAlignment = Alignment.Start; CommandView.TextFormatter.WordWrap = false; - CommandView.HighlightStyle = HighlightStyle.None; + //CommandView.HighlightStyle = HighlightStyle.None; + CommandView.GettingNormalColor += CommanandView_GettingNormalColor; + } + private void CommanandView_GettingNormalColor (object? sender, CancelEventArgs? e) + { + if (HasFocus) + { + e.Cancel = true; + e.NewValue = GetFocusColor (); + } + } private void Shortcut_TitleChanged (object? sender, EventArgs e) { // If the Title changes, update the CommandView text. @@ -533,6 +543,17 @@ public class Shortcut : View, IOrientation, IDesignable HelpView.TextAlignment = Alignment.Start; HelpView.TextFormatter.WordWrap = false; HelpView.HighlightStyle = HighlightStyle.None; + + HelpView.GettingNormalColor += HelpView_GettingNormalColor; + } + + private void HelpView_GettingNormalColor (object? sender, CancelEventArgs? e) + { + if (HasFocus) + { + e.Cancel = true; + e.NewValue = GetFocusColor (); + } } /// @@ -619,10 +640,10 @@ public class Shortcut : View, IOrientation, IDesignable } /// - /// Gets the subview that displays the key. Internal for unit testing. + /// Gets the subview that displays the key. Is drawn with Normal and HotNormal colors reversed. /// - public View KeyView { get; } = new (); + public KeyView KeyView { get; } = new (); private int _minimumKeyTextSize; @@ -698,16 +719,16 @@ public class Shortcut : View, IOrientation, IDesignable #region Focus - /// - public override ColorScheme? ColorScheme - { - get => base.ColorScheme; - set - { - base.ColorScheme = _nonFocusColorScheme = value; - SetColors (); - } - } + ///// + //public override ColorScheme? ColorScheme + //{ + // get => base.ColorScheme; + // set + // { + // base.ColorScheme = _nonFocusColorScheme = value; + // SetColors (); + // } + //} private bool _forceFocusColors; @@ -731,6 +752,7 @@ public class Shortcut : View, IOrientation, IDesignable /// internal void SetColors (bool highlight = false) { + return; if (HasFocus || highlight || ForceFocusColors) { if (_nonFocusColorScheme is null) @@ -762,17 +784,6 @@ public class Shortcut : View, IOrientation, IDesignable } } - // Set KeyView's colors to show "hot" - if (IsInitialized && base.ColorScheme is { }) - { - var cs = new ColorScheme (base.ColorScheme) - { - Normal = GetHotNormalColor (), - HotNormal = GetNormalColor () - }; - KeyView.ColorScheme = cs; - } - if (CommandView.Margin is { }) { CommandView.Margin.ColorScheme = base.ColorScheme; @@ -788,6 +799,28 @@ public class Shortcut : View, IOrientation, IDesignable } } + public override Attribute GetNormalColor () + { + if (HasFocus) + + { + return base.GetFocusColor (); + } + + return base.GetNormalColor (); + } + + public override Attribute GetHotNormalColor () + { + if (HasFocus) + + { + return base.GetHotFocusColor (); + } + + return base.GetHotNormalColor (); + } + /// protected override void OnHasFocusChanged (bool newHasFocus, View? previousFocusedView, View? view) { @@ -832,3 +865,28 @@ public class Shortcut : View, IOrientation, IDesignable base.Dispose (disposing); } } + +public class KeyView : View +{ + + // Normal = GetHotNormalColor (), + // HotNormal = GetNormalColor () + /// + public override Attribute GetNormalColor () + { + if (SuperView is { HasFocus: true}) + + { + return base.GetFocusColor (); + } + + return base.GetHotNormalColor (); + } + + /// + /// + public override Attribute GetHotNormalColor () { return base.GetNormalColor (); } + + /// + public override Attribute GetFocusColor () { return base.GetFocusColor (); } +}