Browse Source

Merge branch 'v2_develop' of tig:gui-cs/Terminal.Gui into v2_develop

Tigger Kindel 2 years ago
parent
commit
98aab602eb

+ 0 - 17
Terminal.Gui/Drawing/Ruler.cs

@@ -64,21 +64,4 @@ namespace Terminal.Gui {
 			}
 		}
 	}
-
-	internal static class StringExtensions {
-		public static string Repeat (this string instr, int n)
-		{
-			if (n <= 0) {
-				return null;
-			}
-
-			if (string.IsNullOrEmpty (instr) || n == 1) {
-				return instr;
-			}
-
-			return new StringBuilder (instr.Length * n)
-				.Insert (0, instr, n)
-				.ToString ();
-		}
-	}
 }

+ 32 - 0
Terminal.Gui/StringExtensions.cs

@@ -0,0 +1,32 @@
+using System.Text;
+
+namespace Terminal.Gui {
+	/// <summary>
+	/// Extension helper of <see cref="System.String"/> to work with specific text manipulation./>
+	/// </summary>
+	public static class StringExtensions {
+		/// <summary>
+		/// Repeats the <paramref name="instr"/> <paramref name="n"/>  times.
+		/// </summary>
+		/// <param name="instr">The text to repeat.</param>
+		/// <param name="n">Number of times to repeat the text.</param>
+		/// <returns>
+		///  The text repeated if <paramref name="n"/> is greater than zero, 
+		///  otherwise <see langword="null"/>.
+		/// </returns>
+		public static string Repeat (this string instr, int n)
+		{
+			if (n <= 0) {
+				return null;
+			}
+
+			if (string.IsNullOrEmpty (instr) || n == 1) {
+				return instr;
+			}
+
+			return new StringBuilder (instr.Length * n)
+				.Insert (0, instr, n)
+				.ToString ();
+		}
+	}
+}

+ 3 - 0
Terminal.Gui/View/View.cs

