浏览代码

merged latest master

Charlie Kindel 5 年之前
父节点
当前提交
ebfd7112a6
共有 3 个文件被更改,包括 41 次插入31 次删除
  1. 1 1
      README.md
  2. 25 17
      Terminal.Gui/ConsoleDrivers/CursesDriver/UnixMainLoop.cs
  3. 15 13
      UICatalog/Scenarios/ComputedLayout.cs

+ 1 - 1
README.md

@@ -174,7 +174,7 @@ Use NuGet to install the `Terminal.Gui` NuGet package: https://www.nuget.org/pac
 
 ## Running and Building
 
-* *`Terminal.Gui`* - Build and run using the .NET SDK command line tools (`doetnet build` in the root directory) or with Visual Studio 2019.
+* *`Terminal.Gui`* - Build and run using the .NET SDK command line tools (`dotnet build` in the root directory) or with Visual Studio 2019.
 
 ## Contributing
 

+ 25 - 17
Terminal.Gui/ConsoleDrivers/CursesDriver/UnixMainLoop.cs

@@ -166,33 +166,23 @@ namespace Terminal.Gui {
 			}
 		}
 
+
 		bool IMainLoopDriver.EventsPending (bool wait)
 		{
-			long now = DateTime.UtcNow.Ticks;
-
-			int pollTimeout, n;
-			if (mainLoop.timeouts.Count > 0) {
-				pollTimeout = (int)((mainLoop.timeouts.Keys [0] - now) / TimeSpan.TicksPerMillisecond);
-				if (pollTimeout < 0)
-					return true;
+			int pollTimeout = 0;
+			int n;
 
-			} else
-				pollTimeout = -1;
-
-			if (!wait)
-				pollTimeout = 0;
+			if (CkeckTimeout (wait, ref pollTimeout))
+				return true;
 
 			UpdatePollMap ();
 
 			while (true) {
-				if (wait && pollTimeout == -1) {
-					pollTimeout = 0;
-				}
-				n = poll (pollmap, (uint)pollmap.Length, pollTimeout);
+				n = poll (pollmap, (uint)pollmap.Length, 0);
 				if (n > 0) {
 					break;
 				}
-				if (mainLoop.timeouts.Count > 0 || mainLoop.idleHandlers.Count > 0) {
+				if (mainLoop.idleHandlers.Count > 0 || CkeckTimeout (wait, ref pollTimeout)) {
 					return true;
 				}
 			}
@@ -202,6 +192,24 @@ namespace Terminal.Gui {
 			return n > 0 || mainLoop.timeouts.Count > 0 && ((mainLoop.timeouts.Keys [0] - DateTime.UtcNow.Ticks) < 0) || ic > 0;
 		}
 
+		bool CkeckTimeout (bool wait, ref int pollTimeout)
+		{
+			long now = DateTime.UtcNow.Ticks;
+
+			if (mainLoop.timeouts.Count > 0) {
+				pollTimeout = (int)((mainLoop.timeouts.Keys [0] - now) / TimeSpan.TicksPerMillisecond);
+				if (pollTimeout < 0)
+					return true;
+
+			} else
+				pollTimeout = -1;
+
+			if (!wait)
+				pollTimeout = 0;
+
+			return false;
+		}
+
 		void IMainLoopDriver.MainIteration ()
 		{
 			if (pollmap != null) {

+ 15 - 13
UICatalog/Scenarios/ComputedLayout.cs

@@ -36,19 +36,21 @@ namespace UICatalog {
 
 			// Demonstrate using Dim to create a vertical ruler that always measures the parent window's height
 			// TODO: Either build a custom control for this or implement linewrap in Label #352
-			//var verticalRuler = new Label ("") {
-			//	X = 0,
-			//	Y = 0,
-			//	Width = 1,
-			//	Height = Dim.Fill (),
-			//	ColorScheme = Colors.Error
-			//};
-
-			//Application.OnResized += () => {
-			//	verticalRuler.Text = rule.Repeat ((int)Math.Ceiling ((double)(verticalRuler.Bounds.Height) / (double)rule.Length)) [0..(verticalRuler.Bounds.Height)];
-			//};
-
-			//Win.Add (verticalRuler);
+			const string vrule = "|\n1\n2\n3\n4\n5\n6\n7\n8\n9\n";
+
+			var verticalRuler = new Label ("") {
+				X = 0,
+				Y = 0,
+				Width = 1,
+				Height = Dim.Fill (),
+				ColorScheme = Colors.Error
+			};
+
+			Application.Resized += (sender, a) => {
+				verticalRuler.Text = vrule.Repeat ((int)Math.Ceiling ((double)(verticalRuler.Bounds.Height*2) / (double)rule.Length)) [0..(verticalRuler.Bounds.Height*2)];
+			};
+
+			Win.Add (verticalRuler);
 
 			// Demonstrate At - Absolute Layout using Pos
 			var absoluteButton = new Button ("Absolute At(2,1)") {