Ver Fonte

Added DrawEventArgs

tznind há 2 anos atrás
pai
commit
796e15a64d

+ 2 - 2
Terminal.Gui/Core/Autocomplete/Autocomplete.cs

@@ -80,12 +80,12 @@ namespace Terminal.Gui {
 			ManipulatePopup ();
 		}
 
-		private void Top_DrawContentComplete (Rect obj)
+		private void Top_DrawContentComplete (object sender, DrawEventArgs e)
 		{
 			ManipulatePopup ();
 		}
 
-		private void Top_DrawContent (Rect obj)
+		private void Top_DrawContent (object sender, DrawEventArgs e)
 		{
 			if (!closed) {
 				ReopenSuggestions ();

+ 28 - 0
Terminal.Gui/Core/EventArgs/DrawEventArgs.cs

@@ -0,0 +1,28 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace Terminal.Gui {
+
+	/// <summary>
+	/// Event args for draw events
+	/// </summary>
+	public class DrawEventArgs : EventArgs{
+
+		/// <summary>
+		/// Creates a new instance of the <see cref="DrawEventArgs"/> class.
+		/// </summary>
+		/// <param name="rect">Gets the view-relative rectangle describing the currently visible viewport into the <see cref="View"/>.</param>
+		public DrawEventArgs (Rect rect)
+		{
+			Rect = rect;
+		}
+
+		/// <summary>
+		/// Gets the view-relative rectangle describing the currently visible viewport into the <see cref="View"/>.
+		/// </summary>
+		public Rect Rect { get; }
+	}
+}

+ 4 - 4
Terminal.Gui/Core/View.cs

@@ -1602,7 +1602,7 @@ namespace Terminal.Gui {
 		/// Rect provides the view-relative rectangle describing the currently visible viewport into the <see cref="View"/>.
 		/// </para>
 		/// </remarks>
-		public event Action<Rect> DrawContent;
+		public event EventHandler<DrawEventArgs> DrawContent;
 
 		/// <summary>
 		/// Enables overrides to draw infinitely scrolled content and/or a background behind added controls. 
@@ -1613,7 +1613,7 @@ namespace Terminal.Gui {
 		/// </remarks>
 		public virtual void OnDrawContent (Rect viewport)
 		{
-			DrawContent?.Invoke (viewport);
+			DrawContent?.Invoke (this, new DrawEventArgs(viewport));
 		}
 
 		/// <summary>
@@ -1627,7 +1627,7 @@ namespace Terminal.Gui {
 		/// Rect provides the view-relative rectangle describing the currently visible viewport into the <see cref="View"/>.
 		/// </para>
 		/// </remarks>
-		public event Action<Rect> DrawContentComplete;
+		public event EventHandler<DrawEventArgs> DrawContentComplete;
 
 		/// <summary>
 		/// Enables overrides after completed drawing infinitely scrolled content and/or a background behind removed controls.
@@ -1638,7 +1638,7 @@ namespace Terminal.Gui {
 		/// </remarks>
 		public virtual void OnDrawContentComplete (Rect viewport)
 		{
-			DrawContentComplete?.Invoke (viewport);
+			DrawContentComplete?.Invoke (this, new DrawEventArgs (viewport));
 		}
 
 		/// <summary>

+ 1 - 1
Terminal.Gui/Windows/Wizard.cs

@@ -243,7 +243,7 @@ namespace Terminal.Gui {
 					}
 				};
 
-				helpTextView.DrawContent += (e) => {
+				helpTextView.DrawContent += (s,e) => {
 					scrollBar.Size = helpTextView.Lines;
 					scrollBar.Position = helpTextView.TopRow;
 					if (scrollBar.OtherScrollBarView != null) {

+ 3 - 1
UICatalog/Scenarios/CharacterMap.cs

@@ -226,8 +226,10 @@ namespace UICatalog.Scenarios {
 			Clipboard.Contents = $"{new Rune (SelectedGlyph)}";
 		}
 
-		private void CharMap_DrawContent (Rect viewport)
+		private void CharMap_DrawContent (object sender, DrawEventArgs e)
 		{
+			Rect viewport = e.Rect;
+
 			var oldClip = Driver.Clip;
 			Driver.Clip = Frame;
 			// Redraw doesn't know about the scroll indicators, so if off, add one to height

+ 1 - 1
UICatalog/Scenarios/CsvEditor.cs

@@ -462,7 +462,7 @@ namespace UICatalog.Scenarios {
 				_listView.SetNeedsDisplay ();
 			};*/
 
-			tableView.DrawContent += (e) => {
+			tableView.DrawContent += (s,e) => {
 				_scrollBar.Size = tableView.Table?.Rows?.Count ?? 0;
 				_scrollBar.Position = tableView.RowOffset;
 				//	_scrollBar.OtherScrollBarView.Size = _listView.Maxlength - 1;

+ 3 - 3
UICatalog/Scenarios/Editor.cs

@@ -160,7 +160,7 @@ namespace UICatalog.Scenarios {
 				}
 			};
 
-			_textView.DrawContent += (e) => {
+			_textView.DrawContent += (s,e) => {
 				_scrollBar.Size = _textView.Lines;
 				_scrollBar.Position = _textView.TopRow;
 				if (_scrollBar.OtherScrollBarView != null) {
@@ -765,7 +765,7 @@ namespace UICatalog.Scenarios {
 		private View FindTab ()
 		{
 			var d = new View ();
-			d.DrawContent += (e) => {
+			d.DrawContent += (s,e) => {
 				foreach (var v in d.Subviews) {
 					v.SetNeedsDisplay ();
 				}
@@ -857,7 +857,7 @@ namespace UICatalog.Scenarios {
 		private View ReplaceTab ()
 		{
 			var d = new View ();
-			d.DrawContent += (e) => {
+			d.DrawContent += (s,e) => {
 				foreach (var v in d.Subviews) {
 					v.SetNeedsDisplay ();
 				}

+ 1 - 1
UICatalog/Scenarios/ListViewWithSelection.cs

@@ -78,7 +78,7 @@ namespace UICatalog.Scenarios {
 				_listView.SetNeedsDisplay ();
 			};
 
-			_listView.DrawContent += (e) => {
+			_listView.DrawContent += (s,e) => {
 				_scrollBar.Size = _listView.Source.Count - 1;
 				_scrollBar.Position = _listView.TopItem;
 				_scrollBar.OtherScrollBarView.Size = _listView.Maxlength - 1;

+ 2 - 2
UICatalog/Scenarios/ListsAndCombos.cs

@@ -57,7 +57,7 @@ namespace UICatalog.Scenarios {
 				listview.SetNeedsDisplay ();
 			};
 
-			listview.DrawContent += (e) => {
+			listview.DrawContent += (s,e) => {
 				_scrollBar.Size = listview.Source.Count - 1;
 				_scrollBar.Position = listview.TopItem;
 				_scrollBar.OtherScrollBarView.Size = listview.Maxlength - 1;
@@ -101,7 +101,7 @@ namespace UICatalog.Scenarios {
 				comboBox.SetNeedsDisplay ();
 			};
 
-			comboBox.DrawContent += (e) => {
+			comboBox.DrawContent += (s,e) => {
 				scrollBarCbx.Size = comboBox.Source.Count;
 				scrollBarCbx.Position = ((ListView)comboBox.Subviews [1]).TopItem;
 				scrollBarCbx.OtherScrollBarView.Size = ((ListView)comboBox.Subviews [1]).Maxlength - 1;

+ 1 - 1
UICatalog/Scenarios/Scrolling.cs

@@ -270,7 +270,7 @@ namespace UICatalog.Scenarios {
 			};
 			var filler = new Filler (new Rect (0, 0, 60, 40));
 			scrollView2.Add (filler);
-			scrollView2.DrawContent += (r) => {
+			scrollView2.DrawContent += (s,e) => {
 				scrollView2.ContentSize = filler.GetContentSize ();
 			};
 			Win.Add (scrollView2);

+ 1 - 1
UICatalog/Scenarios/TableEditor.cs

@@ -335,7 +335,7 @@ namespace UICatalog.Scenarios {
 				_listView.SetNeedsDisplay ();
 			};*/
 
-			tableView.DrawContent += (e) => {
+			tableView.DrawContent += (s,e) => {
 				_scrollBar.Size = tableView.Table?.Rows?.Count ?? 0;
 				_scrollBar.Position = tableView.RowOffset;
 				//	_scrollBar.OtherScrollBarView.Size = _listView.Maxlength - 1;

+ 1 - 1
UICatalog/Scenarios/Text.cs

@@ -56,7 +56,7 @@ namespace UICatalog.Scenarios {
 			textView.DrawContent += TextView_DrawContent;
 
 			// This shows how to enable autocomplete in TextView.
-			void TextView_DrawContent (Rect e)
+			void TextView_DrawContent (object sender, DrawEventArgs e)
 			{
 				textView.Autocomplete.AllSuggestions = Regex.Matches (textView.Text.ToString (), "\\w+")
 					.Select (s => s.Value)

+ 5 - 5
UICatalog/Scenarios/TextViewAutocompletePopup.cs

@@ -126,27 +126,27 @@ namespace UICatalog.Scenarios {
 				.Distinct ().ToList ();
 		}
 
-		private void TextViewCentered_DrawContent (Rect obj)
+		private void TextViewCentered_DrawContent (object sender, DrawEventArgs e)
 		{
 			SetAllSuggestions (textViewCentered);
 		}
 
-		private void TextViewBottomRight_DrawContent (Rect obj)
+		private void TextViewBottomRight_DrawContent (object sender, DrawEventArgs e)
 		{
 			SetAllSuggestions (textViewBottomRight);
 		}
 
-		private void TextViewBottomLeft_DrawContent (Rect obj)
+		private void TextViewBottomLeft_DrawContent (object sender, DrawEventArgs e)
 		{
 			SetAllSuggestions (textViewBottomLeft);
 		}
 
-		private void TextViewTopRight_DrawContent (Rect obj)
+		private void TextViewTopRight_DrawContent (object sender, DrawEventArgs e)
 		{
 			SetAllSuggestions (textViewTopRight);
 		}
 
-		private void TextViewTopLeft_DrawContent (Rect obj)
+		private void TextViewTopLeft_DrawContent (object sender, DrawEventArgs e)
 		{
 			SetAllSuggestions (textViewTopLeft);
 		}

+ 1 - 1
UICatalog/Scenarios/TreeViewFileSystem.cs

@@ -220,7 +220,7 @@ namespace UICatalog.Scenarios {
 				treeViewFiles.SetNeedsDisplay ();
 			};
 
-			treeViewFiles.DrawContent += (e) => {
+			treeViewFiles.DrawContent += (s,e) => {
 				_scrollBar.Size = treeViewFiles.ContentHeight;
 				_scrollBar.Position = treeViewFiles.ScrollOffsetVertical;
 				_scrollBar.OtherScrollBarView.Size = treeViewFiles.GetContentWidth (true);

+ 1 - 1
UICatalog/Scenarios/Wizards.cs

@@ -253,7 +253,7 @@ namespace UICatalog.Scenarios {
 						}
 					};
 
-					someText.DrawContent += (e) => {
+					someText.DrawContent += (s,e) => {
 						scrollBar.Size = someText.Lines;
 						scrollBar.Position = someText.TopRow;
 						if (scrollBar.OtherScrollBarView != null) {

+ 1 - 1
UnitTests/Core/LineCanvasTests.cs

@@ -330,7 +330,7 @@ namespace Terminal.Gui.CoreTests {
 			};
 
 			var canvasCopy = canvas = new LineCanvas ();
-			v.DrawContentComplete += (r) => {
+			v.DrawContentComplete += (s, e) => {
 					foreach(var p in canvasCopy.GenerateImage(v.Bounds))
 					{
 						v.AddRune(

+ 7 - 7
UnitTests/Core/ViewTests.cs

@@ -1655,7 +1655,7 @@ namespace Terminal.Gui.CoreTests {
 		{
 			var view = new View (new Rect (0, 0, 8, 4));
 
-			view.DrawContent += (_) => view.DrawFrame (view.Bounds, 0, true);
+			view.DrawContent += (s, e) => view.DrawFrame (view.Bounds, 0, true);
 
 			Assert.Equal (Point.Empty, new Point (view.Frame.X, view.Frame.Y));
 			Assert.Equal (new Size (8, 4), new Size (view.Frame.Width, view.Frame.Height));
@@ -1679,7 +1679,7 @@ namespace Terminal.Gui.CoreTests {
 		{
 			var view = new View (new Rect (0, 0, 2, 2));
 
-			view.DrawContent += (_) => view.DrawFrame (view.Bounds, 0, true);
+			view.DrawContent += (s, e) => view.DrawFrame (view.Bounds, 0, true);
 
 			Assert.Equal (Point.Empty, new Point (view.Frame.X, view.Frame.Y));
 			Assert.Equal (new Size (2, 2), new Size (view.Frame.Width, view.Frame.Height));
@@ -1701,7 +1701,7 @@ namespace Terminal.Gui.CoreTests {
 		{
 			var view = new View (new Rect (-1, 0, 8, 4));
 
-			view.DrawContent += (_) => view.DrawFrame (view.Bounds, 0, true);
+			view.DrawContent += (s, e) => view.DrawFrame (view.Bounds, 0, true);
 
 			Assert.Equal (new Point (-1, 0), new Point (view.Frame.X, view.Frame.Y));
 			Assert.Equal (new Size (8, 4), new Size (view.Frame.Width, view.Frame.Height));
@@ -2025,7 +2025,7 @@ namespace Terminal.Gui.CoreTests {
 				Width = Dim.Fill (),
 				Height = Dim.Fill ()
 			};
-			view.DrawContent += e => {
+			view.DrawContent += (s,e) => {
 				view.DrawFrame (view.Bounds);
 				var savedClip = Application.Driver.Clip;
 				Application.Driver.Clip = new Rect (1, 1, view.Bounds.Width - 2, view.Bounds.Height - 2);
@@ -2073,7 +2073,7 @@ namespace Terminal.Gui.CoreTests {
 				Width = Dim.Fill (),
 				Height = Dim.Fill ()
 			};
-			view.DrawContent += e => {
+			view.DrawContent += (s,e) => {
 				view.DrawFrame (view.Bounds);
 				var savedClip = Application.Driver.Clip;
 				Application.Driver.Clip = new Rect (1, 1, view.Bounds.Width - 2, view.Bounds.Height - 2);
@@ -2268,9 +2268,9 @@ This is a tes
 			var tvCalled = false;
 
 			var view = new View ("View") { Width = 10, Height = 10 };
-			view.DrawContentComplete += (e) => viewCalled = true;
+			view.DrawContentComplete += (s,e) => viewCalled = true;
 			var tv = new TextView () { Y = 11, Width = 10, Height = 10 };
-			tv.DrawContentComplete += (e) => tvCalled = true;
+			tv.DrawContentComplete += (s, e) => tvCalled = true;
 
 			Application.Top.Add (view, tv);
 			Application.Begin (Application.Top);

+ 4 - 4
UnitTests/Views/ScrollBarViewTests.cs

@@ -76,7 +76,7 @@ namespace Terminal.Gui.ViewTests {
 			_added = false;
 		}
 
-		private void _hostView_DrawContent (Rect obj)
+		private void _hostView_DrawContent (object sender, DrawEventArgs e)
 		{
 			_scrollBar.Size = _hostView.Lines;
 			_scrollBar.Position = _hostView.Top;
@@ -487,7 +487,7 @@ namespace Terminal.Gui.ViewTests {
 					listView.SetNeedsDisplay ();
 				};
 
-				listView.DrawContent += (e) => {
+				listView.DrawContent += (s,e) => {
 					newScrollBarView.Size = listView.Source.Count;
 					Assert.Equal (newScrollBarView.Size, listView.Source.Count);
 					newScrollBarView.Position = listView.TopItem;
@@ -562,7 +562,7 @@ namespace Terminal.Gui.ViewTests {
 					listView.SetNeedsDisplay ();
 				};
 
-				listView.DrawContent += (e) => {
+				listView.DrawContent += (s,e) => {
 					newScrollBarView.Size = listView.Maxlength;
 					Assert.Equal (newScrollBarView.Size, listView.Maxlength);
 					newScrollBarView.Position = listView.LeftItem;
@@ -684,7 +684,7 @@ namespace Terminal.Gui.ViewTests {
 				}
 			};
 
-			textView.DrawContent += (e) => {
+			textView.DrawContent += (s,e) => {
 				scrollBar.Size = textView.Lines;
 				scrollBar.Position = textView.TopRow;
 				if (scrollBar.OtherScrollBarView != null) {