Pārlūkot izejas kodu

Merge branch 'master' of https://github.com/migueldeicaza/gui.cs into combobox_fixes2

Ross Ferguson 5 gadi atpakaļ
vecāks
revīzija
c71fad0050
2 mainītis faili ar 139 papildinājumiem un 19 dzēšanām
  1. 45 5
      Terminal.Gui/Views/ListView.cs
  2. 94 14
      Terminal.Gui/Views/ScrollView.cs

+ 45 - 5
Terminal.Gui/Views/ListView.cs

@@ -346,6 +346,12 @@ namespace Terminal.Gui {
 				OnOpenSelectedItem ();
 				break;
 
+			case Key.End:
+				return MoveEnd ();
+
+			case Key.Home:
+				return MoveHome ();
+
 			}
 			return base.ProcessKey (kb);
 		}
@@ -459,6 +465,38 @@ namespace Terminal.Gui {
 			return true;
 		}
 
+		/// <summary>
+		/// Moves the selected item index to the last row.
+		/// </summary>
+		/// <returns></returns>
+		public virtual bool MoveEnd ()
+		{
+			if (selected != source.Count - 1) {
+				selected = source.Count - 1;
+				top = selected;
+				OnSelectedChanged ();
+				SetNeedsDisplay ();
+			}
+
+			return true;
+		}
+
+		/// <summary>
+		/// Moves the selected item index to the first row.
+		/// </summary>
+		/// <returns></returns>
+		public virtual bool MoveHome ()
+		{
+			if (selected != 0) {
+				selected = 0;
+				top = selected;
+				OnSelectedChanged ();
+				SetNeedsDisplay ();
+			}
+
+			return true;
+		}
+
 		int lastSelectedItem = -1;
 
 		/// <summary>
