Table of Contents

Class ScrollablePanelControl

Namespace
SharpConsoleUI.Controls
Assembly
SharpConsoleUI.dll

A scrollable panel control that can host child controls with automatic scrolling support. Supports vertical and horizontal scrolling, mouse wheel, and visual scrollbars.

public class ScrollablePanelControl : IInteractiveControl, IFocusableControl, IMouseAwareControl, IWindowControl, IDisposable, IContainer, IDOMPaintable, IDirectionalFocusControl
Inheritance
ScrollablePanelControl
Implements
Inherited Members
Extension Methods

Constructors

ScrollablePanelControl()

Initializes a new instance of the ScrollablePanelControl class.

public ScrollablePanelControl()

Properties

ActualHeight

public int? ActualHeight { get; }

Property Value

int?

ActualWidth

Gets the actual rendered width of the control, or null if not yet rendered.

public int? ActualWidth { get; }

Property Value

int?

AutoScroll

Gets or sets whether to automatically scroll to bottom when content is added. When enabled, scrolls to bottom on AddControl if currently at/near bottom. Disables automatically when user scrolls up, re-enables when user scrolls to bottom.

public bool AutoScroll { get; set; }

Property Value

bool

BackgroundColor

Gets or sets the background color for the container and its child controls.

public Color BackgroundColor { get; set; }

Property Value

Color

CanFocusWithMouse

Whether this control can receive focus via mouse clicks

public bool CanFocusWithMouse { get; }

Property Value

bool

CanReceiveFocus

Whether this control can receive focus

public bool CanReceiveFocus { get; }

Property Value

bool

Children

Gets the collection of child controls.

public IReadOnlyList<IWindowControl> Children { get; }

Property Value

IReadOnlyList<IWindowControl>

Container

Gets or sets the parent container that hosts this control.

public IContainer? Container { get; set; }

Property Value

IContainer

EnableMouseWheel

Gets or sets whether mouse wheel scrolling is enabled.

public bool EnableMouseWheel { get; set; }

Property Value

bool

ForegroundColor

Gets or sets the foreground (text) color for the container and its child controls.

public Color ForegroundColor { get; set; }

Property Value

Color

GetConsoleWindowSystem

Gets the console window system instance, or null if not attached to a window system.

public ConsoleWindowSystem? GetConsoleWindowSystem { get; }

Property Value

ConsoleWindowSystem

HasFocus

Gets or sets whether this control currently has keyboard focus.

public bool HasFocus { get; set; }

Property Value

bool

HorizontalAlignment

Gets or sets the horizontal alignment of the control within its container.

public HorizontalAlignment HorizontalAlignment { get; set; }

Property Value

HorizontalAlignment

HorizontalScrollMode

Gets or sets the horizontal scroll mode.

public ScrollMode HorizontalScrollMode { get; set; }

Property Value

ScrollMode

HorizontalScrollOffset

Gets the current horizontal scroll offset in characters.

public int HorizontalScrollOffset { get; }

Property Value

int

IsDirty

Gets or sets whether this container needs to be redrawn.

public bool IsDirty { get; set; }

Property Value

bool

IsEnabled

Gets or sets whether this control is enabled and can receive input.

public bool IsEnabled { get; set; }

Property Value

bool

Margin

Gets or sets the margin (spacing) around the control.

public Margin Margin { get; set; }

Property Value

Margin

Name

Gets or sets the unique name identifier for this control, used for lookup.

public string? Name { get; set; }

Property Value

string

ScrollbarPosition

Gets or sets the position of the scrollbar.

public ScrollbarPosition ScrollbarPosition { get; set; }

Property Value

ScrollbarPosition

ShowScrollbar

Gets or sets whether to show the scrollbar.

public bool ShowScrollbar { get; set; }

Property Value

bool

StickyPosition

Gets or sets whether this control should stick to the top or bottom during scrolling.

public StickyPosition StickyPosition { get; set; }

