Browse Source

Add PointEventArgs

tznind 2 years ago
parent
commit
7a52f45a10

+ 27 - 0
Terminal.Gui/Core/EventArgs/PointEventArgs.cs

@@ -0,0 +1,27 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace Terminal.Gui {
+	/// <summary>
+	/// Event args for events which relate to a single <see cref="Point"/>
+	/// </summary>
+	public class PointEventArgs : EventArgs{
+
+		/// <summary>
+		/// Creates a new instance of the <see cref="PointEventArgs"/> class
+		/// </summary>
+		/// <param name="p"></param>
+		public PointEventArgs (Point p)
+		{
+			this.Point = p;
+		}
+
+		/// <summary>
+		/// The point the event happened at
+		/// </summary>
+		public Point Point { get; }
+	}
+}

+ 2 - 2
Terminal.Gui/Views/TextView.cs

@@ -1170,7 +1170,7 @@ namespace Terminal.Gui {
 		/// <summary>
 		/// Invoked with the unwrapped <see cref="CursorPosition"/>.
 		/// </summary>
-		public event Action<Point> UnwrappedCursorPosition;
+		public event EventHandler<PointEventArgs> UnwrappedCursorPosition;
 
 		/// <summary>
 		/// Provides autocomplete context menu based on suggestions at the current cursor
@@ -2364,7 +2364,7 @@ namespace Terminal.Gui {
 				row = wrapManager.GetModelLineFromWrappedLines (currentRow);
 				col = wrapManager.GetModelColFromWrappedLines (currentRow, currentColumn);
 			}
-			UnwrappedCursorPosition?.Invoke (new Point ((int)col, (int)row));
+			UnwrappedCursorPosition?.Invoke (this, new PointEventArgs(new Point ((int)col, (int)row)));
 		}
 
 		ustring GetSelectedRegion ()

+ 2 - 2
UICatalog/Scenarios/Editor.cs

@@ -59,8 +59,8 @@ namespace UICatalog.Scenarios {
 
 			var siCursorPosition = new StatusItem (Key.Null, "", null);
 
-			_textView.UnwrappedCursorPosition += (e) => {
-				siCursorPosition.Title = $"Ln {e.Y + 1}, Col {e.X + 1}";
+			_textView.UnwrappedCursorPosition += (s,e) => {
+				siCursorPosition.Title = $"Ln {e.Point.Y + 1}, Col {e.Point.X + 1}";
 			};
 
 			LoadFile ();

+ 2 - 2
UnitTests/Views/TextViewTests.cs

@@ -6001,8 +6001,8 @@ line.
 				Height = Dim.Fill (),
 				Text = "This is the first line.\nThis is the second line.\n"
 			};
-			tv.UnwrappedCursorPosition += (e) => {
-				cp = e;
+			tv.UnwrappedCursorPosition += (s,e) => {
+				cp = e.Point;
 			};
 			Application.Top.Add (tv);
 			Application.Begin (Application.Top);