Progress.cs 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. using System;
  2. using Terminal.Gui;
  3. namespace UICatalog {
  4. //
  5. // This would be a great scenario to show of threading (Issue #471)
  6. //
  7. [ScenarioMetadata (Name: "Progress", Description: "Shows off ProgressBar.")]
  8. [ScenarioCategory ("Controls")]
  9. class Progress : Scenario {
  10. private ProgressBar _activityProgressBar;
  11. private ProgressBar _pulseProgressBar;
  12. public override void Setup ()
  13. {
  14. Win.Add (new Button ("Start") {
  15. X = Pos.Center () - 20,
  16. Y = Pos.Center () - 5,
  17. Clicked = () => Start ()
  18. });
  19. Win.Add (new Button ("Pulse") {
  20. X = Pos.Center () - 5,
  21. Y = Pos.Center () - 5,
  22. Clicked = () => Pulse ()
  23. });
  24. Win.Add (new Button ("Stop") {
  25. X = Pos.Center () + 10,
  26. Y = Pos.Center () - 5,
  27. Clicked = () => Stop()
  28. });
  29. _activityProgressBar = new ProgressBar () {
  30. X = Pos.Center (),
  31. // BUGBUG: If you remove the +1 below the control is drawn at top?!?!
  32. Y = Pos.Center ()+1,
  33. Width = 30,
  34. Fraction = 0.25F,
  35. };
  36. Win.Add (_activityProgressBar);
  37. _pulseProgressBar = new ProgressBar () {
  38. X = Pos.Center (),
  39. // BUGBUG: If you remove the +1 below the control is drawn at top?!?!
  40. Y = Pos.Center () + 3,
  41. Width = 30,
  42. };
  43. Win.Add (_pulseProgressBar);
  44. }
  45. private void Pulse ()
  46. {
  47. if (_activityProgressBar.Fraction + 0.1F >= 1) {
  48. _activityProgressBar.Fraction = 0F;
  49. } else {
  50. _activityProgressBar.Fraction += 0.1F;
  51. }
  52. _pulseProgressBar.Pulse ();
  53. }
  54. private void Start ()
  55. {
  56. _activityProgressBar.Fraction = 0F;
  57. _pulseProgressBar.Fraction = 0F;
  58. }
  59. private void Stop ()
  60. {
  61. _activityProgressBar.Fraction = 1F;
  62. _pulseProgressBar.Fraction = 1F;
  63. }
  64. }
  65. }