Table of Contents

Class LayoutNode

Namespace
SharpConsoleUI.Layout
Assembly
SharpConsoleUI.dll

Represents a node in the layout DOM tree. Wraps an IWindowControl and manages layout state (measure/arrange/paint).

public class LayoutNode
Inheritance
LayoutNode
Derived
Inherited Members

Constructors

LayoutNode(IWindowControl?, ILayoutContainer?)

Creates a new layout node for the specified control.

public LayoutNode(IWindowControl? control, ILayoutContainer? layout = null)

Parameters

control IWindowControl
layout ILayoutContainer

LayoutNode(ILayoutContainer)

Creates a new container layout node (no control, just layout).

public LayoutNode(ILayoutContainer layout)

Parameters

layout ILayoutContainer

Properties

AbsoluteBounds

Gets the absolute bounds (screen coordinates) for rendering and hit testing.

public LayoutRect AbsoluteBounds { get; }

Property Value

LayoutRect

Bounds

Gets the bounds relative to the parent node.

public LayoutRect Bounds { get; }

Property Value

LayoutRect

Children

Gets the children of this node.

public IReadOnlyList<LayoutNode> Children { get; }

Property Value

IReadOnlyList<LayoutNode>

Control

Gets the control this node represents.

public IWindowControl? Control { get; }

Property Value

IWindowControl

DesiredSize

Gets the desired size calculated during the measure pass.

public LayoutSize DesiredSize { get; }

Property Value

LayoutSize

ExplicitHeight

Gets or sets an explicit height for this node (null = auto).

public int? ExplicitHeight { get; set; }

Property Value

int?

ExplicitWidth

Gets or sets an explicit width for this node (null = auto).

public int? ExplicitWidth { get; set; }

Property Value

int?

FlexFactor

Gets or sets the flex factor for proportional sizing (default 1.0).

public double FlexFactor { get; set; }

Property Value

double

Id

Gets a unique identifier for this node.

public Guid Id { get; }

Property Value

Guid

IsVisible

Gets or sets whether this node is visible (participates in layout).

public bool IsVisible { get; set; }

Property Value

bool

Layout

Gets or sets the layout container that determines how children are arranged.

public ILayoutContainer? Layout { get; set; }

Property Value

ILayoutContainer

NeedsArrange

Gets whether this node needs to be arranged.

public bool NeedsArrange { get; set; }

Property Value

bool

NeedsMeasure

Gets whether this node needs to be measured.

public bool NeedsMeasure { get; set; }

Property Value

bool

NeedsPaint

Gets whether this node needs to be painted.

public bool NeedsPaint { get; set; }

Property Value

bool

Parent

Gets the parent node, if any.

public LayoutNode? Parent { get; }

Property Value

LayoutNode

PortalChildren

Gets the portal children (render on top, for dropdowns/overlays).

public IReadOnlyList<LayoutNode> PortalChildren { get; }

Property Value

IReadOnlyList<LayoutNode>

VerticalAlignment

Gets or sets the vertical alignment within the parent container.

public VerticalAlignment VerticalAlignment { get; set; }

Property Value

VerticalAlignment

Methods

AddChild(LayoutNode)

Adds a child node.

public void AddChild(LayoutNode child)

Parameters

child LayoutNode

AddPortalChild(LayoutNode)

Adds a portal child (renders on top, for dropdowns/overlays).

public void AddPortalChild(LayoutNode child)

Parameters

child LayoutNode

Arrange(LayoutRect)

Arranges this node and all its children within the given bounds.

public void Arrange(LayoutRect finalRect)

Parameters

finalRect LayoutRect

ClearChildren()

Clears all children.

public void ClearChildren()

FindByControl(IWindowControl)

Finds a node by its control.

public LayoutNode? FindByControl(IWindowControl control)

Parameters

control IWindowControl

Returns

LayoutNode

GetDepth()

Gets the depth of this node in the tree (root = 0).

public int GetDepth()

Returns

int

GetRoot()

Gets the root node of this tree.

public LayoutNode GetRoot()

Returns

LayoutNode

HitTest(int, int)

Performs hit testing to find the node at the specified absolute position.

public virtual LayoutNode? HitTest(int x, int y)

Parameters

x int
y int

Returns

LayoutNode

InsertChild(int, LayoutNode)

Inserts a child node at the specified index.

public void InsertChild(int index, LayoutNode child)

Parameters

index int
child LayoutNode

InvalidateArrange()

Invalidates arrange for this node and propagates down to descendants.

public void InvalidateArrange()

InvalidateMeasure()

Invalidates measure for this node and propagates up to ancestors.

public void InvalidateMeasure()

InvalidatePaint()

Invalidates paint for this node only.

public void InvalidatePaint()

Measure(LayoutConstraints)

Measures this node and all its children. Returns the desired size based on content and constraints.

public LayoutSize Measure(LayoutConstraints constraints)

Parameters

constraints LayoutConstraints

Returns

LayoutSize

MeasureControl(LayoutConstraints)

Measures the control's content to determine its desired size.

protected virtual LayoutSize MeasureControl(LayoutConstraints constraints)

Parameters

constraints LayoutConstraints

Returns

LayoutSize

Paint(CharacterBuffer, LayoutRect)

Paints this node and all its children to the buffer.

public void Paint(CharacterBuffer buffer, LayoutRect clipRect)

Parameters

buffer CharacterBuffer
clipRect LayoutRect

PaintControl(CharacterBuffer, LayoutRect)

Paints the control's content to the buffer.

protected virtual void PaintControl(CharacterBuffer buffer, LayoutRect clipRect)

Parameters

buffer CharacterBuffer
clipRect LayoutRect

PaintControl(CharacterBuffer, LayoutRect, Color, Color)

Paints the control's content to the buffer with specified default colors.

protected virtual void PaintControl(CharacterBuffer buffer, LayoutRect clipRect, Color defaultFg, Color defaultBg)

Parameters

buffer CharacterBuffer
clipRect LayoutRect
defaultFg Color
defaultBg Color

RemoveChild(LayoutNode)

Removes a child node.

public bool RemoveChild(LayoutNode child)

Parameters

child LayoutNode

Returns

bool

RemovePortalChild(LayoutNode)

Removes a portal child.

public bool RemovePortalChild(LayoutNode child)

Parameters

child LayoutNode

Returns

bool

ToDebugString(int)

Returns a debug string representation of the node tree.

public string ToDebugString(int indent = 0)

Parameters

indent int

Returns

string

Visit(Action<LayoutNode>)

Visits all nodes in the tree (depth-first).

public void Visit(Action<LayoutNode> action)

Parameters

action Action<LayoutNode>