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

The host only need to pass the real sizes and the ScrollBarView automatically consider the extra line and column.

BDisp 4 жил өмнө
parent
commit
f9f68048a2

+ 30 - 9
Terminal.Gui/Views/ScrollBarView.cs

@@ -93,6 +93,7 @@ namespace Terminal.Gui {
 					Host = host,
 					Host = host,
 					OtherScrollBarView = this,
 					OtherScrollBarView = this,
 				};
 				};
+				OtherScrollBarView.hosted = true;
 				OtherScrollBarView.X = OtherScrollBarView.IsVertical ? Pos.Right (host) - 1 : Pos.Left (host);
 				OtherScrollBarView.X = OtherScrollBarView.IsVertical ? Pos.Right (host) - 1 : Pos.Left (host);
 				OtherScrollBarView.Y = OtherScrollBarView.IsVertical ? Pos.Top (host) : Pos.Bottom (host) - 1;
 				OtherScrollBarView.Y = OtherScrollBarView.IsVertical ? Pos.Top (host) : Pos.Bottom (host) - 1;
 				OtherScrollBarView.Host.SuperView.Add (OtherScrollBarView);
 				OtherScrollBarView.Host.SuperView.Add (OtherScrollBarView);
@@ -108,7 +109,7 @@ namespace Terminal.Gui {
 			contentBottomRightCorner.MouseClick += ContentBottomRightCorner_MouseClick;
 			contentBottomRightCorner.MouseClick += ContentBottomRightCorner_MouseClick;
 		}
 		}
 
 
-		private void ContentBottomRightCorner_MouseClick (MouseEventArgs me)
+		void ContentBottomRightCorner_MouseClick (MouseEventArgs me)
 		{
 		{
 			if (me.MouseEvent.Flags == MouseFlags.WheeledDown || me.MouseEvent.Flags == MouseFlags.WheeledUp
 			if (me.MouseEvent.Flags == MouseFlags.WheeledDown || me.MouseEvent.Flags == MouseFlags.WheeledUp
 				|| me.MouseEvent.Flags == MouseFlags.WheeledRight || me.MouseEvent.Flags == MouseFlags.WheeledLeft) {
 				|| me.MouseEvent.Flags == MouseFlags.WheeledRight || me.MouseEvent.Flags == MouseFlags.WheeledLeft) {
@@ -148,7 +149,11 @@ namespace Terminal.Gui {
 		public int Size {
 		public int Size {
 			get => size;
 			get => size;
 			set {
 			set {
-				size = value;
+				if (hosted || (otherScrollBarView != null && otherScrollBarView.hosted)) {
+					size = value + 1;
+				} else {
+					size = value;
+				}
 				SetNeedsDisplay ();
 				SetNeedsDisplay ();
 			}
 			}
 		}
 		}
@@ -175,6 +180,10 @@ namespace Terminal.Gui {
 					} else if (max < 0) {
 					} else if (max < 0) {
 						position = Math.Max (position + max, 0);
 						position = Math.Max (position + max, 0);
 					}
 					}
+					var s = GetBarsize (vertical);
+					if (position + s == size && (hosted || (otherScrollBarView != null && otherScrollBarView.hosted))) {
+						position++;
+					}
 					OnChangedPosition ();
 					OnChangedPosition ();
 					SetNeedsDisplay ();
 					SetNeedsDisplay ();
 				}
 				}
@@ -293,9 +302,13 @@ namespace Terminal.Gui {
 			OtherScrollBarView.SetRelativeLayout (OtherScrollBarView.Bounds);
 			OtherScrollBarView.SetRelativeLayout (OtherScrollBarView.Bounds);
 
 
 			if (showBothScrollIndicator) {
 			if (showBothScrollIndicator) {
-				contentBottomRightCorner.Visible = true;
-			} else {
-				contentBottomRightCorner.Visible = false;
+				if (contentBottomRightCorner != null) {
+					contentBottomRightCorner.Visible = true;
+				}
+			} else if (!showScrollIndicator) {
+				if (contentBottomRightCorner != null) {
+					contentBottomRightCorner.Visible = false;
+				}
 				if (Application.mouseGrabView != null && Application.mouseGrabView == this) {
 				if (Application.mouseGrabView != null && Application.mouseGrabView == this) {
 					Application.UngrabMouse ();
 					Application.UngrabMouse ();
 				}
 				}
@@ -508,7 +521,7 @@ namespace Terminal.Gui {
 				}
 				}
 			}
 			}
 
 
-			if (hosted && showBothScrollIndicator) {
+			if (contentBottomRightCorner != null && hosted && showBothScrollIndicator) {
 				contentBottomRightCorner.Redraw (contentBottomRightCorner.Bounds);
 				contentBottomRightCorner.Redraw (contentBottomRightCorner.Bounds);
 			}
 			}
 		}
 		}
