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 : BaseControl, IDOMPaintable, INotifyPropertyChanged, 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

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

ContentWidth

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

public override int? ContentWidth { get; }

Property Value

int?

The maximum line width in characters.

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?

Text

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

public string Text { get; set; }

Property Value

string

WantsMouseEvents

Gets whether this control wants to receive mouse events.

public bool WantsMouseEvents { get; }

Property Value

bool

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.

GetLogicalContentSize()

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

public override Size GetLogicalContentSize()

Returns

Size

The size representing the content's natural dimensions.

MeasureDOM(LayoutConstraints)

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

public override 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 override 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>

MouseRightClick

Occurs when the control is right-clicked.

public event EventHandler<MouseEventArgs>? MouseRightClick

Event Type

EventHandler<MouseEventArgs>