Class PanelControl
- Namespace
- SharpConsoleUI.Controls
- Assembly
- SharpConsoleUI.dll
A control that renders a bordered panel with content. Wraps Spectre.Console's Panel with SharpConsoleUI patterns.
public class PanelControl : IDOMPaintable, IMouseAwareControl, IWindowControl, IDisposable
- Inheritance
-
PanelControl
- Implements
- Inherited Members
- Extension Methods
Constructors
PanelControl()
Initializes a new instance of the PanelControl class.
public PanelControl()
PanelControl(IRenderable)
Initializes a new instance of the PanelControl class with content.
public PanelControl(IRenderable content)
Parameters
contentIRenderableThe content to display inside the panel.
PanelControl(string)
Initializes a new instance of the PanelControl class with text content.
public PanelControl(string text)
Parameters
textstringThe text to display inside the panel (supports Spectre markup).
Properties
ActualWidth
Gets the actual rendered width of the control, or null if not yet rendered.
public int? ActualWidth { get; }
Property Value
- int?
BackgroundColor
Gets or sets the background color. When null, inherits from the container.
public Color? BackgroundColor { get; set; }
Property Value
- Color?
BorderColor
Gets or sets the border color. When null, uses the resolved foreground color.
public Color? BorderColor { get; set; }
Property Value
- Color?
BorderStyle
Gets or sets the border style for the panel.
public BorderStyle BorderStyle { get; set; }
Property Value
CanFocusWithMouse
Whether this control can receive focus via mouse clicks
public bool CanFocusWithMouse { get; set; }
Property Value
Container
Gets or sets the parent container that hosts this control.
public IContainer? Container { get; set; }
Property Value
Content
Gets or sets the content to display inside the panel.
public IRenderable? Content { get; set; }
Property Value
- IRenderable
ForegroundColor
Gets or sets the foreground color. When null, inherits from the container.
public Color? ForegroundColor { get; set; }
Property Value
- Color?
Header
Gets or sets the header text displayed at the top of the panel border.
public string? Header { get; set; }
Property Value
HeaderAlignment
Gets or sets the horizontal alignment of the header text.
public Justify HeaderAlignment { get; set; }
Property Value
- Justify
Height
Gets or sets the explicit height of the panel. When set, the panel border will render at this height. When null and VerticalAlignment is Fill, the panel stretches to fill available height.
public int? Height { get; set; }
Property Value
- int?
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 (spacing) around the control.
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
Padding
Gets or sets the padding inside the panel border.
public Padding Padding { get; set; }
Property Value
- Padding
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
UseSafeBorder
Gets or sets whether to use safe border characters for better terminal compatibility.
public bool UseSafeBorder { 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
Whether this control wants to receive mouse events
public bool WantsMouseEvents { get; set; }
Property Value
Width
Gets or sets the explicit width of the control, or null for automatic sizing.
public int? Width { get; set; }
Property Value
- int?
Methods
Create()
Creates a new builder for configuring a PanelControl
public static PanelBuilder Create()
Returns
- PanelBuilder
A new builder 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()
Marks this control as needing to be re-rendered.
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 a mouse event for this control
public bool ProcessMouseEvent(MouseEventArgs args)
Parameters
argsMouseEventArgsMouse event arguments with control-relative coordinates
Returns
- bool
True if the event was handled and should not propagate further
SetContent(IRenderable)
Sets the content to display inside the panel.
public void SetContent(IRenderable renderable)
Parameters
renderableIRenderableThe renderable to display.
SetContent(string)
Sets the content to display inside the panel using text (supports Spectre markup).
public void SetContent(string text)
Parameters
textstringThe text to display.
Events
MouseClick
Event fired when the control is clicked
public event EventHandler<MouseEventArgs>? MouseClick
Event Type
MouseDoubleClick
Event fired when the control is double-clicked
public event EventHandler<MouseEventArgs>? MouseDoubleClick
Event Type
MouseEnter
Event fired when the mouse enters the control area
public event EventHandler<MouseEventArgs>? MouseEnter
Event Type
MouseLeave
Event fired when the mouse leaves the control area
public event EventHandler<MouseEventArgs>? MouseLeave
Event Type
MouseMove
Event fired when the mouse moves over the control
public event EventHandler<MouseEventArgs>? MouseMove