@@ -627,9 +640,7 @@ namespace Terminal.Gui {
 				max = 0;
 				max = 0;
 				return false;
 				return false;
 			}
 			}
-			var s = isVertical ?
-				(KeepContentAlwaysInViewport ? Host.Bounds.Height + (showBothScrollIndicator ? -2 : -1) : 0) :
-				(KeepContentAlwaysInViewport ? Host.Bounds.Width + (showBothScrollIndicator ? -2 : -1) : 0);
+			int s = GetBarsize (isVertical);
 			var newSize = Math.Max (Math.Min (size - s, position + n), 0);
 			var newSize = Math.Max (Math.Min (size - s, position + n), 0);
 			max = size > s + newSize ? (newSize == 0 ? -position : n) : size - (s + position) - 1;
 			max = size > s + newSize ? (newSize == 0 ? -position : n) : size - (s + position) - 1;
 			if (size >= s + newSize && max != 0) {
 			if (size >= s + newSize && max != 0) {
@@ -637,5 +648,15 @@ namespace Terminal.Gui {
 			}
 			}
 			return false;
 			return false;
 		}
 		}
+
+		int GetBarsize (bool isVertical)
+		{
+			if (Host == null) {
+				return 0;
+			}
+			return isVertical ?
+				(KeepContentAlwaysInViewport ? Host.Bounds.Height + (showBothScrollIndicator ? -2 : -1) : 0) :
+				(KeepContentAlwaysInViewport ? Host.Bounds.Width + (showBothScrollIndicator ? -2 : -1) : 0);
+		}
 	}
 	}
 }
 }

+ 2 - 2
UICatalog/Scenarios/Editor.cs

@@ -89,9 +89,9 @@ namespace UICatalog {
 			};
 			};
 
 
 			_textView.DrawContent += (e) => {
 			_textView.DrawContent += (e) => {
-				_scrollBar.Size = _textView.Lines;
+				_scrollBar.Size = _textView.Lines - 1;
 				_scrollBar.Position = _textView.TopRow;
 				_scrollBar.Position = _textView.TopRow;
-				_scrollBar.OtherScrollBarView.Size = _textView.Maxlength + 1;
+				_scrollBar.OtherScrollBarView.Size = _textView.Maxlength;
 				_scrollBar.OtherScrollBarView.Position = _textView.LeftColumn;
 				_scrollBar.OtherScrollBarView.Position = _textView.LeftColumn;
 				_scrollBar.LayoutSubviews ();
 				_scrollBar.LayoutSubviews ();
 				_scrollBar.Refresh ();
 				_scrollBar.Refresh ();

+ 2 - 2
UICatalog/Scenarios/ListViewWithSelection.cs

@@ -74,9 +74,9 @@ namespace UICatalog {
 			};
 			};
 
 
 			_listView.DrawContent += (e) => {
 			_listView.DrawContent += (e) => {
-				_scrollBar.Size = _listView.Source.Count;
+				_scrollBar.Size = _listView.Source.Count - 1;
 				_scrollBar.Position = _listView.TopItem;
 				_scrollBar.Position = _listView.TopItem;
-				_scrollBar.OtherScrollBarView.Size = _listView.Maxlength;
+				_scrollBar.OtherScrollBarView.Size = _listView.Maxlength - 1;
 				_scrollBar.OtherScrollBarView.Position = _listView.LeftItem;
 				_scrollBar.OtherScrollBarView.Position = _listView.LeftItem;
 				_scrollBar.Refresh ();
 				_scrollBar.Refresh ();
 			};
 			};

+ 4 - 4
UICatalog/Scenarios/ListsAndCombos.cs

@@ -58,9 +58,9 @@ namespace UICatalog.Scenarios {
 			};
 			};
 
 
 			listview.DrawContent += (e) => {
 			listview.DrawContent += (e) => {
-				_scrollBar.Size = listview.Source.Count;
+				_scrollBar.Size = listview.Source.Count - 1;
 				_scrollBar.Position = listview.TopItem;
 				_scrollBar.Position = listview.TopItem;
-				_scrollBar.OtherScrollBarView.Size = listview.Maxlength;
+				_scrollBar.OtherScrollBarView.Size = listview.Maxlength - 1;
 				_scrollBar.OtherScrollBarView.Position = listview.LeftItem;
 				_scrollBar.OtherScrollBarView.Position = listview.LeftItem;
 				_scrollBar.Refresh ();
 				_scrollBar.Refresh ();
 			};
 			};
