Table of Contents

Class SpectreRenderableControl

Namespace
SharpConsoleUI.Controls
Assembly
SharpConsoleUI.dll

A control that wraps any Spectre.Console IRenderable for display within the window system. Provides a bridge between Spectre.Console's rich rendering and the SharpConsoleUI framework.

public class SpectreRenderableControl : BaseControl, IDOMPaintable, INotifyPropertyChanged, IMouseAwareControl, IWindowControl, IDisposable
Inheritance
SpectreRenderableControl
Implements
Inherited Members
Extension Methods

Constructors

SpectreRenderableControl()

Initializes a new instance of the SpectreRenderableControl class.

public SpectreRenderableControl()

SpectreRenderableControl(IRenderable)

Initializes a new instance of the SpectreRenderableControl class with a renderable.

public SpectreRenderableControl(IRenderable renderable)

Parameters

renderable IRenderable

The Spectre.Console renderable to display.

Properties

BackgroundColor

Gets or sets the background color for rendering. Falls back to container or theme colors if not explicitly set.

public Color BackgroundColor { get; set; }

Property Value

Color

CanFocusWithMouse

Whether this control can receive focus via mouse clicks

public bool CanFocusWithMouse { get; set; }

Property Value

bool

ContentWidth

Gets the minimum width needed to display the control's content, including margins. Returns null if width cannot be determined. This is calculated based on content (text length, child controls, etc.) and represents the natural/intrinsic size.

public override int? ContentWidth { get; }

Property Value

int?

ForegroundColor

Gets or sets the foreground color for rendering. Falls back to theme colors if not explicitly set.

public Color ForegroundColor { get; set; }

Property Value

Color

Renderable

Gets or sets the Spectre.Console renderable to display.

public IRenderable? Renderable { get; set; }

Property Value

IRenderable

WantsMouseEvents

Whether this control wants to receive mouse events

public bool WantsMouseEvents { get; set; }

Property Value

bool

Methods

Create()

Creates a new builder for configuring a SpectreRenderableControl

public static SpectreRenderableBuilder Create()

Returns

SpectreRenderableBuilder

A new builder 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.

OnDisposing()

Called during Dispose() before Container is set to null. Override to perform control-specific cleanup (null events, close portals, clear data, etc.).

protected override void OnDisposing()

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 a mouse event for this control

public bool ProcessMouseEvent(MouseEventArgs args)

Parameters

args MouseEventArgs

Mouse event arguments with control-relative coordinates

Returns

bool

True if the event was handled and should not propagate further

SetRenderable(IRenderable)

Sets the Spectre.Console renderable to display.

public void SetRenderable(IRenderable renderable)

Parameters

renderable IRenderable

The renderable to display.

Events

MouseClick

Event fired when the control is clicked

public event EventHandler<MouseEventArgs>? MouseClick

Event Type

EventHandler<MouseEventArgs>

MouseDoubleClick

Event fired when the control is double-clicked

public event EventHandler<MouseEventArgs>? MouseDoubleClick

Event Type

EventHandler<MouseEventArgs>

MouseEnter

Event fired when the mouse enters the control area

public event EventHandler<MouseEventArgs>? MouseEnter

Event Type

EventHandler<MouseEventArgs>

MouseLeave

Event fired when the mouse leaves the control area

public event EventHandler<MouseEventArgs>? MouseLeave

Event Type

EventHandler<MouseEventArgs>

MouseMove

Event fired when the mouse moves over the control

public event EventHandler<MouseEventArgs>? MouseMove

Event Type

EventHandler<MouseEventArgs>

MouseRightClick

Event fired when the control is right-clicked (Button3)

public event EventHandler<MouseEventArgs>? MouseRightClick

Event Type

EventHandler<MouseEventArgs>