Table of Contents

Class MarkupControl

Namespace
SharpConsoleUI.Controls
Assembly
SharpConsoleUI.dll

A control that displays rich text content using Spectre.Console markup syntax. Supports text alignment, margins, word wrapping, and sticky positioning.

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

Constructors

MarkupControl(List<string>)

Initializes a new instance of the MarkupControl class with the specified lines of text.

public MarkupControl(List<string> lines)

Parameters

lines List<string>

The lines of text to display, supporting Spectre.Console markup syntax.

Properties

ActualWidth

Gets the actual rendered width of the control based on content.

public int? ActualWidth { get; }

Property Value

int?

The maximum line width in characters.

BackgroundColor

Gets or sets the background color for the control. If null, uses container's background color. When set with HorizontalAlignment.Stretch, this color will fill the entire width.

public Color? BackgroundColor { get; set; }

Property Value

Color?

CanFocusWithMouse

Gets whether this control can receive focus via mouse click. MarkupControl is display-only, so it doesn't take keyboard focus.

public bool CanFocusWithMouse { get; }

Property Value

bool

Container

Gets or sets the parent container that hosts this control.

public IContainer? Container { get; set; }

Property Value

IContainer

DoubleClickEnabled

Gets or sets whether double-click events are enabled. Default: true.

public bool DoubleClickEnabled { get; set; }

Property Value

bool

DoubleClickThresholdMs

Gets or sets the double-click threshold in milliseconds. Default: 500ms, minimum: 100ms.

public int DoubleClickThresholdMs { get; set; }

Property Value

int

ForegroundColor

Gets or sets the foreground (text) color for the control. If null, uses container's foreground color.

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

Margin

Gets or sets the margin around the control content.

public Margin Margin { get; set; }

Property Value

Margin

Name

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

public string? Name { get; set; }

Property Value

string

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

Text

Gets or sets the text content as a single string with newline separators.

public string Text { 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

WantsMouseEvents

Gets whether this control wants to receive mouse events.

public bool WantsMouseEvents { get; }

Property Value

bool

Width

Gets or sets the fixed width of the control. When null, the control uses available width.

public int? Width { get; set; }

Property Value

int?

Wrap

Gets or sets whether text should wrap to multiple lines when exceeding available width.

public bool Wrap { get; set; }

Property Value

bool

Methods

Create()

Creates a fluent builder for constructing a MarkupControl.

public static MarkupBuilder Create()

Returns

MarkupBuilder

A new MarkupBuilder instance.

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()

Invalidates the control, forcing a re-render on the next draw.

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

ProcessMouseEvent(MouseEventArgs)

Processes mouse events for this control.

public bool ProcessMouseEvent(MouseEventArgs args)

Parameters

args MouseEventArgs

The mouse event arguments.

Returns

bool

True if the event was handled; otherwise, false.

SetContent(List<string>)

Sets the content of the control to the specified lines of text.

public void SetContent(List<string> lines)

Parameters

lines List<string>

The lines of text to display, supporting Spectre.Console markup syntax.

Events

MouseClick

Occurs when the control is clicked.

public event EventHandler<MouseEventArgs>? MouseClick

Event Type

EventHandler<MouseEventArgs>

MouseDoubleClick

Occurs when the control is double-clicked.

public event EventHandler<MouseEventArgs>? MouseDoubleClick

Event Type

EventHandler<MouseEventArgs>

MouseEnter

Occurs when the mouse enters the control area.

public event EventHandler<MouseEventArgs>? MouseEnter

Event Type

EventHandler<MouseEventArgs>

MouseLeave

Occurs when the mouse leaves the control area.

public event EventHandler<MouseEventArgs>? MouseLeave

Event Type

EventHandler<MouseEventArgs>

MouseMove

Occurs when the mouse moves over the control.

public event EventHandler<MouseEventArgs>? MouseMove

Event Type

EventHandler<MouseEventArgs>