浏览代码

Draw scrollbars, I like where this is going

Miguel de Icaza 7 年之前
父节点
当前提交
06e8c5c540
共有 4 个文件被更改,包括 120 次插入6 次删除
  1. 25 0
      Terminal.Gui/Driver.cs
  2. 19 0
      Terminal.Gui/MonoCurses/constants.cs
  3. 40 2
      Terminal.Gui/Views/ScrollView.cs
  4. 36 4
      demo.cs

+ 25 - 0
Terminal.Gui/Driver.cs

@@ -161,6 +161,22 @@ namespace Terminal.Gui {
 		/// Horizontal line character.
 		/// </summary>
 		HLine,
+
+		/// <summary>
+		/// Vertical line character.
+		/// </summary>
+		VLine,
+
+		/// <summary>
+		/// Stipple pattern
+		/// </summary>
+		Stipple,
+
+		/// <summary>
+		/// Diamond character
+		/// </summary>
+		Diamond,
+
 	}
 
 	/// <summary>
@@ -298,6 +314,15 @@ namespace Terminal.Gui {
 			case SpecialChar.HLine:
 				AddRune (Curses.ACS_HLINE);
 				break;
+			case SpecialChar.VLine:
+				AddRune (Curses.ACS_VLINE);
+				break;
+			case SpecialChar.Stipple:
+				AddRune (Curses.ACS_CKBOARD);
+				break;
+			case SpecialChar.Diamond:
+				AddRune (Curses.ACS_DIAMOND);
+				break;
 			}
 		}
 

+ 19 - 0
Terminal.Gui/MonoCurses/constants.cs

@@ -21,6 +21,25 @@ namespace Unix.Terminal {
 		public const int ACS_ULCORNER = unchecked((int)0x40006c);
 		public const int ACS_URCORNER = unchecked((int)0x40006b);
 		public const int ACS_VLINE = unchecked((int)0x400078);
+		public const int ACS_LTEE = unchecked((int)0x400074);
+		public const int ACS_RTEE = unchecked((int)0x400075);
+		public const int ACS_BTEE = unchecked((int)0x400076);
+		public const int ACS_TTEE = unchecked((int)0x400077);
+		public const int ACS_PLUS = unchecked((int)0x40006e);
+		public const int ACS_S1 = unchecked((int)0x40006f);
+		public const int ACS_S9 = unchecked((int)0x400073);
+		public const int ACS_DIAMOND = unchecked((int)0x400060);
+		public const int ACS_CKBOARD = unchecked((int)0x400061);
+		public const int ACS_DEGREE = unchecked((int)0x400066);
+		public const int ACS_PLMINUS = unchecked((int)0x400067);
+		public const int ACS_BULLET = unchecked((int)0x40007e);
+		public const int ACS_LARROW = unchecked((int)0x40002c);
+		public const int ACS_RARROW = unchecked((int)0x40002b);
+		public const int ACS_DARROW = unchecked((int)0x40002e);
+		public const int ACS_UARROW = unchecked((int)0x40002d);
+		public const int ACS_BOARD = unchecked((int)0x400068);
+		public const int ACS_LANTERN = unchecked((int)0x400069);
+		public const int ACS_BLOCK = unchecked((int)0x400030);
 		public const int COLOR_BLACK = unchecked((int)0x0);
 		public const int COLOR_RED = unchecked((int)0x1);
 		public const int COLOR_GREEN = unchecked((int)0x2);

+ 40 - 2
Terminal.Gui/Views/ScrollView.cs

@@ -98,10 +98,48 @@ namespace Terminal.Gui {
 		{
 			var oldClip = ClipToBounds ();
 			base.Redraw(region);
-			Driver.SetAttribute (ColorScheme.Normal);
+			Attribute last = ColorScheme.Normal;
+			Driver.SetAttribute (last);
+
+			void SetColor (Attribute a)
+			{
+				if (a != last)
+					Driver.SetAttribute (a);
+				last = a;
+			}
 
-			DrawFrame (Bounds);
 			Driver.Clip = oldClip;
+
+			if (true || ShowVerticalScrollIndicator) {
+				var bh = Bounds.Height;
+				var by1 = contentOffset.Y * bh/ contentSize.Height;
+				var by2 = (contentOffset.Y+bh) * bh/ contentSize.Height;
+
+				for (int y = 0; y < bh; y++) {
+					Move (Bounds.Width - 1, y);
+					if (y < by1 || y > by2)
+						Driver.AddSpecial (SpecialChar.Stipple);
+					else
+						Driver.AddSpecial (SpecialChar.Diamond);
+				}
+			}
+			if (true || ShowHorizontalScrollIndicator){
+				var bw = Bounds.Width;
+				var bx1 = contentOffset.X * bw / contentSize.Width;
+				var bx2 = (contentOffset.X + bw) * bw / contentSize.Width;
+
+				Move (0, Bounds.Height - 1);
+				for (int x = 0; x < bw; x++) {
+					if (x < bx1 || x > bx2){
+						SetColor (ColorScheme.Normal);
+						Driver.AddSpecial (SpecialChar.Stipple);
+					} else {
+						// Driver.AddSpecial (SpecialChar.Diamond);
+						SetColor (ColorScheme.Focus);
+						Driver.AddSpecial (SpecialChar.Stipple);
+					}
+				}
+			}
 		}
 	}
 }

+ 36 - 4
demo.cs

@@ -2,8 +2,8 @@ using Terminal.Gui;
 using System;
 
 class Demo {
-	class MyView : View {
-		public MyView (int x, int y) : base (new Rect (x, y, 10, 10))
+	class Box10x : View {
+		public Box10x (int x, int y) : base (new Rect (x, y, 10, 10))
 		{
 		}
 
@@ -20,9 +20,40 @@ class Demo {
 			}
 	
 		}
+	}
+
+	class Filler : View {
+		public Filler (Rect rect) : base (rect)
+		{
+		}
+
+		public override void Redraw(Rect region)
+		{
+			Driver.SetAttribute (ColorScheme.Focus);
+			var f = Frame;
 
+			for (int y = 0; y < f.Width; y++) {
+				Move (0, y);
+				for (int x = 0; x < f.Height; x++) {
+					Rune r;
+					switch (x % 3) {
+					case 0:
+						r = '.';
+						break;
+					case 1:
+						r = 'o';
+						break;
+					default:
+						r = 'O';
+						break;
+					}
+					Driver.AddRune (r);
+				}
+			}	
+		}
 	}
 
+
 	static void ShowTextAlignments (View container)
 	{
 		container.Add (
@@ -36,10 +67,11 @@ class Demo {
 	{
 		var scrollView = new ScrollView (new Rect (50, 10, 20, 8)) {
 			ContentSize = new Size (100, 100),
-			ContentOffset = new Point (-1, -1)
+			ContentOffset = new Point (5, -2)
 		};
 
-		scrollView.Add (new MyView (0, 0));
+		//scrollView.Add (new Box10x (0, 0));
+		scrollView.Add (new Filler (new Rect (0, 0, 40, 40)));
 
 		container.Add (
 			new Label (3, 6, "Login: "),