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
BackgroundColor
Gets or sets the background color for the container and its child controls.
public Color BackgroundColor { get; set; }
Property Value
BorderColor
Gets or sets the border color. When null, uses the foreground color.
public Color? BorderColor { get; set; }
Property Value
BorderStyle
Gets or sets the border style for the panel. Default is None (no border).
public BorderStyle BorderStyle { get; set; }
Property Value
CanFocusWithMouse
Whether this control can receive focus via mouse clicks
public bool CanFocusWithMouse { get; }
Property Value
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
CanScrollDown
Gets whether the content can be scrolled downward (more content exists below the viewport).
public bool CanScrollDown { get; }
Property Value
CanScrollLeft
Gets whether the content can be scrolled left (horizontal offset is greater than zero).
public bool CanScrollLeft { get; }
Property Value
CanScrollRight
Gets whether the content can be scrolled right (more content exists beyond the viewport width).
public bool CanScrollRight { get; }
Property Value
CanScrollUp
Gets whether the content can be scrolled upward (vertical offset is greater than zero).
public bool CanScrollUp { get; }
Property Value
Children
Gets the collection of child controls.
public IReadOnlyList<IWindowControl> Children { get; }
Property Value
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
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
ForegroundColor
Gets or sets the foreground (text) color for the container and its child controls.
public Color ForegroundColor { get; set; }
Property Value
GetConsoleWindowSystem
Gets the console window system instance, or null if not attached to a window system.
public ConsoleWindowSystem? GetConsoleWindowSystem { get; }
Property Value
HasFocus
public bool HasFocus { get; }
Property Value
Header
Gets or sets the header text displayed in the top border.
public string? Header { get; set; }
Property Value
HeaderAlignment
Gets or sets the alignment of the header text.
public TextJustification HeaderAlignment { get; set; }
Property Value
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
HorizontalScrollOffset
Gets the current horizontal scroll offset in characters.
public int HorizontalScrollOffset { get; }
Property Value
IsDirty
Gets or sets whether this container needs to be redrawn.
public bool IsDirty { get; set; }
Property Value
IsEnabled
Gets or sets whether this control is enabled and can receive input.
public bool IsEnabled { get; set; }
Property Value
Padding
Gets or sets the padding inside the border.
public Padding Padding { get; set; }
Property Value
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
ScrollbarPosition
Gets or sets the position of the scrollbar.
public ScrollbarPosition ScrollbarPosition { get; set; }
Property Value
ShowScrollbar
Gets or sets whether to show the scrollbar.
public bool ShowScrollbar { get; set; }
Property Value
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
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
VerticalScrollMode
Gets or sets the vertical scroll mode.
public ScrollMode VerticalScrollMode { get; set; }
Property Value
VerticalScrollOffset
Gets the current vertical scroll offset in lines.
public int VerticalScrollOffset { get; }
Property Value
ViewportHeight
Gets the height of the visible viewport area in lines.
public int ViewportHeight { get; }
Property Value
ViewportWidth
Gets the width of the visible viewport area in characters.
public int ViewportWidth { get; }
Property Value
Visible
Gets or sets whether this control is visible.
public override bool Visible { get; set; }
Property Value
WantsMouseEvents
Whether this control wants to receive mouse events
public bool WantsMouseEvents { get; }
Property Value
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
controlIWindowControl
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
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
backwardbool
Returns
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
currentIFocusableControlbackwardbool
Returns
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
controlIWindowControlThe 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
indexintThe zero-based index at which to insert the control.
controlIWindowControlThe control to insert.
Invalidate(bool, IWindowControl?)
Marks this container as needing to be redrawn.
public void Invalidate(bool redrawAll, IWindowControl? callerControl = null)
Parameters
redrawAllboolIf true, forces a complete redraw of all content.
callerControlIWindowControlThe 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
constraintsLayoutConstraintsThe 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
bufferCharacterBufferThe buffer to paint to.
boundsLayoutRectThe absolute bounds where the control should paint.
clipRectLayoutRectThe clipping rectangle (visible area).
defaultFgColordefaultBgColor
ProcessKey(ConsoleKeyInfo)
Processes a keyboard input event.
public bool ProcessKey(ConsoleKeyInfo key)
Parameters
keyConsoleKeyInfoThe 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
argsMouseEventArgsMouse 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
controlIWindowControl
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
childIWindowControl
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
charsintNumber 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
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
linesintNumber of lines to scroll (positive = down, negative = up).
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
Event Type
MouseRightClick
Event fired when the control is right-clicked.
public event EventHandler<MouseEventArgs>? MouseRightClick
Event Type
Scrolled
Event fired when the panel is scrolled.
public event EventHandler<ScrollEventArgs>? Scrolled