Charlie Kindel 5 lat temu
rodzic
commit
649680aab4

+ 37 - 8
UICatalog/Scenarios/ComputedLayout.cs

@@ -83,14 +83,13 @@ namespace UICatalog {
 			textView.Text = "This text view should be half-way down the terminal,\n20% of its height, and 80% of its width.";
 			Win.Add (textView);
 
-			//// Demonstrate AnchorEnd - Button anchored to bottom of textView
-			//var clearButton = new Button ("Clear") {
-			//	X = Pos.AnchorEnd (),
-			//	Y = Pos.AnchorEnd (),
-			//	Width = 15,
-			//	Height = 1
-			//};
-			//Win.Add (clearButton);
+			// Demonstrate AnchorEnd - Button anchored to bottom of textView
+			var clearButton = new Button ("Anchor End") {
+				Y = Pos.AnchorEnd () - 1
+			};
+			clearButton.X = Pos.AnchorEnd () - clearButton.Text.Length + 4;
+
+			Win.Add (clearButton);
 
 			// Demonstrate At - Absolute Layout using Pos
 			var absoluteButton = new Button ("At(10,10)") {
@@ -98,6 +97,36 @@ namespace UICatalog {
 				Y = Pos.At(10)
 			};
 			Win.Add (absoluteButton);
+
+			// Centering multiple controls horizontally. 
+			// This is intentionally convoluted to illustrate potential bugs.
+			var bottomLabel = new Label ("This should be the 2nd to last line (Bug #xxx).") {
+				TextAlignment = Terminal.Gui.TextAlignment.Centered,
+				ColorScheme = Colors.TopLevel,
+				Width = Dim.Fill (),
+				X = Pos.Center (),
+				Y = Pos.Bottom (Win) - 4  // BUGBUG: -2 should be two lines above border; but it has to be -4
+			};
+			Win.Add (bottomLabel);
+
+			var leftButton = new Button ("Left") {
+				Y = Pos.Bottom (Win) - 2
+			};
+			var centerButton = new Button ("Center") {
+				X = Pos.Center (),
+				Y = Pos.AnchorEnd () - 1
+			};
+			var rightButton = new Button ("Right") {
+				Y = Pos.Y(centerButton)
+			};
+
+			leftButton.X = Pos.Left (centerButton) - leftButton.Frame.Width - 5;
+			rightButton.X = Pos.Right (centerButton) + 5;
+
+			Win.Add (leftButton);
+			Win.Add (centerButton);
+			Win.Add (rightButton);
+
 		}
 
 		public override void Run ()

+ 43 - 14
UICatalog/Scenarios/Progress.cs

@@ -1,4 +1,5 @@
 using System;
+using System.Threading;
 using Terminal.Gui;
 
 namespace UICatalog {
@@ -11,27 +12,31 @@ namespace UICatalog {
 
 		private ProgressBar _activityProgressBar;
 		private ProgressBar _pulseProgressBar;
+		private Timer _timer;
+		private object _timeoutToken = null;
+
 		public override void Setup ()
 		{
-			Win.Add (new Button ("Start") {
-				X = Pos.Center () - 20,
-				Y = Pos.Center () - 5,
-				Clicked = () => Start ()
-			});
-
-			Win.Add (new Button ("Pulse") {
-				X = Pos.Center () - 5,
+			var pulseButton = new Button ("Pulse") {
+				X = Pos.Center (),
 				Y = Pos.Center () - 5,
 				Clicked = () => Pulse ()
-			}); 
+			};
 
+			Win.Add (new Button ("Start Timer") {
+				X = Pos.Left(pulseButton) - 20,
+				Y = Pos.Y(pulseButton),
+				Clicked = () => Start ()
+			});
 
-			Win.Add (new Button ("Stop") {
-				X = Pos.Center () + 10,
-				Y = Pos.Center () - 5,
+			Win.Add (new Button ("Stop Timer") {
+				X = Pos.Right (pulseButton) + 20, // BUGBUG: Right is somehow adding additional width
+				Y = Pos.Y (pulseButton),
 				Clicked = () => Stop()
 			});
 
+			Win.Add (pulseButton);
+
 			_activityProgressBar = new ProgressBar () {
 				X = Pos.Center (),
 				// BUGBUG: If you remove the +1 below the control is drawn at top?!?!
@@ -50,24 +55,48 @@ namespace UICatalog {
 			Win.Add (_pulseProgressBar);
 		}
 
+		protected override void Dispose (bool disposing)
+		{
+			_timer?.Dispose ();
+			_timer = null;
+			if (_timeoutToken != null) {
+				Application.MainLoop.RemoveTimeout (_timeoutToken);
+			}
+			base.Dispose (disposing);
+		}
+
 		private void Pulse ()
 		{
-			if (_activityProgressBar.Fraction + 0.1F >= 1) {
+			if (_activityProgressBar.Fraction + 0.01F >= 1) {
 				_activityProgressBar.Fraction = 0F;
 			} else {
-				_activityProgressBar.Fraction += 0.1F;
+				_activityProgressBar.Fraction += 0.01F;
 			}
 			_pulseProgressBar.Pulse ();
 		}
 
 		private void Start ()
 		{
+			_timer?.Dispose ();
+			_timer = null;
+
 			_activityProgressBar.Fraction = 0F;
 			_pulseProgressBar.Fraction = 0F;
+
+			_timer = new Timer ((o) => {
+				// BUGBUG: #409 - Invoke does not cause Wakeup as it should
+				Application.MainLoop.Invoke (() => Pulse ());
+			}, null, 0, 250);
 		}
 
 		private void Stop ()
 		{
+			_timer?.Dispose ();
+			_timer = null;
+			if (_timeoutToken != null) {
+				Application.MainLoop.RemoveTimeout (_timeoutToken);
+			}
+
 			_activityProgressBar.Fraction = 1F;
 			_pulseProgressBar.Fraction = 1F;
 		}