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 : BaseControl, IDOMPaintable, INotifyPropertyChanged, IInteractiveControl, IFocusableControl, IMouseAwareControl, IWindowControl, IDisposable, IContainer, IContainerControl, IScrollableContainer, IFocusScope
Inheritance
ScrollablePanelControl
Implements
Inherited Members
Extension Methods

Constructors

ScrollablePanelControl()

Initializes a new instance of the ScrollablePanelControl class.

public ScrollablePanelControl()

Properties

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

BorderColor

Gets or sets the border color. When null, uses the foreground color.

public Color? BorderColor { get; set; }

Property Value

Color?

BorderStyle

Gets or sets the border style for the panel. Default is None (no border).

public BorderStyle BorderStyle { get; set; }

Property Value

BorderStyle

CanFocusWithMouse

Whether this control can receive focus via mouse clicks

public bool CanFocusWithMouse { get; }

Property Value

bool

CanReceiveFocus

ScrollablePanel is focusable when it has anything to interact with: either scrollable content or focusable children. The panel acts as an opaque focus container — it owns its children's focus lifecycle entirely.

public bool CanReceiveFocus { get; }

Property Value

bool

CanScrollDown

Gets whether the content can be scrolled downward (more content exists below the viewport).

public bool CanScrollDown { get; }

Property Value

bool

CanScrollLeft

Gets whether the content can be scrolled left (horizontal offset is greater than zero).

public bool CanScrollLeft { get; }

Property Value

bool

CanScrollRight

Gets whether the content can be scrolled right (more content exists beyond the viewport width).

public bool CanScrollRight { get; }

Property Value

bool

CanScrollUp

Gets whether the content can be scrolled upward (vertical offset is greater than zero).

public bool CanScrollUp { get; }

Property Value

bool

Children

Gets the collection of child controls.

public IReadOnlyList<IWindowControl> Children { get; }

Property Value

IReadOnlyList<IWindowControl>

ContentHeight

public int? ContentHeight { get; }

Property Value

int?

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?

EnableMouseWheel

Gets or sets whether mouse wheel scrolling is enabled.

public bool EnableMouseWheel { get; set; }

Property Value

bool

ForceReceiveFocus

When true, forces CanReceiveFocus to return true regardless of whether the panel has scrollable content or focusable children. Use this when the panel must be focusable as a scroll/container target even when its children are non-interactive (e.g., the NavigationView nav pane).

public bool ForceReceiveFocus { 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

public bool HasFocus { get; }

Property Value

bool

Header

Gets or sets the header text displayed in the top border.

public string? Header { get; set; }

Property Value

string

HeaderAlignment

Gets or sets the alignment of the header text.

public TextJustification HeaderAlignment { get; set; }

Property Value

TextJustification

Height

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

public override int? Height { get; set; }

Property Value

int?

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

Padding

Gets or sets the padding inside the border.

public Padding Padding { get; set; }

Property Value

Padding

SavedFocus

Saved focus position. FocusManager sets this before exiting the scope (if scope opts in). GetInitialFocus should return this when set, then clear it.

public IFocusableControl? SavedFocus { get; set; }

Property Value

IFocusableControl

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

TotalContentHeight

Gets the total height of the scrollable content area in lines. Unlike ContentHeight (which returns the control's own height), this returns the height of the inner content that may extend beyond the viewport.

public int TotalContentHeight { get; }

Property Value

int

TotalContentWidth

Gets the total width of the scrollable content area in characters. Unlike ContentWidth (which returns the control's own width), this returns the width of the inner content that may extend beyond the viewport.

public int TotalContentWidth { get; }

Property Value

int

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

ViewportHeight

Gets the height of the visible viewport area in lines.

public int ViewportHeight { get; }

Property Value

int

ViewportWidth

Gets the width of the visible viewport area in characters.

public int ViewportWidth { get; }

Property Value

int

Visible

Gets or sets whether this control is visible.

public override bool Visible { get; set; }

Property Value

bool

WantsMouseEvents

Whether this control wants to receive mouse events

public bool WantsMouseEvents { get; }

Property Value

bool

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

ClearContents()

Removes all child controls from the panel.

public void ClearContents()

Create()

Creates a new builder for configuring a ScrollablePanelControl

public static ScrollablePanelBuilder Create()

Returns

ScrollablePanelBuilder

A new builder instance

GetChildren()

Gets the children of this container for Tab navigation traversal. Required by IContainerControl interface.

public IReadOnlyList<IWindowControl> GetChildren()

Returns

IReadOnlyList<IWindowControl>

GetInitialFocus(bool)

Returns the first child to focus when Tab enters this scope. backward=true means Shift+Tab entered from the right — return last child.

public IFocusableControl? GetInitialFocus(bool backward)

Parameters

backward bool

Returns

IFocusableControl

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.

GetNextFocus(IFocusableControl, bool)

Returns the next child to focus after Tab from 'current'. Returns null when Tab should exit this scope.

public IFocusableControl? GetNextFocus(IFocusableControl current, bool backward)

Parameters

current IFocusableControl
backward bool

Returns

IFocusableControl

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

InsertControl(int, IWindowControl)

Inserts a child control at the specified index in the panel. This method is not thread-safe and must be called from the UI thread.

public void InsertControl(int index, IWindowControl control)

Parameters

index int

The zero-based index at which to insert the control.

control IWindowControl

The control to insert.

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

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

ScrollChildIntoView(IWindowControl)

Automatically scrolls to bring a child control into view when it receives focus. This is called by the focus system when a child within this panel gains focus.

public void ScrollChildIntoView(IWindowControl child)

Parameters

child IWindowControl

ScrollHorizontalBy(int)

Scrolls the content horizontally by the specified number of characters. Positive values scroll right, negative values scroll left. The offset is clamped to valid bounds automatically.

public void ScrollHorizontalBy(int chars)

Parameters

chars int

Number of characters to scroll (positive = right, negative = left).

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()

ScrollVerticalBy(int)

Scrolls the content vertically by the specified number of lines. Positive values scroll down, negative values scroll up. The offset is clamped to valid bounds automatically.

public void ScrollVerticalBy(int lines)

Parameters

lines int

Number of lines to scroll (positive = down, negative = up).

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.

public event EventHandler<MouseEventArgs>? MouseRightClick

Event Type

EventHandler<MouseEventArgs>

Scrolled

Event fired when the panel is scrolled.

public event EventHandler<ScrollEventArgs>? Scrolled

Event Type

EventHandler<ScrollEventArgs>