|
@@ -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;
|
|
|
}
|