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
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
Container
Gets or sets the parent container that hosts this control.
public IContainer? Container { get; set; }
Property Value
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
- Color?
HorizontalAlignment
Gets or sets the horizontal alignment of the control within its container.
public HorizontalAlignment HorizontalAlignment { get; set; }
Property Value
Margin
Gets or sets the margin around the control content.
public Margin Margin { get; set; }
Property Value
Name
Gets or sets the unique name identifier for this control, used for lookup.
public string? Name { get; set; }
Property Value
StickyPosition
Gets or sets whether this control should stick to the top or bottom during scrolling.
public StickyPosition StickyPosition { get; set; }
Property Value
Tag
Gets or sets an arbitrary object value that can be used to store custom data.
public object? Tag { 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
VerticalAlignment
Gets or sets the vertical alignment of the control within its container.
public VerticalAlignment VerticalAlignment { get; set; }
Property Value
Visible
Gets or sets whether this control is visible.
public bool Visible { get; set; }
Property Value
WantsMouseEvents
Gets whether this control wants to receive mouse events.
public bool WantsMouseEvents { get; }
Property Value
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
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
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 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