@@ -102,9 +102,9 @@ namespace UICatalog.Scenarios {
 			};
 			};
 
 
 			comboBox.DrawContent += (e) => {
 			comboBox.DrawContent += (e) => {
-				scrollBarCbx.Size = comboBox.Source.Count + 1;
+				scrollBarCbx.Size = comboBox.Source.Count;
 				scrollBarCbx.Position = ((ListView)comboBox.Subviews [1]).TopItem;
 				scrollBarCbx.Position = ((ListView)comboBox.Subviews [1]).TopItem;
-				scrollBarCbx.OtherScrollBarView.Size = ((ListView)comboBox.Subviews [1]).Maxlength;
+				scrollBarCbx.OtherScrollBarView.Size = ((ListView)comboBox.Subviews [1]).Maxlength - 1;
 				scrollBarCbx.OtherScrollBarView.Position = ((ListView)comboBox.Subviews [1]).LeftItem;
 				scrollBarCbx.OtherScrollBarView.Position = ((ListView)comboBox.Subviews [1]).LeftItem;
 				scrollBarCbx.Refresh ();
 				scrollBarCbx.Refresh ();
 			};
 			};

+ 20 - 12
UnitTests/ScrollBarViewTests.cs

@@ -153,9 +153,9 @@ namespace Terminal.Gui {
 			_hostView.Redraw (_hostView.Bounds);
 			_hostView.Redraw (_hostView.Bounds);
 
 
 			Assert.Equal (_scrollBar.Position, _hostView.Top);
 			Assert.Equal (_scrollBar.Position, _hostView.Top);
-			Assert.Equal (_scrollBar.Size, _hostView.Lines);
+			Assert.Equal (_scrollBar.Size, _hostView.Lines + 1);
 			Assert.Equal (_scrollBar.OtherScrollBarView.Position, _hostView.Left);
 			Assert.Equal (_scrollBar.OtherScrollBarView.Position, _hostView.Left);
-			Assert.Equal (_scrollBar.OtherScrollBarView.Size, _hostView.Cols);
+			Assert.Equal (_scrollBar.OtherScrollBarView.Size, _hostView.Cols + 1);
 		}
 		}
 
 
 		[Fact]
 		[Fact]
