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

Fixes #1050. ScrollView take to long to scroll enormous content size.

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

+ 39 - 6
Terminal.Gui/Views/ScrollView.cs

@@ -277,6 +277,8 @@ namespace Terminal.Gui {
 			}
 		}
 
+		int lastLocation = -1;
+
 		///<inheritdoc/>
 		public override bool MouseEvent (MouseEvent me)
 		{
@@ -285,6 +287,10 @@ namespace Terminal.Gui {
 				return false;
 			}
 
+			if (!me.Flags.HasFlag (MouseFlags.Button1Pressed | MouseFlags.ReportMousePosition)) {
+				lastLocation = -1;
+			}
+
 			int location = vertical ? me.Y : me.X;
 			int barsize = vertical ? Bounds.Height : Bounds.Width;
 			int posTopLeftTee = vertical ? posTopTee : posLeftTee;
@@ -307,13 +313,40 @@ namespace Terminal.Gui {
 					b1 = Math.Max (b1 - 1, 0);
 				}
 
-				if (location > b2 + 1 && location > posTopLeftTee && location > b1 && location > posBottomRightTee && posBottomRightTee > 0) {
-					Host.CanScroll (location, out int nv, vertical);
-					if (nv > 0) {
-						SetPosition (Math.Min (pos + nv, Size));
+				if (location > b1 && location <= b2 + 1) {
+					if (me.Flags == MouseFlags.Button1Pressed || me.Flags == MouseFlags.Button1Clicked) {
+						if (location == 1) {
+							SetPosition (0);
+						} else if (location == barsize) {
+							Host.CanScroll (Size - pos, out int nv, vertical);
+							if (nv > 0) {
+								SetPosition (Math.Min (pos + nv, Size));
+							}
+						}
+					} else if (me.Flags.HasFlag (MouseFlags.Button1Pressed | MouseFlags.ReportMousePosition)) {
+						var mb = (b2 - b1) / 2;
+						var ml = mb + b1 + (mb == 0 ? 1 : 0);
+						if ((location >= b1 && location <= ml) || (location < lastLocation && lastLocation > -1)) {
+							lastLocation = location;
+							var np = b1 * Size / barsize;
+							SetPosition (np);
+						} else if (location > lastLocation) {
+							var np = location * Size / barsize;
+							Host.CanScroll (np - pos, out int nv, vertical);
+							if (nv > 0) {
+								SetPosition (pos + nv);
+							}
+						}
+					}
+				} else {
+					if (location >= b2 + 1 && location > posTopLeftTee && location > b1 && location > posBottomRightTee && posBottomRightTee > 0) {
+						Host.CanScroll (location, out int nv, vertical);
+						if (nv > 0) {
+							SetPosition (Math.Min (pos + nv, Size));
+						}
+					} else if (location <= b1) {
+						SetPosition (Math.Max (pos - barsize - location, 0));
 					}
-				} else if (location <= b1) {
-					SetPosition (Math.Max (pos - barsize - location, 0));
 				}
 			}
 

+ 2 - 0
UICatalog/Scenarios/CharacterMap.cs

@@ -137,6 +137,8 @@ namespace UICatalog {
 			//	}
 			//}
 
+			ContentSize = new Size (CharMap.RowWidth, MaxCodePointVal / 16 + Frame.Height - 1);
+
 			for (int header = 0; header < 16; header++) {
 				Move (viewport.X + RowHeaderWidth + (header * H_SPACE), 0);
 				Driver.AddStr ($" {header:x} ");

+ 1 - 0
UICatalog/Scenarios/Scrolling.cs

@@ -129,6 +129,7 @@ namespace UICatalog {
 				X = 0,
 				Y = 0,
 				Width = Dim.Fill (1),  // BUGBUG: I don't think this should be needed; DimFill() should respect container's frame. X does.
+				Height = 1,
 				ColorScheme = Colors.Error
 			};
 			scrollView.Add (horizontalRuler);