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
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
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
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
DoubleClickThresholdMs
Gets or sets the double-click threshold in milliseconds. Default: 500ms, minimum: 100ms.
public int DoubleClickThresholdMs { get; set; }
Property Value
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
Text
Gets or sets the text content as a single string with newline separators.
public string Text { get; set; }
Property Value
WantsMouseEvents
Gets whether this control wants to receive mouse events.
public bool WantsMouseEvents { get; }
Property Value
Wrap
Gets or sets whether text should wrap to multiple lines when exceeding available width.
public bool Wrap { get; set; }
Property Value
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
constraintsLayoutConstraintsThe 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
bufferCharacterBufferThe buffer to paint to.
boundsLayoutRectThe absolute bounds where the control should paint.
clipRectLayoutRectThe clipping rectangle (visible area).
defaultFgColordefaultBgColor
ProcessMouseEvent(MouseEventArgs)
Processes mouse events for this control.
public bool ProcessMouseEvent(MouseEventArgs args)
Parameters
argsMouseEventArgsThe 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
Events
MouseClick
Occurs when the control is clicked.
public event EventHandler<MouseEventArgs>? MouseClick
Event Type
MouseDoubleClick
Occurs when the control is double-clicked.
public event EventHandler<MouseEventArgs>? MouseDoubleClick
Event Type
MouseEnter
Occurs when the mouse enters the control area.
public event EventHandler<MouseEventArgs>? MouseEnter
Event Type
MouseLeave
Occurs when the mouse leaves the control area.
public event EventHandler<MouseEventArgs>? MouseLeave
Event Type
MouseMove
Occurs when the mouse moves over the control.
public event EventHandler<MouseEventArgs>? MouseMove
Event Type
MouseRightClick
Occurs when the control is right-clicked.
public event EventHandler<MouseEventArgs>? MouseRightClick