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
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
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
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
Bindings
Gets the binding collection for this control. Lazily allocated on first access.
public BindingCollection Bindings { get; }
Property Value
Container
Gets or sets the parent container that hosts this control.
public virtual IContainer? Container { get; set; }
Property Value
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
Margin
Gets or sets the margin (spacing) around the control.
public virtual Margin Margin { get; set; }
Property Value
Name
Gets or sets the unique name identifier for this control, used for lookup.
public string? Name { get; set; }
Property Value
StickyPosition
Gets or sets whether this control should stick to the top or bottom during scrolling.
public virtual StickyPosition StickyPosition { get; set; }
Property Value
Tag
Gets or sets an arbitrary object value that can be used to store custom data.
public object? Tag { get; set; }
Property Value
VerticalAlignment
Gets or sets the vertical alignment of the control within its container.
public virtual VerticalAlignment VerticalAlignment { get; set; }
Property Value
Visible
Gets or sets whether this control is visible.
public virtual bool Visible { get; set; }
Property Value
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
ComputeIsInFocusPath()
Checks portal focus first, then window FocusManager.IsInFocusPath.
protected bool ComputeIsInFocusPath()
Returns
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
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 virtual void OnDisposing()
OnPropertyChanged(string?)
Raises the PropertyChanged event.
protected void OnPropertyChanged(string? propertyName = null)
Parameters
propertyNamestringThe 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
bufferCharacterBufferThe buffer to paint to.
boundsLayoutRectThe absolute bounds where the control should paint.
clipRectLayoutRectThe clipping rectangle (visible area).
defaultForegroundColorThe default foreground color from the container.
defaultBackgroundColorThe 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
boundsLayoutRectThe 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
fieldTReference to the backing field.
valueTThe new value.
validateFunc<T, T>Validation/transformation function applied before setting.
propertyNamestringThe property name (auto-filled by compiler).
Returns
- bool
True if the value changed.
Type Parameters
TThe 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
fieldTReference to the backing field.
valueTThe new value.
propertyNamestringThe property name (auto-filled by compiler).
Returns
- bool
True if the value changed.
Type Parameters
TThe 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
LostFocus
Occurs when this control loses focus. Fired via the window's FocusManager.
public event EventHandler? LostFocus
Event Type
PropertyChanged
Occurs when a property value changes.
public event PropertyChangedEventHandler? PropertyChanged