Property Value

StickyPosition

Tag

Gets or sets an arbitrary object value that can be used to store custom data.

public object? Tag { get; set; }

Property Value

object

VerticalAlignment

Gets or sets the vertical alignment of the control within its container.

public VerticalAlignment VerticalAlignment { get; set; }

Property Value

VerticalAlignment

VerticalScrollMode

Gets or sets the vertical scroll mode.

public ScrollMode VerticalScrollMode { get; set; }

Property Value

ScrollMode

VerticalScrollOffset

Gets the current vertical scroll offset in lines.

public int VerticalScrollOffset { get; }

Property Value

int

Visible

Gets or sets whether this control is visible.

public bool Visible { get; set; }

Property Value

bool

WantsMouseEvents

Whether this control wants to receive mouse events

public bool WantsMouseEvents { get; }

Property Value

bool

Width

Gets or sets the explicit width of the control, or null for automatic sizing.

public int? Width { get; set; }

Property Value

int?

Methods

AddControl(IWindowControl)

Adds a child control to the panel. This method is not thread-safe and must be called from the UI thread. For multi-threaded scenarios, queue additions and process them during paint.

public void AddControl(IWindowControl control)

Parameters

control IWindowControl

Create()

Creates a new builder for configuring a ScrollablePanelControl

public static ScrollablePanelBuilder Create()

Returns

ScrollablePanelBuilder

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.

GetVisibleHeightForControl(IWindowControl)

Gets the actual visible height for a control within the container viewport. Returns null if the control is not found or visibility cannot be determined.

public int? GetVisibleHeightForControl(IWindowControl control)

Parameters

control IWindowControl

The control to check

Returns

int?

The number of visible lines, or null if unknown

Invalidate()

Marks this control as needing to be re-rendered.

public void Invalidate()

Invalidate(bool, IWindowControl?)

Marks this container as needing to be redrawn.

public void Invalidate(bool redrawAll, IWindowControl? callerControl = null)

Parameters

redrawAll bool

If true, forces a complete redraw of all content.

callerControl IWindowControl

The control that triggered the invalidation, if any.

MeasureDOM(LayoutConstraints)

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

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

ProcessKey(ConsoleKeyInfo)

Processes a keyboard input event.

public bool ProcessKey(ConsoleKeyInfo key)

Parameters

key ConsoleKeyInfo

The key information for the pressed key.

Returns

bool

True if the key was handled by this control; otherwise, false.

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

RemoveControl(IWindowControl)

Removes a child control from the panel. This method is not thread-safe and must be called from the UI thread.

public void RemoveControl(IWindowControl control)

Parameters

control IWindowControl

ScrollToBottom()

Scrolls to the bottom of the content.

public void ScrollToBottom()

ScrollToPosition(int, int)

Scrolls to a specific position.

public void ScrollToPosition(int vertical, int horizontal = 0)

Parameters

vertical int
horizontal int

ScrollToTop()

Scrolls to the top of the content.

public void ScrollToTop()

SetFocus(bool, FocusReason)

Sets focus to this control

public void SetFocus(bool focus, FocusReason reason = FocusReason.Programmatic)

Parameters

focus bool

Whether to give or remove focus

reason FocusReason

The reason for the focus change

SetFocusWithDirection(bool, bool)

Sets focus with direction information for proper child control selection

public void SetFocusWithDirection(bool focus, bool backward)

Parameters

focus bool

Whether to set or remove focus

backward bool

If true, focus last child; if false, focus first child

Events

GotFocus

Event fired when the control gains focus.

public event EventHandler? GotFocus

Event Type

EventHandler

LostFocus

Event fired when the control loses focus.

public event EventHandler? LostFocus

Event Type

EventHandler

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>

Scrolled

Event fired when the panel is scrolled.

public event EventHandler<ScrollEventArgs>? Scrolled

Event Type

EventHandler<ScrollEventArgs>