Table of Contents

Class BarGraphControl

Namespace
SharpConsoleUI.Controls
Assembly
SharpConsoleUI.dll

A horizontal bar graph control for visualizing percentage-based data. Displays a filled/unfilled bar with optional label, value, and custom colors.

public class BarGraphControl : IWindowControl, IDisposable, IDOMPaintable
Inheritance
BarGraphControl
Implements
Inherited Members
Extension Methods

Constructors

BarGraphControl()

Initializes a new instance of the BarGraphControl class.

public BarGraphControl()

Properties

ActualWidth

Gets the actual rendered width of the control, or null if not yet rendered.

public int? ActualWidth { get; }

Property Value

int?

BackgroundColor

Gets or sets the background color of the control. When null, inherits from the container.

public Color? BackgroundColor { get; set; }

Property Value

Color?

BarWidth

Gets or sets the width of the bar in characters.

public int BarWidth { get; set; }

Property Value

int

ColorThresholds

Gets the current color thresholds for gradient effect.

public IReadOnlyList<ColorThreshold>? ColorThresholds { get; }

Property Value

IReadOnlyList<ColorThreshold>

Container

Gets or sets the parent container that hosts this control.

public IContainer? Container { get; set; }

Property Value

IContainer

FilledColor

Gets or sets the color for the filled portion of the bar.

public Color FilledColor { get; set; }

Property Value

Color

ForegroundColor

Gets or sets the foreground color for labels and values. When null, inherits from the container.

public Color? ForegroundColor { get; set; }

Property Value

Color?

HorizontalAlignment

Gets or sets the horizontal alignment of the control within its container.

public HorizontalAlignment HorizontalAlignment { get; set; }

Property Value

HorizontalAlignment

Label

Gets or sets the label text displayed before the bar.

public string Label { get; set; }

Property Value

string

LabelWidth

Gets or sets the fixed width for the label column in characters. When set, labels are padded or truncated to this width, ensuring bars align vertically. When null (default), the label uses its natural length.

public int? LabelWidth { get; set; }

Property Value

int?

Margin

Gets or sets the margin (spacing) around the control.

public Margin Margin { get; set; }

Property Value

Margin

MaxValue

Gets or sets the maximum value for the bar (100% fill).

public double MaxValue { get; set; }

Property Value

double

Name

Gets or sets the unique name identifier for this control, used for lookup.

public string? Name { get; set; }

Property Value

string

ShowLabel

Gets or sets whether to show the label.

public bool ShowLabel { get; set; }

Property Value

bool

ShowValue

Gets or sets whether to show the value after the bar.

public bool ShowValue { get; set; }

Property Value

bool

SmoothGradient

Gets or sets the smooth color gradient for horizontal color interpolation. When set, the bar smoothly transitions from start to end color based on fill percentage. This is in addition to (not replacement of) threshold-based gradients. Threshold gradients take precedence when both are set.

public ColorGradient? SmoothGradient { get; set; }

Property Value

ColorGradient

StickyPosition

Gets or sets whether this control should stick to the top or bottom during scrolling.

public StickyPosition StickyPosition { get; set; }

Property Value

StickyPosition

Tag

Gets or sets an arbitrary object value that can be used to store custom data.

public object? Tag { get; set; }

Property Value

object

UnfilledColor

Gets or sets the color for the unfilled portion of the bar.

public Color UnfilledColor { get; set; }

Property Value

Color

Value

Gets or sets the current value to display.

public double Value { get; set; }

Property Value

double

ValueFormat

Gets or sets the format string for displaying the value (e.g., "F1", "F2", "0").

public string ValueFormat { get; set; }

Property Value

string

VerticalAlignment

Gets or sets the vertical alignment of the control within its container.

public VerticalAlignment VerticalAlignment { get; set; }

Property Value

VerticalAlignment

Visible

Gets or sets whether this control is visible.

public bool Visible { get; set; }

Property Value

bool

Width

Gets or sets the explicit width of the control, or null for automatic sizing.

public int? Width { get; set; }

Property Value

int?

Methods

ClearColorThresholds()

Clears all color thresholds, reverting to single FilledColor.

public void ClearColorThresholds()

Dispose()

Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.

public void Dispose()

GetLogicalContentSize()

Gets the logical size of the control's content without rendering.

public Size GetLogicalContentSize()

Returns

Size

The size representing the content's natural dimensions.

Invalidate()

Marks this control as needing to be re-rendered.

public void Invalidate()

MeasureDOM(LayoutConstraints)

Measures the control's desired size given the available constraints.

public LayoutSize MeasureDOM(LayoutConstraints constraints)

Parameters

constraints LayoutConstraints

The layout constraints (min/max width/height).

Returns

LayoutSize

The desired size of the control.

PaintDOM(CharacterBuffer, LayoutRect, LayoutRect, Color, Color)

Paints the control's content directly to a CharacterBuffer.

public void PaintDOM(CharacterBuffer buffer, LayoutRect bounds, LayoutRect clipRect, Color defaultFg, Color defaultBg)

Parameters

buffer CharacterBuffer

The buffer to paint to.

bounds LayoutRect

The absolute bounds where the control should paint.

clipRect LayoutRect

The clipping rectangle (visible area).

defaultFg Color
defaultBg Color

SetColorThresholds(params ColorThreshold[])

Sets color thresholds for gradient effect. Colors apply when the bar percentage is greater than or equal to the threshold. Example: (0, Green), (50, Yellow), (80, Red) shows green 0-49%, yellow 50-79%, red 80%+.

public void SetColorThresholds(params ColorThreshold[] thresholds)

Parameters

thresholds ColorThreshold[]

Color thresholds ordered by percentage. Will be auto-sorted.