Skip to content

Commit b30090c

Browse files
testtest
authored andcommitted
Added progress bar. Added example usage to example application.
1 parent 5529a19 commit b30090c

2 files changed

Lines changed: 27 additions & 4 deletions

File tree

Source/ConsoleDraw/Inputs/ProgressBar.cs

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,19 +13,32 @@ public class ProgressBar : Input
1313
public ConsoleColor BackgroundColour = ConsoleColor.Gray;
1414
public ConsoleColor BarColour = ConsoleColor.Black;
1515

16-
public int PercentageComplete = 50;
16+
private int percentageComplete;
17+
public int PercentageComplete {
18+
get { return this.percentageComplete; }
19+
set {
20+
if (value < 0 || value > 100) {
21+
throw new ArgumentOutOfRangeException(String.Format("Percentage must be between 0 & 100, actual:{0}", value));
22+
}
23+
this.percentageComplete = value;
24+
Draw();
25+
}
26+
}
1727

18-
public ProgressBar(int x, int y, int height, int width, String iD, Window parentWindow) : base(x, y, height, width, parentWindow, iD)
28+
public ProgressBar(int percentageComplete, int x, int y, int height, int width, String iD, Window parentWindow) : base(x, y, height, width, parentWindow, iD)
1929
{
2030
Selectable = false;
21-
}
31+
PercentageComplete = percentageComplete;
32+
}
2233

2334
public override void Draw()
2435
{
2536
int widthCompleted = (int)Math.Round(Width * ((double)PercentageComplete / 100));
2637
int widthUncompleted = Width - widthCompleted;
2738

2839
//WindowManager.DrawColourBlock(BackgroundColour, Xpostion, Ypostion, Xpostion + Height, Ypostion + Width);
40+
41+
2942
WindowManager.WirteText("".PadRight(widthCompleted, '█'), Xpostion, Ypostion, BarColour, BackgroundColour);
3043
WindowManager.WirteText("".PadRight(widthUncompleted, '▒'), Xpostion, Ypostion + widthCompleted, BarColour, BackgroundColour);
3144
}

Source/TestApp/Windows/MainWindow.cs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,13 @@ public MainWindow() : base(0, 0, Console.WindowWidth, Console.WindowHeight, null
6060

6161
var fileSelect = new FileBrowser(26, 2, 40, 10, Directory.GetCurrentDirectory(), "fileSelect", this, true);
6262

63-
var progressBar = new ProgressBar(37, 2, 3, 70, "progressBar", this);
63+
var progressBar = new ProgressBar(10, 39, 2, 3, 70, "progressBar", this);
64+
var progressBarLabel = new Label("10%", 39, 73, "oneCheckBoxLabel", this);
65+
66+
var progressBarDownBtn = new Button(37, 2, "Progress Down", "displaySettingsBtn", this) { Action = delegate () { progressBar.PercentageComplete--; progressBarLabel.SetText(String.Format("{0}%", progressBar.PercentageComplete).PadRight(4)); } };
67+
var progressBarUpBtn = new Button(37, 18, "Progress Up", "displaySettingsBtn", this) { Action = delegate () { progressBar.PercentageComplete++; progressBarLabel.SetText(String.Format("{0}%", progressBar.PercentageComplete).PadRight(4)); } };
68+
69+
6470

6571
Inputs.Add(oneBtn);
6672
Inputs.Add(twoBtn);
@@ -101,7 +107,11 @@ public MainWindow() : base(0, 0, Console.WindowWidth, Console.WindowHeight, null
101107

102108
Inputs.Add(fileSelect);
103109

110+
Inputs.Add(progressBarDownBtn);
111+
Inputs.Add(progressBarUpBtn);
112+
104113
Inputs.Add(progressBar);
114+
Inputs.Add(progressBarLabel);
105115

106116
List<string> opts = new List<string>() { "hello", "world"};
107117
var cb = new Dropdown(0, 0, opts, "cb", this);

0 commit comments

Comments
 (0)