@@ -2658,12 +2658,15 @@ namespace Terminal.Gui {
 						}
 						edges.Remove ((from, to));
 					} else if (from.SuperView == to.SuperView) {
+						// if 'from' is not yet added to the result, add it
 						if (result.Find (v => v == from) == null) {
 							result.Add (from);
 						}
+						// if 'to' is not yet added to the result, add it
 						if (result.Find (v => v == to) == null) {
 							result.Add (to);
 						}
+						// remove from edge
 						edges.Remove ((from, to));
 					} else if (from != superView?.GetTopSuperView (to, from) && !ReferenceEquals (from, to)) {
 						if (ReferenceEquals (from.SuperView, to)) {

+ 16 - 43
UICatalog/Scenarios/ComputedLayout.cs

@@ -54,7 +54,7 @@ namespace UICatalog.Scenarios {
 
 			Application.Top.LayoutComplete += (s, a) => {
 				horizontalRuler.Text = rule.Repeat ((int)Math.Ceiling ((double)(horizontalRuler.Bounds.Width) / (double)rule.Length)) [0..(horizontalRuler.Bounds.Width)];
-				verticalRuler.Text = vrule.Repeat ((int)Math.Ceiling ((double)(verticalRuler.Bounds.Height * 2) / (double)rule.Length)) [0..(verticalRuler.Bounds.Height*2)];
+				verticalRuler.Text = vrule.Repeat ((int)Math.Ceiling ((double)(verticalRuler.Bounds.Height * 2) / (double)rule.Length)) [0..(verticalRuler.Bounds.Height * 2)];
 			};
 
 			Application.Top.Add (verticalRuler);
@@ -66,7 +66,7 @@ namespace UICatalog.Scenarios {
 			};
 			Application.Top.Add (atButton);
 
-			// Throw in a literal absolute - Should funciton identically to above
+			// Throw in a literal absolute - Should function identically to above
 			var absoluteButton = new Button ("X = 30, Y = 1") {
 				X = 30,
 				Y = 1
@@ -81,7 +81,7 @@ namespace UICatalog.Scenarios {
 				Width = Dim.Fill (margin),
 				Height = 7
 			};
-			subWin.Title = $"{subWin.GetType().Name} {{X={subWin.X},Y={subWin.Y},Width={subWin.Width},Height={subWin.Height}}}";
+			subWin.Title = $"{subWin.GetType ().Name} {{X={subWin.X},Y={subWin.Y},Width={subWin.Width},Height={subWin.Height}}}";
 			Application.Top.Add (subWin);
 
 			int i = 1;
@@ -95,7 +95,7 @@ namespace UICatalog.Scenarios {
 			subWin.Add (labelList.ToArray ());
 
 			var frameView = new FrameView () {
-				X = 2, 
+				X = 2,
 				Y = Pos.Bottom (subWin),
 				Width = 30,
 				Height = 7
@@ -112,9 +112,9 @@ namespace UICatalog.Scenarios {
 			Application.Top.Add (frameView);
 
 			frameView = new FrameView () {
-				X = Pos.Right(frameView),
+				X = Pos.Right (frameView),
 				Y = Pos.Top (frameView),
-				Width = Dim.Fill(),
+				Width = Dim.Fill (),
 				Height = 7,
 			};
 			frameView.Title = $"{frameView.GetType ().Name} {{X={frameView.X},Y={frameView.Y},Width={frameView.Width},Height={frameView.Height}}}";
@@ -168,7 +168,7 @@ namespace UICatalog.Scenarios {
 			// This demonstrates nonsense: it the same as using Pos.AnchorEnd (100/2=50 + 100/2=50 = 100 - 50)
 			// The `- Pos.Percent(5)` is there so at least something is visible
 			oddballButton = new Button ("Center + Center - Percent(50)") {
-				X = Pos.Center () + Pos.Center () - Pos.Percent(50),
+				X = Pos.Center () + Pos.Center () - Pos.Percent (50),
 				Y = Pos.Bottom (oddballButton)
 			};
 			Application.Top.Add (oddballButton);
@@ -199,7 +199,7 @@ namespace UICatalog.Scenarios {
 
 			// This demonstrates combining Percents)
 			oddballButton = new Button ("Percent(40) + Percent(10)") {
-				X = Pos.Percent (40) + Pos.Percent(10),
+				X = Pos.Percent (40) + Pos.Percent (10),
 				Y = Pos.Bottom (oddballButton)
 			};
 			Application.Top.Add (oddballButton);
@@ -209,8 +209,8 @@ namespace UICatalog.Scenarios {
 				Y = Pos.AnchorEnd () - 1,
 			};
 			anchorButton.X = Pos.AnchorEnd () - (Pos.Right (anchorButton) - Pos.Left (anchorButton));
-			anchorButton.Clicked += (s,e) => {
-				// Ths demonstrates how to have a dynamically sized button
+			anchorButton.Clicked += (s, e) => {
+				// This demonstrates how to have a dynamically sized button
 				// Each time the button is clicked the button's text gets longer
 				// The call to Application.Top.LayoutSubviews causes the Computed layout to
 				// get updated. 
@@ -245,8 +245,8 @@ namespace UICatalog.Scenarios {
 			var leftButton = new Button ("Left") {
 				Y = Pos.AnchorEnd () - 1 // Pos.Combine
 			};
-			leftButton.Clicked += (s,e) => {
-				// Ths demonstrates how to have a dynamically sized button
+			leftButton.Clicked += (s, e) => {
+				// This demonstrates how to have a dynamically sized button
 				// Each time the button is clicked the button's text gets longer
 				// The call to Application.Top.LayoutSubviews causes the Computed layout to
 				// get updated. 
@@ -260,8 +260,8 @@ namespace UICatalog.Scenarios {
 				X = Pos.Center (),
 				Y = Pos.AnchorEnd (1)  // Pos.AnchorEnd(1)
 			};
-			centerButton.Clicked += (s,e) => {
-				// Ths demonstrates how to have a dynamically sized button
+			centerButton.Clicked += (s, e) => {
+				// This demonstrates how to have a dynamically sized button
 				// Each time the button is clicked the button's text gets longer
 				// The call to Application.Top.LayoutSubviews causes the Computed layout to
 				// get updated. 
@@ -273,8 +273,8 @@ namespace UICatalog.Scenarios {
 			var rightButton = new Button ("Right") {
 				Y = Pos.Y (centerButton)
 			};
-			rightButton.Clicked += (s,e) => {
-				// Ths demonstrates how to have a dynamically sized button
+			rightButton.Clicked += (s, e) => {
+				// This demonstrates how to have a dynamically sized button
 				// Each time the button is clicked the button's text gets longer
 				// The call to Application.Top.LayoutSubviews causes the Computed layout to
 				// get updated. 
@@ -290,32 +290,5 @@ namespace UICatalog.Scenarios {
 			Application.Top.Add (centerButton);
 			Application.Top.Add (rightButton);
 		}
-
-		public override void Run ()
-		{
-			base.Run ();
-		}
-
-		private void Quit ()
-		{
-			Application.RequestStop ();
-		}
-	}
-
-	internal static class StringExtensions {
-		public static string Repeat (this string instr, int n)
-		{
-			if (n <= 0) {
-				return null;
-			}
-
-			if (string.IsNullOrEmpty (instr) || n == 1) {
-				return instr;
-			}
-
-			return new StringBuilder (instr.Length * n)
-				.Insert (0, instr, n)
-				.ToString ();
-		}
 	}
 }

+ 0 - 1
UICatalog/Scenarios/Scrolling.cs

@@ -154,7 +154,6 @@ namespace UICatalog.Scenarios {
 
 			void Top_Loaded (object sender, EventArgs args)
 			{
-				// BUGBUG: v2 - this broke somehow - fix later
 				horizontalRuler.Text = rule.Repeat ((int)Math.Ceiling ((double)(horizontalRuler.Bounds.Width) / (double)rule.Length)) [0..(horizontalRuler.Bounds.Width)] +
 					"\n" + "|         ".Repeat ((int)Math.Ceiling ((double)(horizontalRuler.Bounds.Width) / (double)rule.Length)) [0..(horizontalRuler.Bounds.Width)];
 				verticalRuler.Text = vrule.Repeat ((int)Math.Ceiling ((double)(verticalRuler.Bounds.Height * 2) / (double)rule.Length)) [0..(verticalRuler.Bounds.Height * 2)];