@@ -264,8 +264,8 @@ namespace Terminal.Gui {
 			Assert.Equal (25, _hostView.Bounds.Height);
 			Assert.Equal (25, _hostView.Bounds.Height);
 			Assert.Equal (79, _scrollBar.OtherScrollBarView.Bounds.Width);
 			Assert.Equal (79, _scrollBar.OtherScrollBarView.Bounds.Width);
 			Assert.Equal (24, _scrollBar.Bounds.Height);
 			Assert.Equal (24, _scrollBar.Bounds.Height);
-			Assert.Equal (30, _scrollBar.Size);
-			Assert.Equal (100, _scrollBar.OtherScrollBarView.Size);
+			Assert.Equal (31, _scrollBar.Size);
+			Assert.Equal (101, _scrollBar.OtherScrollBarView.Size);
 			Assert.True (_scrollBar.ShowScrollIndicator);
 			Assert.True (_scrollBar.ShowScrollIndicator);
 			Assert.True (_scrollBar.OtherScrollBarView.ShowScrollIndicator);
 			Assert.True (_scrollBar.OtherScrollBarView.ShowScrollIndicator);
 			Assert.True (_scrollBar.Visible);
 			Assert.True (_scrollBar.Visible);
@@ -274,14 +274,22 @@ namespace Terminal.Gui {
 			_scrollBar.Position = 50;
 			_scrollBar.Position = 50;
 			Assert.Equal (_scrollBar.Position, _scrollBar.Size - _scrollBar.Bounds.Height);
 			Assert.Equal (_scrollBar.Position, _scrollBar.Size - _scrollBar.Bounds.Height);
 			Assert.Equal (_scrollBar.Position, _hostView.Top);
 			Assert.Equal (_scrollBar.Position, _hostView.Top);
-			Assert.Equal (6, _scrollBar.Position);
-			Assert.Equal (6, _hostView.Top);
+			Assert.Equal (7, _scrollBar.Position);
+			Assert.Equal (7, _hostView.Top);
+			Assert.True (_scrollBar.ShowScrollIndicator);
+			Assert.True (_scrollBar.OtherScrollBarView.ShowScrollIndicator);
+			Assert.True (_scrollBar.Visible);
+			Assert.True (_scrollBar.OtherScrollBarView.Visible);
 
 
 			_scrollBar.OtherScrollBarView.Position = 150;
 			_scrollBar.OtherScrollBarView.Position = 150;
 			Assert.Equal (_scrollBar.OtherScrollBarView.Position, _scrollBar.OtherScrollBarView.Size - _scrollBar.OtherScrollBarView.Bounds.Width);
 			Assert.Equal (_scrollBar.OtherScrollBarView.Position, _scrollBar.OtherScrollBarView.Size - _scrollBar.OtherScrollBarView.Bounds.Width);
 			Assert.Equal (_scrollBar.OtherScrollBarView.Position, _hostView.Left);
 			Assert.Equal (_scrollBar.OtherScrollBarView.Position, _hostView.Left);
-			Assert.Equal (21, _scrollBar.OtherScrollBarView.Position);
-			Assert.Equal (21, _hostView.Left);
+			Assert.Equal (22, _scrollBar.OtherScrollBarView.Position);
+			Assert.Equal (22, _hostView.Left);
+			Assert.True (_scrollBar.ShowScrollIndicator);
+			Assert.True (_scrollBar.OtherScrollBarView.ShowScrollIndicator);
+			Assert.True (_scrollBar.Visible);
+			Assert.True (_scrollBar.OtherScrollBarView.Visible);
 		}
 		}
 
 
 		[Fact]
 		[Fact]
@@ -295,14 +303,14 @@ namespace Terminal.Gui {
 			_scrollBar.Position = 50;
 			_scrollBar.Position = 50;
 			Assert.Equal (_scrollBar.Position, _scrollBar.Size - 1);
 			Assert.Equal (_scrollBar.Position, _scrollBar.Size - 1);
 			Assert.Equal (_scrollBar.Position, _hostView.Top);
 			Assert.Equal (_scrollBar.Position, _hostView.Top);
-			Assert.Equal (29, _scrollBar.Position);
-			Assert.Equal (29, _hostView.Top);
+			Assert.Equal (30, _scrollBar.Position);
+			Assert.Equal (30, _hostView.Top);
 
 
 			_scrollBar.OtherScrollBarView.Position = 150;
 			_scrollBar.OtherScrollBarView.Position = 150;
 			Assert.Equal (_scrollBar.OtherScrollBarView.Position, _scrollBar.OtherScrollBarView.Size - 1);
 			Assert.Equal (_scrollBar.OtherScrollBarView.Position, _scrollBar.OtherScrollBarView.Size - 1);
 			Assert.Equal (_scrollBar.OtherScrollBarView.Position, _hostView.Left);
 			Assert.Equal (_scrollBar.OtherScrollBarView.Position, _hostView.Left);
-			Assert.Equal (99, _scrollBar.OtherScrollBarView.Position);
-			Assert.Equal (99, _hostView.Left);
+			Assert.Equal (100, _scrollBar.OtherScrollBarView.Position);
+			Assert.Equal (100, _hostView.Left);
 		}
 		}
 
 
 		[Fact]
 		[Fact]