@@ -551,15 +589,17 @@ namespace Terminal.Gui {
 		/// <param name="source"></param>
 		public ListWrapper (IList source)
 		{
-			count = source.Count;
-			marks = new BitArray (count);
-			this.src = source;
+			if (source != null) {
+				count = source.Count;
+				marks = new BitArray (count);
+				this.src = source;
+			}
 		}
 
 		/// <summary>
 		/// Gets the number of items in the <see cref="IList"/>.
 		/// </summary>
-		public int Count => src.Count;
+		public int Count => src != null ? src.Count : 0;
 
 		void RenderUstr (ConsoleDriver driver, ustring ustr, int col, int line, int width)
 		{
@@ -594,7 +634,7 @@ namespace Terminal.Gui {
 			container.Move (col, line);
 			var t = src [item];
 			if (t == null) {
-				RenderUstr (driver, ustring.Make(""), col, line, width);
+				RenderUstr (driver, ustring.Make (""), col, line, width);
 			} else {
 				if (t is ustring) {
 					RenderUstr (driver, (ustring)t, col, line, width);

+ 94 - 14
Terminal.Gui/Views/ScrollView.cs

@@ -135,6 +135,10 @@ namespace Terminal.Gui {
 
 			Driver.SetAttribute (ColorScheme.Normal);
 
+			if (Bounds.Height == 0) {
+				return;
+			}
+
 			if (vertical) {
 				if (region.Right < Bounds.Width - 1)
 					return;
@@ -148,9 +152,19 @@ namespace Terminal.Gui {
 					var by2 = (position + bh) * bh / Size;
 
 					Move (col, 0);
-					Driver.AddRune (Driver.UpArrow);
-					Move (col, Bounds.Height - 1);
-					Driver.AddRune (Driver.DownArrow);
+					if (Bounds.Height == 1) {
+						Driver.AddRune (Driver.Diamond);
+					} else {
+						Driver.AddRune (Driver.UpArrow);
+					}
+					if (Bounds.Height == 3) {
+						Move (col, 1);
+						Driver.AddRune (Driver.Diamond);
+					}
+					if (Bounds.Height > 1) {
+						Move (col, Bounds.Height - 1);
+						Driver.AddRune (Driver.DownArrow);
+					}
 				} else {
 					bh -= 2;
 					var by1 = position * bh / Size;
@@ -393,6 +407,11 @@ namespace Terminal.Gui {
 			}
 		}
 
+		/// <summary>
+		/// If true the vertical/horizontal scroll bars won't be showed if it's not needed.
+		/// </summary>
+		public bool AutoHideScrollBars { get; set; } = true;
+
 		/// <summary>
 		/// Adds the view to the scrollview.
 		/// </summary>
@@ -494,17 +513,21 @@ namespace Terminal.Gui {
 
 			var savedClip = ClipToBounds ();
 			OnDrawContent (new Rect (ContentOffset,
-				new Size (Bounds.Width - (ShowVerticalScrollIndicator ? 1 : 0),
-					Bounds.Height - (ShowHorizontalScrollIndicator ? 1 : 0))));
+				new Size (Math.Max (Bounds.Width - (ShowVerticalScrollIndicator ? 1 : 0), 0),
+					Math.Max (Bounds.Height - (ShowHorizontalScrollIndicator ? 1 : 0), 0))));
 			contentView.Redraw (contentView.Frame);
 			Driver.Clip = savedClip;
 
-			if (ShowVerticalScrollIndicator) {
-				vertical.Redraw (vertical.Bounds);
-			}
+			if (AutoHideScrollBars) {
+				ShowHideScrollBars ();
+			} else {
+				if (ShowVerticalScrollIndicator) {
+					vertical.Redraw (vertical.Bounds);
+				}
 
-			if (ShowHorizontalScrollIndicator) {
-				horizontal.Redraw (horizontal.Bounds);
+				if (ShowHorizontalScrollIndicator) {
+					horizontal.Redraw (horizontal.Bounds);
+				}
 			}
 
 			// Fill in the bottom left corner
@@ -514,6 +537,63 @@ namespace Terminal.Gui {
 			Driver.SetAttribute (ColorScheme.Normal);
 		}
 
+		void ShowHideScrollBars ()
+		{
+			bool v = false, h = false; bool p = false;
+
+			if (Bounds.Height == 0 || Bounds.Height > contentSize.Height) {
+				if (ShowVerticalScrollIndicator) {
+					ShowVerticalScrollIndicator = false;
+				}
+				v = false;
+			} else if (Bounds.Height > 0 && Bounds.Height == contentSize.Height) {
+				p = true;
+			} else {
+				if (!ShowVerticalScrollIndicator) {
+					ShowVerticalScrollIndicator = true;
+				}
+				v = true;
+			}
+			if (Bounds.Width == 0 || Bounds.Width > contentSize.Width) {
+				if (ShowHorizontalScrollIndicator) {
+					ShowHorizontalScrollIndicator = false;
+				}
+				h = false;
+			} else if (Bounds.Width > 0 && Bounds.Width == contentSize.Width && p) {
+				if (ShowHorizontalScrollIndicator) {
+					ShowHorizontalScrollIndicator = false;
+				}
+				h = false;
+				if (ShowVerticalScrollIndicator) {
+					ShowVerticalScrollIndicator = false;
+				}
+				v = false;
+			} else {
+				if (p) {
+					if (!ShowVerticalScrollIndicator) {
+						ShowVerticalScrollIndicator = true;
+					}
+					v = true;
+				}
+				if (!ShowHorizontalScrollIndicator) {
+					ShowHorizontalScrollIndicator = true;
+				}
+				h = true;
+			}
+
+			vertical.Height = Dim.Fill (h ? 1 : 0);
+			horizontal.Width = Dim.Fill (v ? 1 : 0);
+
+			if (v) {
+				vertical.SetRelativeLayout (Bounds);
+				vertical.Redraw (vertical.Bounds);
+			}
+			if (h) {
+				horizontal.SetRelativeLayout (Bounds);
+				horizontal.Redraw (horizontal.Bounds);
+			}
+		}
+
 		void SetViewsNeedsDisplay ()
 		{
 			foreach (View view in contentView) {
@@ -631,13 +711,13 @@ namespace Terminal.Gui {
 				!me.Flags.HasFlag (MouseFlags.Button1Pressed | MouseFlags.ReportMousePosition))
 				return false;
 
-			if (me.Flags == MouseFlags.WheeledDown)
+			if (me.Flags == MouseFlags.WheeledDown && ShowVerticalScrollIndicator)
 				ScrollDown (1);
-			else if (me.Flags == MouseFlags.WheeledUp)
+			else if (me.Flags == MouseFlags.WheeledUp && ShowVerticalScrollIndicator)
 				ScrollUp (1);
-			else if (me.X == vertical.Frame.X)
+			else if (me.X == vertical.Frame.X && ShowVerticalScrollIndicator)
 				vertical.MouseEvent (me);
-			else if (me.Y == horizontal.Frame.Y)
+			else if (me.Y == horizontal.Frame.Y && ShowHorizontalScrollIndicator)
 				horizontal.MouseEvent (me);
 			else if (IsOverridden (me.View)) {
 				Application.UngrabMouse ();