Table of Contents

Class BaseControl

Namespace
SharpConsoleUI.Controls
Assembly
SharpConsoleUI.dll

Abstract base class for all UI controls, providing shared layout fields, properties, and default implementations of IWindowControl and IDOMPaintable. Implements INotifyPropertyChanged for MVVM data binding support.

public abstract class BaseControl : IWindowControl, IDisposable, IDOMPaintable, INotifyPropertyChanged
Inheritance
BaseControl
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

Bindings

Gets the binding collection for this control. Lazily allocated on first access.

public BindingCollection Bindings { get; }

Property Value

BindingCollection

Container

Gets or sets the parent container that hosts this control.

public virtual IContainer? Container { get; set; }

Property Value

IContainer

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

Property Value

int?

Height

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

public virtual int? Height { get; set; }

Property Value

int?

HorizontalAlignment

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

public virtual HorizontalAlignment HorizontalAlignment { get; set; }

Property Value

HorizontalAlignment

Margin

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

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

StickyPosition

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

public virtual 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 virtual VerticalAlignment VerticalAlignment { get; set; }

Property Value

VerticalAlignment

Visible

Gets or sets whether this control is visible.

public virtual bool Visible { get; set; }

Property Value

bool

Width

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

public virtual int? Width { get; set; }

Property Value

int?

Methods

ComputeHasFocus()

Checks portal focus first, then window FocusManager.IsFocused.

protected bool ComputeHasFocus()

Returns

bool

ComputeIsInFocusPath()

Checks portal focus first, then window FocusManager.IsInFocusPath.

protected bool ComputeIsInFocusPath()

Returns

bool

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 virtual 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 abstract 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 virtual void OnDisposing()

OnPropertyChanged(string?)

Raises the PropertyChanged event.

protected void OnPropertyChanged(string? propertyName = null)

Parameters

propertyName string

The name of the property that changed.

PaintDOM(CharacterBuffer, LayoutRect, LayoutRect, Color, Color)

Paints the control's content directly to a CharacterBuffer.

public abstract void PaintDOM(CharacterBuffer buffer, LayoutRect bounds, LayoutRect clipRect, Color defaultForeground, Color defaultBackground)

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

defaultForeground Color

The default foreground color from the container.

defaultBackground Color

The default background color from the container.

SetActualBounds(LayoutRect)

Sets the actual rendered bounds from the layout system. Call this at the start of PaintDOM(CharacterBuffer, LayoutRect, LayoutRect, Color, Color) to record the control's position.

protected void SetActualBounds(LayoutRect bounds)

Parameters

bounds LayoutRect

The layout bounds assigned by the layout engine.

SetProperty<T>(ref T, T, Func<T, T>, string?)

Sets a property value with validation, change detection, notification, and automatic invalidation.

protected bool SetProperty<T>(ref T field, T value, Func<T, T> validate, string? propertyName = null)

Parameters

field T

Reference to the backing field.

value T

The new value.

validate Func<T, T>

Validation/transformation function applied before setting.

propertyName string

The property name (auto-filled by compiler).

Returns

bool

True if the value changed.

Type Parameters

T

The property type.

SetProperty<T>(ref T, T, string?)

Sets a property value with change detection, notification, and automatic invalidation.

protected bool SetProperty<T>(ref T field, T value, string? propertyName = null)

Parameters

field T

Reference to the backing field.

value T

The new value.

propertyName string

The property name (auto-filled by compiler).

Returns

bool

True if the value changed.

Type Parameters

T

The property type.

SubscribeToFocusManager()

Subscribes or re-subscribes to the parent window's FocusManager.FocusChanged event. Called whenever Container changes. Subclasses that override Container should call base.Container = value to ensure this subscription is maintained.

protected void SubscribeToFocusManager()

Events

GotFocus

Occurs when this control gains focus. Fired via the window's FocusManager.

public event EventHandler? GotFocus

Event Type

EventHandler

LostFocus

Occurs when this control loses focus. Fired via the window's FocusManager.

public event EventHandler? LostFocus

Event Type

EventHandler

PropertyChanged

Occurs when a property value changes.

public event PropertyChangedEventHandler? PropertyChanged

Event Type

PropertyChangedEventHandler