Table of Contents

Class PortalContentBase

Namespace
SharpConsoleUI.Controls
Assembly
SharpConsoleUI.dll

Abstract base class for portal content controls (overlay panels used by dropdowns, menus, etc.). Provides default implementations of IWindowControl, IDOMPaintable, IMouseAwareControl, and IHasPortalBounds to eliminate boilerplate.

public abstract class PortalContentBase : IContainer, IDOMPaintable, IMouseAwareControl, IWindowControl, IDisposable, IHasPortalBounds
Inheritance
PortalContentBase
Implements
Derived
Inherited Members
Extension Methods

Properties

ActualHeight

Gets the actual height at which the control was last rendered. Returns 0 if the control has not been rendered yet.

public int ActualHeight { get; }

Property Value

int

ActualWidth

Gets the actual width at which the control was last rendered. Returns 0 if the control has not been rendered yet.

public int ActualWidth { get; }

Property Value

int

ActualX

Gets the actual X coordinate where the control was last rendered. Returns 0 if the control has not been rendered yet.

public int ActualX { get; }

Property Value

int

ActualY

Gets the actual Y coordinate where the control was last rendered. Returns 0 if the control has not been rendered yet.

public int ActualY { get; }

Property Value

int

BackgroundColor

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

public Color BackgroundColor { get; set; }

Property Value

Color

BorderBackgroundColor

Background color for the border and fill area. Falls back to the default background.

public Color? BorderBackgroundColor { get; set; }

Property Value

Color?

BorderColor

Foreground color for the border characters. Falls back to the default foreground.

public Color? BorderColor { get; set; }

Property Value

Color?

BorderStyle

When set, PaintDOM draws a border using these characters and shrinks the inner bounds by 1 on each side before calling PaintPortalContent(CharacterBuffer, LayoutRect, LayoutRect, Color, Color). Mouse coordinates are automatically adjusted by (-1,-1) for the border offset.

public BoxChars? BorderStyle { get; set; }

Property Value

BoxChars?

CanFocusWithMouse

Whether this control can receive focus via mouse clicks

public virtual bool CanFocusWithMouse { get; }

Property Value

bool

Container

Gets or sets the parent container that hosts this control.

public IContainer? Container { get; set; }

Property Value

IContainer

Remarks

This is the upstream container — the window that hosts this portal (set by CreatePortal). It is distinct from this portal acting as the container for an optional hosted Content child (see the IContainer implementation): a hosted child's Container points at this portal, and this portal's Container points at the window, forming the child → portal → window chain.

Content

Optional hosted child control. When set, this portal renders the child through the normal control pipeline (the child's own MeasureDOM(LayoutConstraints)/PaintDOM(CharacterBuffer, LayoutRect, LayoutRect, Color, Color)), inside this portal's border, and forwards mouse events to it — so the child self-invalidates via its Container and the consumer never calls Invalidate. When null, the subclass paints manually via PaintPortalContent(CharacterBuffer, LayoutRect, LayoutRect, Color, Color) (the legacy path), so existing subclasses are unaffected.

public IWindowControl? Content { get; set; }

Property Value

IWindowControl

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 int? ContentWidth { get; }

Property Value

int?

DismissOnOutsideClick

When true, the portal is automatically dismissed when the user clicks outside its bounds.

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

Height

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

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

HorizontalAlignment

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

PortalFocusedControl

Gets or sets the control that is focused within this portal's scope, independently of the window's FocusManager.

public IFocusableControl? PortalFocusedControl { get; set; }

Property Value

IFocusableControl

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

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

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.

GetPortalBounds()

Returns the absolute position and size for this portal overlay. Subclasses must implement this to provide their bounds.

public abstract Rectangle GetPortalBounds()

Returns

Rectangle

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

Remarks

Returns the height of the INNER content area the hosted Content is painted into — i.e. the portal height minus the border rows — NOT the portal's full ActualHeight. The hosted child uses this for its scroll/ensure-visible math, so it must match the rect the child is actually painted into (_contentRect), or the child believes it has the border rows too and scrolls one row late.

Invalidate(Invalidation)

Marks this control as needing the specified work on the next frame.

public void Invalidate(Invalidation work)

Parameters

work Invalidation

Repaint (appearance-only) or Relayout (size/position-affecting).

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

PaintPortalContent(CharacterBuffer, LayoutRect, LayoutRect, Color, Color)

Paints the portal content. Called by PaintDOM(CharacterBuffer, LayoutRect, LayoutRect, Color, Color) after setting actual bounds.

protected abstract void PaintPortalContent(CharacterBuffer buffer, LayoutRect bounds, LayoutRect clipRect, Color defaultFg, Color defaultBg)

Parameters

buffer CharacterBuffer
bounds LayoutRect
clipRect LayoutRect
defaultFg Color
defaultBg Color

ProcessHostedMouseEvent(MouseEventArgs)

Default mouse handling for a hosted Content child: forwards the (already border-adjusted) event to the child. Subclasses that host a child should return this from their ProcessMouseEvent override (and may inspect the result to fire higher-level events such as item-accepted).

protected bool ProcessHostedMouseEvent(MouseEventArgs args)

Parameters

args MouseEventArgs

Returns

bool

ProcessMouseEvent(MouseEventArgs)

Processes a mouse event. When BorderStyle is set, coordinates are already adjusted for the border offset.

public abstract bool ProcessMouseEvent(MouseEventArgs args)

Parameters

args MouseEventArgs

Returns

bool

Events

DismissRequested

Raised when the portal is about to be dismissed due to an outside click. Consumers can use this to perform cleanup before the portal is removed.

public event EventHandler? DismissRequested

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>

MouseRightClick

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

public event EventHandler<MouseEventArgs>? MouseRightClick

Event Type

EventHandler<MouseEventArgs>