Charlie Kindel 5 年之前
父節點
當前提交
9606dad68c
共有 3 個文件被更改,包括 122 次插入19 次删除
  1. 38 0
      Terminal.Gui/Views/ListView.cs
  2. 68 11
      Terminal.Gui/Views/ScrollView.cs
  3. 16 8
      UICatalog/Scenarios/Unicode.cs

+ 38 - 0
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>

+ 68 - 11
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;
@@ -149,6 +153,10 @@ namespace Terminal.Gui {
 
 					Move (col, 0);
 					Driver.AddRune (Driver.UpArrow);
+					if (Bounds.Height == 3) {
+						Move (col, 1);
+						Driver.AddRune (Driver.Diamond);
+					}
 					Move (col, Bounds.Height - 1);
 					Driver.AddRune (Driver.DownArrow);
 				} else {
@@ -393,6 +401,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 +507,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 +531,46 @@ namespace Terminal.Gui {
 			Driver.SetAttribute (ColorScheme.Normal);
 		}
 
+		void ShowHideScrollBars ()
+		{
+			bool v = false, h = false;
+
+			if (Bounds.Height == 0 || Bounds.Height > contentSize.Height) {
+				if (ShowVerticalScrollIndicator) {
+					ShowVerticalScrollIndicator = false;
+				}
+				v = false;
+			} else {
+				if (!ShowVerticalScrollIndicator) {
+					ShowVerticalScrollIndicator = true;
+				}
+				v = true;
+			}
+			if (Bounds.Width == 0 || Bounds.Width > contentSize.Width) {
+				if (ShowHorizontalScrollIndicator) {
+					ShowHorizontalScrollIndicator = false;
+				}
+				h = false;
+			} else {
+				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 +688,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 ();

+ 16 - 8
UICatalog/Scenarios/Unicode.cs

@@ -10,9 +10,17 @@ namespace UICatalog {
 	class UnicodeInMenu : Scenario {
 		public override void Setup ()
 		{
+			const string IdenticalSign = "\u2261";
+			const string ArrowUpSign = "\u2191";
+			const string ArrowDownSign = "\u2193";
+			const string EllipsesSign = "\u2026";
+			const string StashSign = "\u205E";
+
 			//string text = "Hello world, how are you today? Pretty neat!\nSecond line\n\nFourth Line.";
 			string unicode = "Τὴ γλῶσσα μοῦ ἔδωσαν ἑλληνικὴ\nτὸ σπίτι φτωχικὸ στὶς ἀμμουδιὲς τοῦ Ὁμήρου.\nΜονάχη ἔγνοια ἡ γλῶσσα μου στὶς ἀμμουδιὲς τοῦ Ὁμήρου.";
 
+			string gitString = $"gui.cs master {IdenticalSign} {ArrowDownSign}18 {ArrowUpSign}10 {StashSign}1 {EllipsesSign}";
+
 			var menu = new MenuBar (new MenuBarItem [] {
 				new MenuBarItem ("_Файл", new MenuItem [] {
 					new MenuItem ("_Создать", "Creates new file", null),
@@ -30,7 +38,7 @@ namespace UICatalog {
 
 			var label = new Label ("Label:") { X = 0, Y = 1 };
 			Win.Add (label);
-			var testlabel = new Label ("Стоял _он, дум великих полн") { X = 20, Y = Pos.Y (label), Width = Dim.Percent (50), };
+			var testlabel = new Label (gitString) { X = 20, Y = Pos.Y (label), Width = Dim.Percent (50), };
 			Win.Add (testlabel);
 
 			label = new Label ("Label (CanFocus):") { X = Pos.X (label), Y = Pos.Bottom (label) + 1 };
@@ -45,7 +53,7 @@ namespace UICatalog {
 
 			label = new Label ("CheckBox:") { X = Pos.X (label), Y = Pos.Bottom (label) + 1 };
 			Win.Add (label);
-			var checkBox = new CheckBox (" ~  s  gui.cs   master ↑10") { X = 20, Y = Pos.Y (label), Width = Dim.Percent (50) };
+			var checkBox = new CheckBox (gitString) { X = 20, Y = Pos.Y (label), Width = Dim.Percent (50) };
 			Win.Add (checkBox);
 
 			// BUGBUG: Combobox does not deal with unicode properly. 
@@ -57,14 +65,14 @@ namespace UICatalog {
 				Y = Pos.Y (label),
 				Width = Dim.Percent (50),
 			};
-			comboBox.SetSource (new List<string> () { "item #1", " ~  s  gui.cs   master ↑10", "Со_хранить" });
+			comboBox.SetSource (new List<string> () { gitString, "Со_хранить" });
 
 			Win.Add (comboBox);
-			comboBox.Text = " ~  s  gui.cs   master ↑10";
+			comboBox.Text = gitString;
 #endif
 			label = new Label ("HexView:") { X = Pos.X (label), Y = Pos.Bottom (label) + 2 };
 			Win.Add (label);
-			var hexView = new HexView (new System.IO.MemoryStream (Encoding.ASCII.GetBytes (" ~  s  gui.cs   master ↑10 Со_хранить"))) {
+			var hexView = new HexView (new System.IO.MemoryStream (Encoding.ASCII.GetBytes (gitString + " Со_хранить"))) {
 				X = 20,
 				Y = Pos.Y (label),
 				Width = Dim.Percent (60),
@@ -74,7 +82,7 @@ namespace UICatalog {
 
 			label = new Label ("ListView:") { X = Pos.X (label), Y = Pos.Bottom (hexView) + 1 };
 			Win.Add (label);
-			var listView = new ListView (new List<string> () { "item #1", " ~  s  gui.cs   master ↑10", "Со_хранить", unicode }) {
+			var listView = new ListView (new List<string> () { "item #1", gitString, "Со_хранить", unicode }) {
 				X = 20,
 				Y = Pos.Y (label),
 				Width = Dim.Percent (60),
@@ -84,7 +92,7 @@ namespace UICatalog {
 
 			label = new Label ("RadioGroup:") { X = Pos.X (label), Y = Pos.Bottom (listView) + 1 };
 			Win.Add (label);
-			var radioGroup = new RadioGroup (new ustring [] { "item #1", " ~  s  gui.cs   master ↑10", "Со_хранить" }, selected: 0) {
+			var radioGroup = new RadioGroup (new ustring [] { "item #1", gitString, "Со_хранить" }, selected: 0) {
 				X = 20,
 				Y = Pos.Y (label),
 				Width = Dim.Percent (60),
@@ -93,7 +101,7 @@ namespace UICatalog {
 
 			label = new Label ("TextField:") { X = Pos.X (label), Y = Pos.Bottom (radioGroup) + 1 };
 			Win.Add (label);
-			var textField = new TextField (" ~  s  gui.cs   master ↑10 = Со_хранить") { X = 20, Y = Pos.Y (label), Width = Dim.Percent (60) };
+			var textField = new TextField (gitString + " = Со_хранить") { X = 20, Y = Pos.Y (label), Width = Dim.Percent (60) };
 			Win.Add (textField);
 
 			label = new Label ("TextView:") { X = Pos.X (label), Y = Pos.Bottom (textField) + 1 };