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
controlIWindowControllayoutILayoutContainer
LayoutNode(ILayoutContainer)
Creates a new container layout node (no control, just layout).
public LayoutNode(ILayoutContainer layout)
Parameters
layoutILayoutContainer
Properties
AbsoluteBounds
Gets the absolute bounds (screen coordinates) for rendering and hit testing.
public LayoutRect AbsoluteBounds { get; }
Property Value
Bounds
Gets the bounds relative to the parent node.
public LayoutRect Bounds { get; }
Property Value
Children
Gets the children of this node.
public IReadOnlyList<LayoutNode> Children { get; }
Property Value
Control
Gets the control this node represents.
public IWindowControl? Control { get; }
Property Value
DesiredSize
Gets the desired size calculated during the measure pass.
public LayoutSize DesiredSize { get; }
Property Value
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
Id
Gets a unique identifier for this node.
public Guid Id { get; }
Property Value
IsVisible
Gets or sets whether this node is visible (participates in layout).
public bool IsVisible { get; set; }
Property Value
Layout
Gets or sets the layout container that determines how children are arranged.
public ILayoutContainer? Layout { get; set; }
Property Value
NeedsArrange
Gets whether this node needs to be arranged.
public bool NeedsArrange { get; set; }
Property Value
NeedsMeasure
Gets whether this node needs to be measured.
public bool NeedsMeasure { get; set; }
Property Value
NeedsPaint
Gets whether this node needs to be painted.
public bool NeedsPaint { get; set; }
Property Value
Parent
Gets the parent node, if any.
public LayoutNode? Parent { get; }
Property Value
PortalChildren
Gets the portal children (render on top, for dropdowns/overlays).
public IReadOnlyList<LayoutNode> PortalChildren { get; }
Property Value
VerticalAlignment
Gets or sets the vertical alignment within the parent container.
public VerticalAlignment VerticalAlignment { get; set; }
Property Value
Methods
AddChild(LayoutNode)
Adds a child node.
public void AddChild(LayoutNode child)
Parameters
childLayoutNode
AddPortalChild(LayoutNode)
Adds a portal child (renders on top, for dropdowns/overlays).
public void AddPortalChild(LayoutNode child)
Parameters
childLayoutNode
Arrange(LayoutRect)
Arranges this node and all its children within the given bounds.
public void Arrange(LayoutRect finalRect)
Parameters
finalRectLayoutRect
ClearChildren()
Clears all children.
public void ClearChildren()
FindByControl(IWindowControl)
Finds a node by its control.
public LayoutNode? FindByControl(IWindowControl control)
Parameters
controlIWindowControl
Returns
GetDepth()
Gets the depth of this node in the tree (root = 0).
public int GetDepth()
Returns
GetRoot()
Gets the root node of this tree.
public LayoutNode GetRoot()
Returns
HitTest(int, int)
Performs hit testing to find the node at the specified absolute position.
public virtual LayoutNode? HitTest(int x, int y)
Parameters
Returns
InsertChild(int, LayoutNode)
Inserts a child node at the specified index.
public void InsertChild(int index, LayoutNode child)
Parameters
indexintchildLayoutNode
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
constraintsLayoutConstraints
Returns
MeasureControl(LayoutConstraints)
Measures the control's content to determine its desired size.
protected virtual LayoutSize MeasureControl(LayoutConstraints constraints)
Parameters
constraintsLayoutConstraints
Returns
Paint(CharacterBuffer, LayoutRect)
Paints this node and all its children to the buffer.
public void Paint(CharacterBuffer buffer, LayoutRect clipRect)
Parameters
bufferCharacterBufferclipRectLayoutRect
PaintControl(CharacterBuffer, LayoutRect)
Paints the control's content to the buffer.
protected virtual void PaintControl(CharacterBuffer buffer, LayoutRect clipRect)
Parameters
bufferCharacterBufferclipRectLayoutRect
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
bufferCharacterBufferclipRectLayoutRectdefaultFgColordefaultBgColor
RemoveChild(LayoutNode)
Removes a child node.
public bool RemoveChild(LayoutNode child)
Parameters
childLayoutNode
Returns
RemovePortalChild(LayoutNode)
Removes a portal child.
public bool RemovePortalChild(LayoutNode child)
Parameters
childLayoutNode
Returns
ToDebugString(int)
Returns a debug string representation of the node tree.
public string ToDebugString(int indent = 0)
Parameters
indentint
Returns
Visit(Action<LayoutNode>)
Visits all nodes in the tree (depth-first).
public void Visit(Action<LayoutNode> action)
Parameters
actionAction<LayoutNode>