浏览代码

Fixed backward bug and added one more unit test to probe.

BDisp 4 年之前
父节点
当前提交
351cb8133f
共有 3 个文件被更改,包括 28 次插入2 次删除
  1. 1 1
      Terminal.Gui/Core/View.cs
  2. 1 1
      Terminal.Gui/Views/ScrollBarView.cs
  3. 26 0
      UnitTests/ScrollBarViewTests.cs

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

@@ -1342,8 +1342,8 @@ namespace Terminal.Gui {
 							// Draw the subview
 							// Draw the subview
 							// Use the view's bounds (view-relative; Location will always be (0,0)
 							// Use the view's bounds (view-relative; Location will always be (0,0)
 							if (view.Visible && view.Frame.Width > 0 && view.Frame.Height > 0) {
 							if (view.Visible && view.Frame.Width > 0 && view.Frame.Height > 0) {
-								view.OnDrawContent (view.Bounds);
 								view.Redraw (view.Bounds);
 								view.Redraw (view.Bounds);
+								view.OnDrawContent (view.Bounds);
 							}
 							}
 						}
 						}
 						view.NeedDisplay = Rect.Empty;
 						view.NeedDisplay = Rect.Empty;

+ 1 - 1
Terminal.Gui/Views/ScrollBarView.cs

@@ -137,7 +137,7 @@ namespace Terminal.Gui {
 						if (max > 0 && max == value - position) {
 						if (max > 0 && max == value - position) {
 							position = value;
 							position = value;
 						} else {
 						} else {
-							position = Math.Max (max, 0);
+							position = Math.Max (position + max, 0);
 						}
 						}
 					}
 					}
 					OnChangedPosition ();
 					OnChangedPosition ();

+ 26 - 0
UnitTests/ScrollBarViewTests.cs

@@ -146,6 +146,32 @@ namespace Terminal.Gui {
 			Assert.Equal (_horizontal.Position, _hostView.Left);
 			Assert.Equal (_horizontal.Position, _hostView.Left);
 		}
 		}
 
 
+		[Fact]
+		public void ChangedPosition_Scrolling ()
+		{
+			Hosting_A_View_To_A_ScrollBarView ();
+
+			AddHandlers ();
+
+			for (int i = 0; i < _vertical.Size; i++) {
+				_vertical.Position += 1;
+				Assert.Equal (_vertical.Position, _hostView.Top);
+			}
+			for (int i = _vertical.Size - 1; i >= 0; i--) {
+				_vertical.Position -= 1;
+				Assert.Equal (_vertical.Position, _hostView.Top);
+			}
+
+			for (int i = 0; i < _horizontal.Size; i++) {
+				_horizontal.Position += i;
+				Assert.Equal (_horizontal.Position, _hostView.Left);
+			}
+			for (int i = _horizontal.Size - 1; i >= 0; i--) {
+				_horizontal.Position -= 1;
+				Assert.Equal (_horizontal.Position, _hostView.Left);
+			}
+		}
+
 		[Fact]
 		[Fact]
 		public void ChangedPosition_Negative_Value ()
 		public void ChangedPosition_Negative_Value ()
 		{
 		{