|
@@ -1,4 +1,5 @@
|
|
-namespace Terminal.Gui;
|
|
|
|
|
|
+#nullable enable
|
|
|
|
+namespace Terminal.Gui;
|
|
|
|
|
|
/// <summary>Specifies the style that a <see cref="ProgressBar"/> uses to indicate the progress of an operation.</summary>
|
|
/// <summary>Specifies the style that a <see cref="ProgressBar"/> uses to indicate the progress of an operation.</summary>
|
|
public enum ProgressBarStyle
|
|
public enum ProgressBarStyle
|
|
@@ -37,30 +38,29 @@ public enum ProgressBarFormat
|
|
/// </remarks>
|
|
/// </remarks>
|
|
public class ProgressBar : View, IDesignable
|
|
public class ProgressBar : View, IDesignable
|
|
{
|
|
{
|
|
- private int [] _activityPos;
|
|
|
|
- private bool _bidirectionalMarquee = true;
|
|
|
|
|
|
+ private int []? _activityPos;
|
|
private int _delta;
|
|
private int _delta;
|
|
private float _fraction;
|
|
private float _fraction;
|
|
private bool _isActivity;
|
|
private bool _isActivity;
|
|
private ProgressBarStyle _progressBarStyle = ProgressBarStyle.Blocks;
|
|
private ProgressBarStyle _progressBarStyle = ProgressBarStyle.Blocks;
|
|
- private ProgressBarFormat _progressBarFormat = ProgressBarFormat.Simple;
|
|
|
|
- private Rune _segmentCharacter = Glyphs.BlocksMeterSegment;
|
|
|
|
|
|
|
|
/// <summary>
|
|
/// <summary>
|
|
/// Initializes a new instance of the <see cref="ProgressBar"/> class, starts in percentage mode and uses relative
|
|
/// Initializes a new instance of the <see cref="ProgressBar"/> class, starts in percentage mode and uses relative
|
|
/// layout.
|
|
/// layout.
|
|
/// </summary>
|
|
/// </summary>
|
|
- public ProgressBar () { SetInitialProperties (); }
|
|
|
|
|
|
+ public ProgressBar ()
|
|
|
|
+ {
|
|
|
|
+ Width = Dim.Auto (DimAutoStyle.Content);
|
|
|
|
+ Height = Dim.Auto (DimAutoStyle.Content, 1);
|
|
|
|
+ CanFocus = false;
|
|
|
|
+ _fraction = 0;
|
|
|
|
+ }
|
|
|
|
|
|
/// <summary>
|
|
/// <summary>
|
|
/// Specifies if the <see cref="ProgressBarStyle.MarqueeBlocks"/> or the
|
|
/// Specifies if the <see cref="ProgressBarStyle.MarqueeBlocks"/> or the
|
|
/// <see cref="ProgressBarStyle.MarqueeContinuous"/> styles is unidirectional or bidirectional.
|
|
/// <see cref="ProgressBarStyle.MarqueeContinuous"/> styles is unidirectional or bidirectional.
|
|
/// </summary>
|
|
/// </summary>
|
|
- public bool BidirectionalMarquee
|
|
|
|
- {
|
|
|
|
- get => _bidirectionalMarquee;
|
|
|
|
- set => _bidirectionalMarquee = value;
|
|
|
|
- }
|
|
|
|
|
|
+ public bool BidirectionalMarquee { get; set; } = true;
|
|
|
|
|
|
/// <summary>Gets or sets the <see cref="ProgressBar"/> fraction to display, must be a value between 0 and 1.</summary>
|
|
/// <summary>Gets or sets the <see cref="ProgressBar"/> fraction to display, must be a value between 0 and 1.</summary>
|
|
/// <value>The fraction representing the progress.</value>
|
|
/// <value>The fraction representing the progress.</value>
|
|
@@ -76,11 +76,7 @@ public class ProgressBar : View, IDesignable
|
|
}
|
|
}
|
|
|
|
|
|
/// <summary>Specifies the format that a <see cref="ProgressBar"/> uses to indicate the visual presentation.</summary>
|
|
/// <summary>Specifies the format that a <see cref="ProgressBar"/> uses to indicate the visual presentation.</summary>
|
|
- public ProgressBarFormat ProgressBarFormat
|
|
|
|
- {
|
|
|
|
- get => _progressBarFormat;
|
|
|
|
- set => _progressBarFormat = value;
|
|
|
|
- }
|
|
|
|
|
|
+ public ProgressBarFormat ProgressBarFormat { get; set; } = ProgressBarFormat.Simple;
|
|
|
|
|
|
/// <summary>Gets/Sets the progress bar style based on the <see cref="Terminal.Gui.ProgressBarStyle"/></summary>
|
|
/// <summary>Gets/Sets the progress bar style based on the <see cref="Terminal.Gui.ProgressBarStyle"/></summary>
|
|
public ProgressBarStyle ProgressBarStyle
|
|
public ProgressBarStyle ProgressBarStyle
|
|
@@ -109,16 +105,13 @@ public class ProgressBar : View, IDesignable
|
|
|
|
|
|
break;
|
|
break;
|
|
}
|
|
}
|
|
|
|
+
|
|
SetNeedsDraw ();
|
|
SetNeedsDraw ();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
/// <summary>Segment indicator for meter views.</summary>
|
|
/// <summary>Segment indicator for meter views.</summary>
|
|
- public Rune SegmentCharacter
|
|
|
|
- {
|
|
|
|
- get => _segmentCharacter;
|
|
|
|
- set => _segmentCharacter = value;
|
|
|
|
- }
|
|
|
|
|
|
+ public Rune SegmentCharacter { get; set; } = Glyphs.BlocksMeterSegment;
|
|
|
|
|
|
/// <summary>
|
|
/// <summary>
|
|
/// Gets or sets the text displayed on the progress bar. If set to an empty string and
|
|
/// Gets or sets the text displayed on the progress bar. If set to an empty string and
|
|
@@ -130,8 +123,7 @@ public class ProgressBar : View, IDesignable
|
|
get => string.IsNullOrEmpty (base.Text) ? $"{_fraction * 100:F0}%" : base.Text;
|
|
get => string.IsNullOrEmpty (base.Text) ? $"{_fraction * 100:F0}%" : base.Text;
|
|
set
|
|
set
|
|
{
|
|
{
|
|
- if (ProgressBarStyle == ProgressBarStyle.MarqueeBlocks
|
|
|
|
- || ProgressBarStyle == ProgressBarStyle.MarqueeContinuous)
|
|
|
|
|
|
+ if (ProgressBarStyle is ProgressBarStyle.MarqueeBlocks or ProgressBarStyle.MarqueeContinuous)
|
|
{
|
|
{
|
|
base.Text = value;
|
|
base.Text = value;
|
|
}
|
|
}
|
|
@@ -178,19 +170,19 @@ public class ProgressBar : View, IDesignable
|
|
if (ProgressBarFormat != ProgressBarFormat.Simple && !_isActivity)
|
|
if (ProgressBarFormat != ProgressBarFormat.Simple && !_isActivity)
|
|
{
|
|
{
|
|
var tf = new TextFormatter { Alignment = Alignment.Center, Text = Text };
|
|
var tf = new TextFormatter { Alignment = Alignment.Center, Text = Text };
|
|
- var attr = new Attribute (ColorScheme.HotNormal.Foreground, ColorScheme.HotNormal.Background);
|
|
|
|
|
|
+ var attr = new Attribute (ColorScheme!.HotNormal.Foreground, ColorScheme.HotNormal.Background);
|
|
|
|
|
|
if (_fraction > .5)
|
|
if (_fraction > .5)
|
|
{
|
|
{
|
|
- attr = new Attribute (ColorScheme.HotNormal.Background, ColorScheme.HotNormal.Foreground);
|
|
|
|
|
|
+ attr = new (ColorScheme.HotNormal.Background, ColorScheme.HotNormal.Foreground);
|
|
}
|
|
}
|
|
|
|
|
|
tf.Draw (
|
|
tf.Draw (
|
|
- ViewportToScreen (Viewport),
|
|
|
|
- attr,
|
|
|
|
- ColorScheme.Normal,
|
|
|
|
- SuperView?.ViewportToScreen (SuperView.Viewport) ?? default (Rectangle)
|
|
|
|
- );
|
|
|
|
|
|
+ ViewportToScreen (Viewport),
|
|
|
|
+ attr,
|
|
|
|
+ ColorScheme.Normal,
|
|
|
|
+ SuperView?.ViewportToScreen (SuperView.Viewport) ?? default (Rectangle)
|
|
|
|
+ );
|
|
}
|
|
}
|
|
|
|
|
|
return true;
|
|
return true;
|
|
@@ -236,7 +228,7 @@ public class ProgressBar : View, IDesignable
|
|
}
|
|
}
|
|
else if (_activityPos [0] >= Viewport.Width)
|
|
else if (_activityPos [0] >= Viewport.Width)
|
|
{
|
|
{
|
|
- if (_bidirectionalMarquee)
|
|
|
|
|
|
+ if (BidirectionalMarquee)
|
|
{
|
|
{
|
|
for (var i = 0; i < _activityPos.Length; i++)
|
|
for (var i = 0; i < _activityPos.Length; i++)
|
|
{
|
|
{
|
|
@@ -265,29 +257,13 @@ public class ProgressBar : View, IDesignable
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
- private void ProgressBar_Initialized (object sender, EventArgs e)
|
|
|
|
- {
|
|
|
|
- //ColorScheme = new ColorScheme (ColorScheme ?? SuperView?.ColorScheme ?? Colors.ColorSchemes ["Base"])
|
|
|
|
- //{
|
|
|
|
- // HotNormal = new Attribute (Color.BrightGreen, Color.Gray)
|
|
|
|
- //};
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- private void SetInitialProperties ()
|
|
|
|
- {
|
|
|
|
- Width = Dim.Auto (DimAutoStyle.Content);
|
|
|
|
- Height = Dim.Auto (DimAutoStyle.Content, minimumContentDim: 1);
|
|
|
|
- CanFocus = false;
|
|
|
|
- _fraction = 0;
|
|
|
|
- Initialized += ProgressBar_Initialized;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- /// <inheritdoc />
|
|
|
|
|
|
+ /// <inheritdoc/>
|
|
public bool EnableForDesign ()
|
|
public bool EnableForDesign ()
|
|
{
|
|
{
|
|
Width = Dim.Fill ();
|
|
Width = Dim.Fill ();
|
|
- Height = Dim.Auto (DimAutoStyle.Text, minimumContentDim: 1);
|
|
|
|
|
|
+ Height = Dim.Auto (DimAutoStyle.Text, 1);
|
|
Fraction = 0.75f;
|
|
Fraction = 0.75f;
|
|
|
|
+
|
|
return true;
|
|
return true;
|
|
}
|
|
}
|
|
}
|
|
}
|