瀏覽代碼

WIP: Making Hover work menu-style

Tig 10 月之前
父節點
當前提交
72aac7fefa

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

@@ -408,7 +408,7 @@ public partial class View // Drawing APIs
         Attribute attr = inputAttribute;
         if (HighlightStyle.HasFlag (HighlightStyle.Hover) && _Hover)
         {
-            attr = new (inputAttribute.Foreground.GetHighlightColor (), inputAttribute.Background);
+            //attr = new (inputAttribute.Foreground.GetHighlightColor (), inputAttribute.Background);
         }
 
         if (Diagnostics.HasFlag (ViewDiagnosticFlags.Hover) && _Hover)

+ 15 - 1
Terminal.Gui/View/View.Mouse.cs

@@ -163,7 +163,15 @@ public partial class View // Mouse APIs
 
         if ((HighlightStyle.HasFlag(HighlightStyle.Hover) ||  Diagnostics.HasFlag (ViewDiagnosticFlags.Hover)))
         {
+            HighlightStyle copy = HighlightStyle;
+            HighlightStyle hover = HighlightStyle.Hover;
+            CancelEventArgs<HighlightStyle> args = new (ref copy, ref hover);
+            if (!RaiseHighlight (args))
+            {
+            }
             SetNeedsDisplay ();
+
+            return args.Cancel;
         }
 
         return false;
@@ -245,7 +253,13 @@ public partial class View // Mouse APIs
 
         if ((HighlightStyle.HasFlag (HighlightStyle.Hover) || Diagnostics.HasFlag (ViewDiagnosticFlags.Hover)))
         {
-            SetNeedsDisplay ();
+            HighlightStyle copy = HighlightStyle;
+            HighlightStyle hover = HighlightStyle.None;
+            CancelEventArgs<HighlightStyle> args = new (ref copy, ref hover);
+            if (!RaiseHighlight (args))
+            {
+                SetNeedsDisplay ();
+            }
         }
     }
 

+ 1 - 0
Terminal.Gui/Views/Menuv2.cs

@@ -53,6 +53,7 @@ public class Menuv2 : Bar
             shortcut.CanFocus = true;
             shortcut.KeyBindingScope = KeyBindingScope.Application;
             shortcut.Orientation = Orientation.Vertical;
+            shortcut.HighlightStyle |= HighlightStyle.Hover;
 
             // TODO: not happy about using AlignmentModes for this. Too implied.
             // TODO: instead, add a property (a style enum?) to Shortcut to control this

+ 18 - 3
Terminal.Gui/Views/Shortcut.cs

@@ -54,7 +54,7 @@ public class Shortcut : View, IOrientation, IDesignable
     {
         Id = "_shortcut";
         HighlightStyle = HighlightStyle.Pressed;
-        Highlight += Shortcut_Highlight;
+        //Highlight += Shortcut_Highlight;
         CanFocus = true;
         Width = GetWidthDimAuto ();
         Height = Dim.Auto (DimAutoStyle.Content, 1);
@@ -149,6 +149,21 @@ public class Shortcut : View, IOrientation, IDesignable
 
     private Color? _savedForeColor;
 
+    /// <inheritdoc />
+    protected override bool OnHighlight (CancelEventArgs<HighlightStyle> args)
+    {
+        if (args.NewValue.HasFlag (HighlightStyle.Hover))
+        {
+            SetColors (true);
+        }
+        else
+        {
+            SetColors (false);
+        }
+
+        return true;
+    }
+
     /// <inheritdoc/>
     public bool EnableForDesign ()
     {
@@ -803,12 +818,12 @@ public class Shortcut : View, IOrientation, IDesignable
 
     /// <summary>
     /// </summary>
-    internal void SetColors ()
+    internal void SetColors (bool highlight = false)
     {
         // Border should match superview.
         Border.ColorScheme = SuperView?.ColorScheme;
 
-        if (HasFocus)
+        if (HasFocus || highlight)
         {
             base.ColorScheme ??= new (Attribute.Default);
 

+ 8 - 2
UICatalog/Scenarios/Bars.cs

@@ -349,20 +349,23 @@ public class Bars : Scenario
             Title = "_File",
             HelpText = "File Menu",
             Key = Key.D0.WithAlt,
+            HighlightStyle = HighlightStyle.Hover
         };
 
         var editMenuBarItem = new Shortcut
         {
             Title = "_Edit",
             HelpText = "Edit Menu",
-            Key = Key.D1.WithAlt
+            Key = Key.D1.WithAlt,
+            HighlightStyle = HighlightStyle.Hover
         };
 
         var helpMenuBarItem = new Shortcut
         {
             Title = "_Help",
             HelpText = "Halp Menu",
-            Key = Key.D2.WithAlt
+            Key = Key.D2.WithAlt,
+            HighlightStyle = HighlightStyle.Hover
         };
 
         bar.Add (fileMenuBarItem, editMenuBarItem, helpMenuBarItem);
@@ -376,6 +379,7 @@ public class Bars : Scenario
             Title = "Z_igzag",
             Key = Key.I.WithCtrl,
             Text = "Gonna zig zag",
+            HighlightStyle = HighlightStyle.Hover
         };
 
         var shortcut2 = new Shortcut
@@ -383,6 +387,7 @@ public class Bars : Scenario
             Title = "Za_G",
             Text = "Gonna zag",
             Key = Key.G.WithAlt,
+            HighlightStyle = HighlightStyle.Hover
         };
 
         var line = new Line ()
@@ -397,6 +402,7 @@ public class Bars : Scenario
             Title = "_Three",
             Text = "The 3rd item",
             Key = Key.D3.WithAlt,
+            HighlightStyle = HighlightStyle.Hover
         };
 
         bar.Add (shortcut1, shortcut2, line, shortcut3);