Ver Fonte

Improving BottomOffset and RightOffset by not relying on CurrentRow and CurrentColumn.

BDisp há 2 anos atrás
pai
commit
cd10fb4cae
1 ficheiros alterados com 26 adições e 8 exclusões
  1. 26 8
      Terminal.Gui/Views/TextView.cs

+ 26 - 8
Terminal.Gui/Views/TextView.cs

@@ -1654,11 +1654,8 @@ namespace Terminal.Gui {
 		public int BottomOffset {
 			get => bottomOffset;
 			set {
-				if (currentRow == Lines - 1 && bottomOffset > 0 && value == 0) {
-					topRow = Math.Max (topRow - bottomOffset, 0);
-				}
+				topRow = AdjustOffset (value);
 				bottomOffset = value;
-				Adjust ();
 			}
 		}
 
@@ -1669,11 +1666,8 @@ namespace Terminal.Gui {
 		public int RightOffset {
 			get => rightOffset;
 			set {
-				if (!wordWrap && currentColumn == GetCurrentLine ().Count && rightOffset > 0 && value == 0) {
-					leftColumn = Math.Max (leftColumn - rightOffset, 0);
-				}
+				leftColumn = AdjustOffset (value, false);
 				rightOffset = value;
-				Adjust ();
 			}
 		}
 
@@ -2710,6 +2704,30 @@ namespace Terminal.Gui {
 			OnUnwrappedCursorPosition ();
 		}
 
+		int AdjustOffset (int valueOffset, bool isRow = true)
+		{
+			var curWrap = isRow ? false : wordWrap;
+			var curLength = isRow ? Lines - 1 : GetCurrentLine ().Count;
+			var curStart = isRow ? topRow : leftColumn;
+			var curOffset = isRow ? bottomOffset : rightOffset;
+			var curSize = isRow ? Frame.Height - valueOffset : Frame.Width - valueOffset;
+			var newStart = curStart;
+
+			if (!curWrap) {
+				if (curStart > 0 && curOffset > 0 && valueOffset == 0) {
+					newStart = Math.Max (curStart - curOffset, 0);
+				} else if (curOffset == 0 && valueOffset > 0) {
+					newStart = Math.Max (Math.Min (curStart + valueOffset, curLength - curSize + 1), 0);
+				}
+
+				if (newStart != curStart) {
+					Application.MainLoop.Invoke (() => SetNeedsDisplay ());
+				}
+			}
+
+			return newStart;
+		}
+
 		/// <summary>
 		/// Event arguments for events for when the contents of the TextView change. E.g. the <see cref="ContentsChanged"/> event.
 		/// </summary>