mirror of
https://github.com/gui-cs/Terminal.Gui.git
synced 2025-12-26 15:57:56 +01:00
updated to really show stuff off
This commit is contained in:
@@ -36,8 +36,10 @@ namespace Terminal.Gui {
|
||||
/// Changed event, raised when the text has clicked.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Client code can hook up to this event, it is
|
||||
/// raised when the text in the entry changes.
|
||||
/// This event is raised when the <see cref="Text"/> changes.
|
||||
/// </remarks>
|
||||
/// <remarks>
|
||||
/// The passed <see cref="EventArgs"/> is a <see cref="ustring"/> containing the old value.
|
||||
/// </remarks>
|
||||
public event EventHandler<ustring> Changed;
|
||||
|
||||
|
||||
@@ -10,34 +10,55 @@ namespace UICatalog {
|
||||
//
|
||||
[ScenarioMetadata (Name: "Progress", Description: "Shows off ProgressBar and Threading")]
|
||||
[ScenarioCategory ("Controls")]
|
||||
[ScenarioCategory ("MainLoop")]
|
||||
[ScenarioCategory ("Threading")]
|
||||
class Progress : Scenario {
|
||||
|
||||
class ProgressDemo : FrameView {
|
||||
const int _verticalSpace = 1;
|
||||
|
||||
internal FrameView LeftFrame { get; private set; }
|
||||
internal TextField Speed { get; private set; }
|
||||
internal ProgressBar ActivityProgressBar { get; private set; }
|
||||
internal ProgressBar PulseProgressBar { get; private set; }
|
||||
internal Action StartBtnClick;
|
||||
internal Action StopBtnClick;
|
||||
internal Action PulseBtnClick;
|
||||
private Label _startedLabel;
|
||||
internal bool Started {
|
||||
get {
|
||||
return _startedLabel.Text == "Started";
|
||||
}
|
||||
private set {
|
||||
_startedLabel.Text = value ? "Started" : "Stopped";
|
||||
}
|
||||
}
|
||||
|
||||
internal ProgressDemo (ustring title) : base (title)
|
||||
{
|
||||
ColorScheme = Colors.Dialog;
|
||||
|
||||
var leftFrame = new FrameView ("Settings") {
|
||||
LeftFrame = new FrameView ("Settings") {
|
||||
X = 0,
|
||||
Y = 0,
|
||||
Height = Dim.Percent (100),
|
||||
Width = Dim.Percent (30)
|
||||
Height = Dim.Percent (100) + 1, // BUGBUG: This +1 should not be needed
|
||||
Width = Dim.Percent (25)
|
||||
};
|
||||
Add (leftFrame);
|
||||
var lbl = new Label (1, 1, "Tick every (ms):");
|
||||
LeftFrame.Add (lbl);
|
||||
Speed = new TextField ("") {
|
||||
X = Pos.Right (lbl) + 1,
|
||||
Y = Pos.Y (lbl),
|
||||
Width = 7,
|
||||
};
|
||||
LeftFrame.Add (Speed);
|
||||
|
||||
Add (LeftFrame);
|
||||
|
||||
var startButton = new Button ("Start Timer") {
|
||||
X = Pos.Right (leftFrame) + 1,
|
||||
X = Pos.Right (LeftFrame) + 1,
|
||||
Y = 0,
|
||||
Clicked = () => StartBtnClick?.Invoke ()
|
||||
Clicked = () => Start()
|
||||
};
|
||||
var pulseButton = new Button ("Pulse") {
|
||||
X = Pos.Right (startButton) + 2,
|
||||
@@ -47,7 +68,7 @@ namespace UICatalog {
|
||||
var stopbutton = new Button ("Stop Timer") {
|
||||
X = Pos.Right (pulseButton) + 2,
|
||||
Y = Pos.Top (pulseButton),
|
||||
Clicked = () => StopBtnClick.Invoke ()
|
||||
Clicked = () => Stop()
|
||||
};
|
||||
|
||||
Add (startButton);
|
||||
@@ -55,7 +76,7 @@ namespace UICatalog {
|
||||
Add (stopbutton);
|
||||
|
||||
ActivityProgressBar = new ProgressBar () {
|
||||
X = Pos.Right (leftFrame) + 1,
|
||||
X = Pos.Right (LeftFrame) + 1,
|
||||
Y = Pos.Bottom (startButton) + 1,
|
||||
Width = Dim.Fill (),
|
||||
Height = 1,
|
||||
@@ -65,7 +86,7 @@ namespace UICatalog {
|
||||
Add (ActivityProgressBar);
|
||||
|
||||
PulseProgressBar = new ProgressBar () {
|
||||
X = Pos.Right (leftFrame) + 1,
|
||||
X = Pos.Right (LeftFrame) + 1,
|
||||
Y = Pos.Bottom (ActivityProgressBar) + 1,
|
||||
Width = Dim.Fill (),
|
||||
Height = 1,
|
||||
@@ -73,16 +94,49 @@ namespace UICatalog {
|
||||
};
|
||||
Add (PulseProgressBar);
|
||||
|
||||
_startedLabel = new Label ("Stopped") {
|
||||
X = Pos.Right (LeftFrame) + 1,
|
||||
Y = Pos.Bottom (PulseProgressBar),
|
||||
};
|
||||
Add (_startedLabel);
|
||||
|
||||
|
||||
// Set height to height of controls + spacing + frame
|
||||
Height = 2 + _verticalSpace + Dim.Height (startButton) + _verticalSpace + Dim.Height (ActivityProgressBar) + _verticalSpace + Dim.Height (PulseProgressBar) + _verticalSpace;
|
||||
}
|
||||
|
||||
internal void Start ()
|
||||
{
|
||||
Started = true;
|
||||
StartBtnClick?.Invoke ();
|
||||
}
|
||||
|
||||
internal void Stop ()
|
||||
{
|
||||
Started = false;
|
||||
StopBtnClick?.Invoke ();
|
||||
}
|
||||
|
||||
internal void Pulse ()
|
||||
{
|
||||
if (PulseBtnClick != null) {
|
||||
PulseBtnClick?.Invoke ();
|
||||
|
||||
} else {
|
||||
if (ActivityProgressBar.Fraction + 0.01F >= 1) {
|
||||
ActivityProgressBar.Fraction = 0F;
|
||||
} else {
|
||||
ActivityProgressBar.Fraction += 0.01F;
|
||||
}
|
||||
PulseProgressBar.Pulse ();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private Timer _systemTimer = null;
|
||||
private int _systemTimerTick = 100; // ms
|
||||
private uint _systemTimerTick = 1000; // ms
|
||||
private object _mainLoopTimeout = null;
|
||||
private int _mainLooopTimeoutTick = 1000; // ms
|
||||
private uint _mainLooopTimeoutTick = 1000; // ms
|
||||
public override void Setup ()
|
||||
{
|
||||
// Demo #1 - Use System.Timer (and threading)
|
||||
@@ -101,18 +155,10 @@ namespace UICatalog {
|
||||
_systemTimer = new Timer ((o) => {
|
||||
// Note the check for Mainloop being valid. System.Timers can run after they are Disposed.
|
||||
// This code must be defensive for that.
|
||||
Application.MainLoop?.Invoke (() => systemTimerDemo.PulseBtnClick ());
|
||||
Application.MainLoop?.Invoke (() => systemTimerDemo.Pulse ());
|
||||
}, null, 0, _systemTimerTick);
|
||||
};
|
||||
|
||||
systemTimerDemo.PulseBtnClick = () => {
|
||||
if (systemTimerDemo.ActivityProgressBar.Fraction + 0.01F >= 1) {
|
||||
systemTimerDemo.ActivityProgressBar.Fraction = 0F;
|
||||
} else {
|
||||
systemTimerDemo.ActivityProgressBar.Fraction += 0.01F;
|
||||
}
|
||||
systemTimerDemo.PulseProgressBar.Pulse ();
|
||||
};
|
||||
systemTimerDemo.StopBtnClick = () => {
|
||||
_systemTimer?.Dispose ();
|
||||
_systemTimer = null;
|
||||
@@ -120,8 +166,20 @@ namespace UICatalog {
|
||||
systemTimerDemo.ActivityProgressBar.Fraction = 1F;
|
||||
systemTimerDemo.PulseProgressBar.Fraction = 1F;
|
||||
};
|
||||
systemTimerDemo.Speed.Text = $"{_systemTimerTick}";
|
||||
systemTimerDemo.Speed.Changed += (sender, a) => {
|
||||
uint result;
|
||||
if (uint.TryParse (systemTimerDemo.Speed.Text.ToString(), out result)) {
|
||||
_systemTimerTick = result;
|
||||
System.Diagnostics.Debug.WriteLine ($"{_systemTimerTick}");
|
||||
if (systemTimerDemo.Started) {
|
||||
systemTimerDemo.Start ();
|
||||
}
|
||||
|
||||
|
||||
} else {
|
||||
System.Diagnostics.Debug.WriteLine ("bad entry");
|
||||
}
|
||||
};
|
||||
Win.Add (systemTimerDemo);
|
||||
|
||||
// Demo #2 - Use Application.MainLoop.AddTimeout (no threads)
|
||||
@@ -137,18 +195,10 @@ namespace UICatalog {
|
||||
mainLoopTimeoutDemo.PulseProgressBar.Fraction = 0F;
|
||||
|
||||
_mainLoopTimeout = Application.MainLoop.AddTimeout (TimeSpan.FromMilliseconds (_mainLooopTimeoutTick), (loop) => {
|
||||
mainLoopTimeoutDemo?.PulseBtnClick ();
|
||||
mainLoopTimeoutDemo.Pulse ();
|
||||
return true;
|
||||
});
|
||||
};
|
||||
mainLoopTimeoutDemo.PulseBtnClick = () => {
|
||||
if (mainLoopTimeoutDemo.ActivityProgressBar.Fraction + 0.01F >= 1) {
|
||||
mainLoopTimeoutDemo.ActivityProgressBar.Fraction = 0F;
|
||||
} else {
|
||||
mainLoopTimeoutDemo.ActivityProgressBar.Fraction += 0.01F;
|
||||
}
|
||||
mainLoopTimeoutDemo.PulseProgressBar.Pulse ();
|
||||
};
|
||||
mainLoopTimeoutDemo.StopBtnClick = () => {
|
||||
if (_mainLoopTimeout != null) {
|
||||
Application.MainLoop.RemoveTimeout (_mainLoopTimeout);
|
||||
@@ -158,8 +208,29 @@ namespace UICatalog {
|
||||
mainLoopTimeoutDemo.ActivityProgressBar.Fraction = 1F;
|
||||
mainLoopTimeoutDemo.PulseProgressBar.Fraction = 1F;
|
||||
};
|
||||
|
||||
mainLoopTimeoutDemo.Speed.Text = $"{_mainLooopTimeoutTick}";
|
||||
mainLoopTimeoutDemo.Speed.Changed += (sender, a) => {
|
||||
uint result;
|
||||
if (uint.TryParse (mainLoopTimeoutDemo.Speed.Text.ToString (), out result)) {
|
||||
_mainLooopTimeoutTick = result;
|
||||
if (mainLoopTimeoutDemo.Started) {
|
||||
mainLoopTimeoutDemo.Start ();
|
||||
}
|
||||
}
|
||||
};
|
||||
Win.Add (mainLoopTimeoutDemo);
|
||||
|
||||
var startBoth = new Button ("Start Both") {
|
||||
X = Pos.Center (),
|
||||
Y = Pos.AnchorEnd () - 1,
|
||||
};
|
||||
startBoth.Clicked = () => {
|
||||
systemTimerDemo.Start ();
|
||||
mainLoopTimeoutDemo.Start ();
|
||||
};
|
||||
Win.Add (startBoth);
|
||||
|
||||
}
|
||||
|
||||
protected override void Dispose (bool disposing)
|
||||
|
||||
Reference in New Issue
Block a user