Browse Source

Adds a diagnostic flag to highlight adornment mouse enter/leave

Tig 1 year ago
parent
commit
2b3ff6e175

+ 7 - 1
Terminal.Gui/ConsoleDrivers/ConsoleDriver.cs

@@ -31,7 +31,13 @@ public abstract class ConsoleDriver
         ///     When enabled, <see cref="View.OnDrawAdornments"/> will draw a 'L', 'R', 'T', and 'B' when clearing
         ///     When enabled, <see cref="View.OnDrawAdornments"/> will draw a 'L', 'R', 'T', and 'B' when clearing
         ///     <see cref="Thickness"/>'s instead of ' '.
         ///     <see cref="Thickness"/>'s instead of ' '.
         /// </summary>
         /// </summary>
-        FramePadding = 0b_0000_0010
+        FramePadding = 0b_0000_0010,
+
+        /// <summary>
+        ///     When enabled, <see cref="Adornment.OnMouseEnter(Gui.MouseEvent)"/> and <see cref="Adornment.OnMouseLeave(Gui.MouseEvent)"/>
+        ///     will invert the foreground and background colors.        ///     
+        /// </summary>
+        HighlightAdornmentOnMouseEnter = 0b_0000_00100
     }
     }
 
 
     // As performance is a concern, we keep track of the dirty lines and only refresh those.
     // As performance is a concern, we keep track of the dirty lines and only refresh those.

+ 29 - 0
Terminal.Gui/View/Adornment/Adornment.cs

@@ -39,6 +39,7 @@ public class Adornment : View
         Parent = parent;
         Parent = parent;
     }
     }
 
 
+
     /// <summary>
     /// <summary>
     ///     Gets the rectangle that describes the area of the Adornment. The Location is always (0,0).
     ///     Gets the rectangle that describes the area of the Adornment. The Location is always (0,0).
     ///     The size is the size of the Frame
     ///     The size is the size of the Frame
@@ -325,4 +326,32 @@ public class Adornment : View
             e.Cancel = true;
             e.Cancel = true;
         }
         }
     }
     }
+
+    protected internal override bool OnMouseEnter (MouseEvent mouseEvent)
+    {
+        // Invert Normal
+        if (ConsoleDriver.Diagnostics.HasFlag(ConsoleDriver.DiagnosticFlags.HighlightAdornmentOnMouseEnter) && ColorScheme != null)
+        {
+            var cs = new ColorScheme (ColorScheme) 
+            { 
+                Normal = new Attribute (ColorScheme.Normal.Background, ColorScheme.Normal.Foreground) 
+            };
+            ColorScheme = cs;
+        }
+        return base.OnMouseEnter (mouseEvent);
+    }
+
+    protected internal override bool OnMouseLeave (MouseEvent mouseEvent)
+    {
+        // Invert Normal
+        if (ConsoleDriver.Diagnostics.HasFlag (ConsoleDriver.DiagnosticFlags.HighlightAdornmentOnMouseEnter) && ColorScheme != null)
+        {
+            var cs = new ColorScheme (ColorScheme)
+            {
+                Normal = new Attribute (ColorScheme.Normal.Background, ColorScheme.Normal.Foreground)
+            };
+            ColorScheme= cs;
+        }
+        return base.OnMouseLeave (mouseEvent);
+    }
 }
 }

+ 4 - 1
UICatalog/Scenarios/Adornments.cs

@@ -11,6 +11,8 @@ namespace UICatalog.Scenarios;
 [ScenarioCategory ("Borders")]
 [ScenarioCategory ("Borders")]
 public class Adornments : Scenario
 public class Adornments : Scenario
 {
 {
+    private ConsoleDriver.DiagnosticFlags _diagnosticFlags;
+
     public override void Init ()
     public override void Init ()
     {
     {
         Application.Init ();
         Application.Init ();
@@ -112,6 +114,7 @@ public class Adornments : Scenario
                                 view.Accept += (s, e) => MessageBox.Query (20, 7, "Hi", "Window Close Button Pressed!", "Ok");
                                 view.Accept += (s, e) => MessageBox.Query (20, 7, "Hi", "Window Close Button Pressed!", "Ok");
                             };
                             };
 
 
+        Application.Top.Closed += (s, e) => ConsoleDriver.Diagnostics = _diagnosticFlags;
 
 
         Application.Run (editor);
         Application.Run (editor);
         Application.Shutdown ();
         Application.Shutdown ();
@@ -431,7 +434,7 @@ public class Adornments : Scenario
                                              if (e.NewValue == true)
                                              if (e.NewValue == true)
                                              {
                                              {
                                                  ConsoleDriver.Diagnostics =
                                                  ConsoleDriver.Diagnostics =
-                                                     ConsoleDriver.DiagnosticFlags.FramePadding | ConsoleDriver.DiagnosticFlags.FrameRuler;
+                                                     ConsoleDriver.DiagnosticFlags.FramePadding | ConsoleDriver.DiagnosticFlags.HighlightAdornmentOnMouseEnter;
                                              }
                                              }
                                              else
                                              else
                                              {
                                              {