浏览代码

layoutsubviews not virtual

Charlie Kindel 5 年之前
父节点
当前提交
10f90a7a7a
共有 2 个文件被更改,包括 26 次插入7 次删除
  1. 20 3
      Terminal.Gui/Core/View.cs
  2. 6 4
      Terminal.Gui/Windows/Dialog.cs

+ 20 - 3
Terminal.Gui/Core/View.cs

@@ -1500,6 +1500,22 @@ namespace Terminal.Gui {
 			public Rect OldBounds { get; set; }
 		}
 
+		/// <summary>
+		/// Fired after the Views's <see cref="LayoutSubviews"/> method has completed. 
+		/// </summary>
+		/// <remarks>
+		/// Subscribe to this event to perform tasks when the <see cref="View"/> has been resized or the layout has otherwise changed.
+		/// </remarks>
+		public Action<LayoutEventArgs> LayoutStarted;
+
+		/// <summary>
+		/// Raises the <see cref="LayoutStarted"/> event. Called from  <see cref="LayoutSubviews"/> before any subviews have been laid out.
+		/// </summary>
+		internal virtual void OnLayoutStarted (LayoutEventArgs args)
+		{
+			LayoutStarted?.Invoke (args);
+		}
+
 		/// <summary>
 		/// Fired after the Views's <see cref="LayoutSubviews"/> method has completed. 
 		/// </summary>
@@ -1509,7 +1525,7 @@ namespace Terminal.Gui {
 		public Action<LayoutEventArgs> LayoutComplete;
 
 		/// <summary>
-		/// Raises the <see cref="LayoutComplete"/> event. Called from  <see cref="LayoutSubviews"/> after all sub-views have been laid out.
+		/// Raises the <see cref="LayoutComplete"/> event. Called from  <see cref="LayoutSubviews"/> before all sub-views have been laid out.
 		/// </summary>
 		internal virtual void OnLayoutComplete (LayoutEventArgs args)
 		{
@@ -1528,9 +1544,10 @@ namespace Terminal.Gui {
 			if (!layoutNeeded)
 				return;
 
-			viewText.Size = Bounds.Size;
-
 			Rect oldBounds = Bounds;
+			OnLayoutStarted (new LayoutEventArgs () { OldBounds = oldBounds });
+
+			viewText.Size = Bounds.Size;
 
 			// Sort out the dependencies of the X, Y, Width, Height properties
 			var nodes = new HashSet<View> ();

+ 6 - 4
Terminal.Gui/Windows/Dialog.cs

@@ -61,6 +61,10 @@ namespace Terminal.Gui {
 					Add (b);
 				}
 			}
+
+			LayoutStarted += (args) => {
+				LayoutStartedHandler ();
+			};
 		}
 
 		/// <summary>
@@ -110,8 +114,8 @@ namespace Terminal.Gui {
 			}
 			return buttons.Select (b => b.Bounds.Width).Sum () + buttons.Count() - 1;
 		}
-		///<inheritdoc/>
-		public override void LayoutSubviews ()
+
+		void LayoutStartedHandler ()
 		{
 			int buttonsWidth = GetButtonsWidth ();
 
@@ -122,8 +126,6 @@ namespace Terminal.Gui {
 				button.X = Pos.AnchorEnd (shiftLeft);
 				button.Y = Pos.AnchorEnd (1);
 			}
-
-			base.LayoutSubviews ();
 		}
 
 		///<inheritdoc/>