2
0
Эх сурвалжийг харах

Added some more improvements.

BDisp 2 жил өмнө
parent
commit
250ebd3f97

+ 8 - 3
Terminal.Gui/ConsoleDrivers/WindowsDriver.cs

@@ -1435,11 +1435,16 @@ namespace Terminal.Gui {
 			crow = row;
 		}
 
+		int GetOutputBufferPosition ()
+		{
+			return crow * Cols + ccol;
+		}
+
 		public override void AddRune (Rune rune)
 		{
 			rune = MakePrintable (rune);
 			var runeWidth = Rune.ColumnWidth (rune);
-			var position = crow * Cols + ccol;
+			var position = GetOutputBufferPosition ();
 			var validClip = IsValidContent (ccol, crow, Clip);
 
 			if (validClip) {
@@ -1453,7 +1458,7 @@ namespace Terminal.Gui {
 				} else if (runeWidth < 2 && ccol <= Clip.Right - 1
 					&& Rune.ColumnWidth ((char)contents [crow, ccol, 0]) > 1) {
 
-					var prevPosition = crow * Cols + ccol + 1;
+					var prevPosition = GetOutputBufferPosition () + 1;
 					OutputBuffer [prevPosition].Char.UnicodeChar = (char)' ';
 					contents [crow, ccol + 1, 0] = (int)(uint)' ';
 
@@ -1474,7 +1479,7 @@ namespace Terminal.Gui {
 			ccol++;
 			if (runeWidth > 1) {
 				if (validClip && ccol < Clip.Right) {
-					position = crow * Cols + ccol;
+					position = GetOutputBufferPosition ();
 					OutputBuffer [position].Attributes = (ushort)currentAttribute;
 					OutputBuffer [position].Char.UnicodeChar = (char)0x00;
 					contents [crow, ccol, 0] = (int)(uint)0x00;

+ 17 - 11
Terminal.Gui/Core/TextFormatter.cs

@@ -1182,10 +1182,22 @@ namespace Terminal.Gui {
 			}
 
 			var isVertical = IsVerticalDirection (textDirection);
+			var savedClip = Application.Driver?.Clip;
+			var maxBounds = bounds;
+			if (Application.Driver != null) {
+				Application.Driver.Clip = maxBounds = containerBounds == default
+					? bounds
+					: new Rect (Math.Max (containerBounds.X, bounds.X),
+					Math.Max (containerBounds.Y, bounds.Y),
+					Math.Max (Math.Min (containerBounds.Width, containerBounds.Right - bounds.Left), 0),
+					Math.Max (Math.Min (containerBounds.Height, containerBounds.Bottom - bounds.Top), 0));
+			}
 
 			for (int line = 0; line < linesFormated.Count; line++) {
 				if ((isVertical && line > bounds.Width) || (!isVertical && line > bounds.Height))
 					continue;
+				if ((isVertical && line > maxBounds.Left + maxBounds.Width - bounds.X) || (!isVertical && line > maxBounds.Top + maxBounds.Height - bounds.Y))
+					break;
 
 				var runes = lines [line].ToRunes ();
 
@@ -1262,15 +1274,6 @@ namespace Terminal.Gui {
 				var start = isVertical ? bounds.Top : bounds.Left;
 				var size = isVertical ? bounds.Height : bounds.Width;
 				var current = start;
-				var savedClip = Application.Driver?.Clip;
-				if (Application.Driver != null) {
-					Application.Driver.Clip = containerBounds == default
-						? bounds
-						: new Rect (Math.Max (containerBounds.X, bounds.X),
-						Math.Max (containerBounds.Y, bounds.Y),
-						Math.Max (Math.Min (containerBounds.Width, containerBounds.Right - bounds.Left), 0),
-						Math.Max (Math.Min (containerBounds.Height, containerBounds.Bottom - bounds.Top), 0));
-				}
 
 				for (var idx = (isVertical ? start - y : start - x); current < start + size; idx++) {
 					if (!fillRemaining && idx < 0) {
@@ -1279,6 +1282,9 @@ namespace Terminal.Gui {
 					} else if (!fillRemaining && idx > runes.Length - 1) {
 						break;
 					}
+					if ((!isVertical && idx > maxBounds.Left + maxBounds.Width - bounds.X) || (isVertical && idx > maxBounds.Top + maxBounds.Height - bounds.Y))
+						break;
+
 					var rune = (Rune)' ';
 					if (isVertical) {
 						Application.Driver?.Move (x, current);
@@ -1313,9 +1319,9 @@ namespace Terminal.Gui {
 						break;
 					}
 				}
-				if (Application.Driver != null)
-					Application.Driver.Clip = (Rect)savedClip;
 			}
+			if (Application.Driver != null)
+				Application.Driver.Clip = (Rect)savedClip;
 		}
 	}
 }

+ 58 - 60
Terminal.Gui/Core/View.cs

@@ -348,7 +348,7 @@ namespace Terminal.Gui {
 				}
 				if (base.CanFocus != value) {
 					base.CanFocus = value;
-					
+
 					switch (value) {
 					case false when tabIndex > -1:
 						TabIndex = -1;
@@ -357,7 +357,7 @@ namespace Terminal.Gui {
 						SuperView.CanFocus = true;
 						break;
 					}
-					
+
 					if (value && tabIndex == -1) {
 						TabIndex = SuperView != null ? SuperView.tabIndexes.IndexOf (this) : -1;
 					}
@@ -881,10 +881,10 @@ namespace Terminal.Gui {
 				NeedDisplay = new Rect (x, y, w, h);
 			}
 			container?.SetChildNeedsDisplay ();
-			
+
 			if (subviews == null)
 				return;
-			
+
 			foreach (var view in subviews)
 				if (view.Frame.IntersectsWith (region)) {
 					var childRegion = Rect.Intersect (view.Frame, region);
@@ -1132,7 +1132,7 @@ namespace Terminal.Gui {
 			// Computes the real row, col relative to the screen.
 			rrow = row + frame.Y;
 			rcol = col + frame.X;
-			
+
 			var curContainer = container;
 			while (curContainer != null) {
 				rrow += curContainer.frame.Y;
@@ -1303,7 +1303,7 @@ namespace Terminal.Gui {
 		}
 
 		bool hasFocus;
-		
+
 		/// <inheritdoc/>
 		public override bool HasFocus => hasFocus;
 
@@ -1495,14 +1495,17 @@ namespace Terminal.Gui {
 
 			if (Border != null) {
 				Border.DrawContent (this);
-			} else if ((GetType ().IsPublic || GetType ().IsNestedPublic) && !IsOverridden (this, "Redraw") &&
+			} else if (ustring.IsNullOrEmpty (TextFormatter.Text) &&
+				(GetType ().IsPublic || GetType ().IsNestedPublic) && !IsOverridden (this, "Redraw") &&
 				(!NeedDisplay.IsEmpty || ChildNeedsDisplay || LayoutNeeded)) {
 
 				Clear ();
+				SetChildNeedsDisplay ();
 			}
 
 			if (!ustring.IsNullOrEmpty (TextFormatter.Text)) {
 				Clear ();
+				SetChildNeedsDisplay ();
 				// Draw any Text
 				if (TextFormatter != null) {
 					TextFormatter.NeedsFormat = true;
@@ -1694,7 +1697,7 @@ namespace Terminal.Gui {
 				if (args.Handled)
 					return true;
 			}
-			
+
 			return Focused?.Enabled == true && Focused?.ProcessKey (keyEvent) == true;
 		}
 
@@ -1870,7 +1873,7 @@ namespace Terminal.Gui {
 				return true;
 			if (subviews == null || subviews.Count == 0)
 				return false;
-			
+
 			foreach (var view in subviews)
 				if (view.Enabled && view.ProcessHotKey (keyEvent))
 					return true;
@@ -1897,7 +1900,7 @@ namespace Terminal.Gui {
 				return true;
 			if (subviews == null || subviews.Count == 0)
 				return false;
-			
+
 			foreach (var view in subviews)
 				if (view.Enabled && view.ProcessColdKey (keyEvent))
 					return true;
@@ -2043,7 +2046,7 @@ namespace Terminal.Gui {
 				FocusLast ();
 				return focused != null;
 			}
-			
+
 			var focusedIdx = -1;
 			for (var i = tabIndexes.Count; i > 0;) {
 				i--;
@@ -2153,7 +2156,7 @@ namespace Terminal.Gui {
 				actX = x.Anchor (hostFrame.Width - actW);
 			} else {
 				actX = x?.Anchor (hostFrame.Width) ?? 0;
-				
+
 				switch (width) {
 				case null:
 					actW = AutoSize ? s.Width : hostFrame.Width;
@@ -2179,7 +2182,7 @@ namespace Terminal.Gui {
 				actY = y.Anchor (hostFrame.Height - actH);
 			} else {
 				actY = y?.Anchor (hostFrame.Height) ?? 0;
-				
+
 				switch (height) {
 				case null:
 					actH = AutoSize ? s.Height : hostFrame.Height;
@@ -2194,7 +2197,7 @@ namespace Terminal.Gui {
 					break;
 				}
 			}
-			
+
 			var r = new Rect (actX, actY, actW, actH);
 			if (Frame != r) {
 				Frame = new Rect (actX, actY, actW, actH);
@@ -2325,48 +2328,44 @@ namespace Terminal.Gui {
 			void CollectPos (Pos pos, View from, ref HashSet<View> nNodes, ref HashSet<(View, View)> nEdges)
 			{
 				switch (pos) {
-				case Pos.PosView pv:
-				{
-					if (pv.Target != this) {
-						nEdges.Add ((pv.Target, from));
-					}
-					foreach (var v in from.InternalSubviews) {
-						CollectAll (v, ref nNodes, ref nEdges);
+				case Pos.PosView pv: {
+						if (pv.Target != this) {
+							nEdges.Add ((pv.Target, from));
+						}
+						foreach (var v in from.InternalSubviews) {
+							CollectAll (v, ref nNodes, ref nEdges);
+						}
+						return;
 					}
-					return;
-				}
-				case Pos.PosCombine pc:
-				{
-					foreach (var v in from.InternalSubviews) {
-						CollectPos (pc.left, from, ref nNodes, ref nEdges);
-						CollectPos (pc.right, from, ref nNodes, ref nEdges);
+				case Pos.PosCombine pc: {
+						foreach (var v in from.InternalSubviews) {
+							CollectPos (pc.left, from, ref nNodes, ref nEdges);
+							CollectPos (pc.right, from, ref nNodes, ref nEdges);
+						}
+						break;
 					}
-					break;
-				}
 				}
 			}
 
 			void CollectDim (Dim dim, View from, ref HashSet<View> nNodes, ref HashSet<(View, View)> nEdges)
 			{
 				switch (dim) {
-				case Dim.DimView dv:
-				{
-					if (dv.Target != this) {
-						nEdges.Add ((dv.Target, from));
-					}
-					foreach (var v in from.InternalSubviews) {
-						CollectAll (v, ref nNodes, ref nEdges);
+				case Dim.DimView dv: {
+						if (dv.Target != this) {
+							nEdges.Add ((dv.Target, from));
+						}
+						foreach (var v in from.InternalSubviews) {
+							CollectAll (v, ref nNodes, ref nEdges);
+						}
+						return;
 					}
-					return;
-				}
-				case Dim.DimCombine dc:
-				{
-					foreach (var v in from.InternalSubviews) {
-						CollectDim (dc.left, from, ref nNodes, ref nEdges);
-						CollectDim (dc.right, from, ref nNodes, ref nEdges);
+				case Dim.DimCombine dc: {
+						foreach (var v in from.InternalSubviews) {
+							CollectDim (dc.left, from, ref nNodes, ref nEdges);
+							CollectDim (dc.right, from, ref nNodes, ref nEdges);
+						}
+						break;
 					}
-					break;
-				}
 				}
 			}
 
@@ -2759,14 +2758,14 @@ namespace Terminal.Gui {
 			/// The <see cref="MouseEvent"/> for the event.
 			/// </summary>
 			public MouseEvent MouseEvent { get; set; }
-			
+
 			/// <summary>
 			/// Indicates if the current mouse event has already been processed and the driver should stop notifying any other event subscriber.
 			/// Its important to set this value to true specially when updating any View's layout from inside the subscriber method.
 			/// </summary>
 			/// <remarks>This property forwards to the <see cref="MouseEvent.Handled"/> property and is provided as a convenience and for
 			/// backwards compatibility</remarks>
-			public bool Handled { 
+			public bool Handled {
 				get => MouseEvent.Handled;
 				set => MouseEvent.Handled = value;
 			}
@@ -2785,7 +2784,7 @@ namespace Terminal.Gui {
 
 			var args = new MouseEventArgs (mouseEvent);
 			MouseEnter?.Invoke (args);
-			
+
 			return args.Handled || base.OnMouseEnter (mouseEvent);
 		}
 
@@ -2802,7 +2801,7 @@ namespace Terminal.Gui {
 
 			var args = new MouseEventArgs (mouseEvent);
 			MouseLeave?.Invoke (args);
-			
+
 			return args.Handled || base.OnMouseLeave (mouseEvent);
 		}
 
@@ -2955,17 +2954,16 @@ namespace Terminal.Gui {
 				h = Height.Anchor (h);
 				canSetHeight = !ForceValidatePosDim;
 				break;
-			case Dim.DimFactor factor:
-			{
-				// Tries to get the SuperView height otherwise the view height.
-				var sh = SuperView != null ? SuperView.Frame.Height : h;
-				if (factor.IsFromRemaining ()) {
-					sh -= Frame.Y;
+			case Dim.DimFactor factor: {
+					// Tries to get the SuperView height otherwise the view height.
+					var sh = SuperView != null ? SuperView.Frame.Height : h;
+					if (factor.IsFromRemaining ()) {
+						sh -= Frame.Y;
+					}
+					h = Height.Anchor (sh);
+					canSetHeight = !ForceValidatePosDim;
+					break;
 				}
-				h = Height.Anchor (sh);
-				canSetHeight = !ForceValidatePosDim;
-				break;
-			}
 			default:
 				canSetHeight = true;
 				break;

+ 0 - 6
Terminal.Gui/Core/Window.cs

@@ -303,12 +303,6 @@ namespace Terminal.Gui {
 			if (Border.DrawMarginFrame)
 				Driver.DrawWindowTitle (scrRect, Title, padding.Left, padding.Top, padding.Right, padding.Bottom);
 			Driver.SetAttribute (GetNormalColor ());
-
-			// Checks if there are any SuperView view which intersect with this window.
-			if (SuperView != null) {
-				SuperView.SetNeedsLayout ();
-				SuperView.SetNeedsDisplay ();
-			}
 		}
 
 		/// <inheritdoc/>

+ 14 - 0
UICatalog/Properties/launchSettings.json

@@ -26,6 +26,20 @@
     "Issue1719Repro": {
       "commandName": "Project",
       "commandLineArgs": "\"ProgressBar Styles\""
+    },
+    "WSL2": {
+      "commandName": "Executable",
+      "executablePath": "wsl",
+      "commandLineArgs": "dotnet UICatalog.dll"
+    },
+    "WSL2 : -usc": {
+      "commandName": "Executable",
+      "executablePath": "wsl",
+      "commandLineArgs": "dotnet UICatalog.dll -usc"
+    },
+    "WSL": {
+      "commandName": "WSL2",
+      "distributionName": ""
     }
   }
 }

+ 23 - 14
UICatalog/Scenarios/Scrolling.cs

@@ -105,8 +105,8 @@ namespace UICatalog.Scenarios {
 		{
 			Win.X = 3;
 			Win.Y = 3;
-			Win.Width = Dim.Fill () - 3;
-			Win.Height = Dim.Fill () - 3;
+			Win.Width = Dim.Fill (3);
+			Win.Height = Dim.Fill (3);
 			var label = new Label ("ScrollView (new Rect (2, 2, 50, 20)) with a 200, 100 ContentSize...") {
 				X = 0,
 				Y = 0,
@@ -128,6 +128,7 @@ namespace UICatalog.Scenarios {
 			};
 
 			const string rule = "0123456789";
+
 			var horizontalRuler = new Label () {
 				X = 0,
 				Y = 0,
@@ -137,6 +138,7 @@ namespace UICatalog.Scenarios {
 				AutoSize = false
 			};
 			scrollView.Add (horizontalRuler);
+
 			const string vrule = "0\n1\n2\n3\n4\n5\n6\n7\n8\n9\n";
 
 			var verticalRuler = new Label () {
@@ -152,7 +154,7 @@ namespace UICatalog.Scenarios {
 			void Top_Loaded ()
 			{
 				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)];
+					"\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)];
 				Top.Loaded -= Top_Loaded;
 			}
@@ -168,7 +170,7 @@ namespace UICatalog.Scenarios {
 			var aLongButton = new Button ("A very long button. Should be wide enough to demo clipping!") {
 				X = 3,
 				Y = 4,
-				Width = Dim.Fill (6),
+				Width = Dim.Fill (3),
 			};
 			aLongButton.Clicked += () => MessageBox.Query (20, 7, "MessageBox", "Neat?", "Yes", "No");
 			scrollView.Add (aLongButton);
@@ -210,6 +212,8 @@ namespace UICatalog.Scenarios {
 			};
 			scrollView.Add (anchorButton);
 
+			Win.Add (scrollView);
+
 			var hCheckBox = new CheckBox ("Horizontal Scrollbar", scrollView.ShowHorizontalScrollIndicator) {
 				X = Pos.X (scrollView),
 				Y = Pos.Bottom (scrollView) + 1,
@@ -269,6 +273,7 @@ namespace UICatalog.Scenarios {
 			scrollView2.DrawContent += (r) => {
 				scrollView2.ContentSize = filler.GetContentSize ();
 			};
+			Win.Add (scrollView2);
 
 			// This is just to debug the visuals of the scrollview when small
 			var scrollView3 = new ScrollView (new Rect (55, 15, 3, 3)) {
@@ -277,20 +282,26 @@ namespace UICatalog.Scenarios {
 				ShowHorizontalScrollIndicator = true
 			};
 			scrollView3.Add (new Box10x (0, 0));
+			Win.Add (scrollView3);
 
 			int count = 0;
-			var mousePos = new Label ("Mouse: ");
-			mousePos.X = Pos.Right (scrollView) + 1;
-			mousePos.Y = Pos.AnchorEnd (1);
-			mousePos.Width = 50;
+			var mousePos = new Label ("Mouse: ") {
+				X = Pos.Right (scrollView) + 1,
+				Y = Pos.AnchorEnd (1),
+				Width = 50,
+			};
+			Win.Add (mousePos);
 			Application.RootMouseEvent += delegate (MouseEvent me) {
 				mousePos.Text = $"Mouse: ({me.X},{me.Y}) - {me.Flags} {count++}";
 			};
 
-			var progress = new ProgressBar ();
-			progress.X = Pos.Right (scrollView) + 1;
-			progress.Y = Pos.AnchorEnd (2);
-			progress.Width = 50;
+			var progress = new ProgressBar {
+				X = Pos.Right (scrollView) + 1,
+				Y = Pos.AnchorEnd (2),
+				Width = 50
+			};
+			Win.Add (progress);
+
 			bool pulsing = true;
 			bool timer (MainLoop caller)
 			{
@@ -305,8 +316,6 @@ namespace UICatalog.Scenarios {
 				Top.Unloaded -= Top_Unloaded;
 			}
 			Top.Unloaded += Top_Unloaded;
-
-			Win.Add (scrollView, scrollView2, scrollView3, mousePos, progress);
 		}
 	}
 }