Class DefaultNodeRenderer
- Namespace
- FlowGraph.Avalonia.Rendering.NodeRenderers
- Assembly
- FlowGraph.Avalonia.dll
Default node renderer that creates a standard bordered box with text. Supports inline label editing via IEditableNodeRenderer.
public class DefaultNodeRenderer : IEditableNodeRenderer, INodeRenderer
- Inheritance
-
DefaultNodeRenderer
- Implements
- Derived
- Inherited Members
Methods
BeginEdit(Control, Node, NodeRenderContext, Action<string>, Action)
Enters edit mode - replaces the label TextBlock with a TextBox.
public virtual void BeginEdit(Control visual, Node node, NodeRenderContext context, Action<string> onCommit, Action onCancel)
Parameters
visualControlnodeNodecontextNodeRenderContextonCommitAction<string>onCancelAction
CreateNodeContent(Node, NodeRenderContext)
Creates the content inside the node. Override to customize.
protected virtual Control CreateNodeContent(Node node, NodeRenderContext context)
Parameters
nodeNodecontextNodeRenderContext
Returns
- Control
CreateNodeVisual(Node, NodeRenderContext)
Creates the visual representation for a node.
public virtual Control CreateNodeVisual(Node node, NodeRenderContext context)
Parameters
nodeNodeThe node data to render.
contextNodeRenderContextThe rendering context with theme, scale, and settings.
Returns
- Control
A Control representing the node visual.
EndEdit(Control, Node, NodeRenderContext)
Exits edit mode - removes the TextBox and shows the label.
public virtual void EndEdit(Control visual, Node node, NodeRenderContext context)
Parameters
visualControlnodeNodecontextNodeRenderContext
FindContentPanel(Control)
Finds the content panel in the node visual.
protected Grid? FindContentPanel(Control visual)
Parameters
visualControl
Returns
- Grid
FindLabelTextBlock(Grid)
Finds the label TextBlock in the content panel.
protected TextBlock? FindLabelTextBlock(Grid contentPanel)
Parameters
contentPanelGrid
Returns
- TextBlock
GetBorderBrush(Node, ThemeResources)
Gets the appropriate border brush based on node state. Priority: Selected > Highlighted > Normal
protected virtual IBrush GetBorderBrush(Node node, ThemeResources theme)
Parameters
nodeNodethemeThemeResources
Returns
- IBrush
GetBorderThickness(Node)
Gets the appropriate border thickness based on node state.
protected virtual Thickness GetBorderThickness(Node node)
Parameters
nodeNode
Returns
- Thickness
GetDisplayText(Node)
Gets the display text for the node. Override to customize.
protected virtual string GetDisplayText(Node node)
Parameters
nodeNode
Returns
GetEditableText(Node)
Gets the text to edit. Override to customize.
protected virtual string GetEditableText(Node node)
Parameters
nodeNode
Returns
GetHeight(Node, FlowCanvasSettings)
Gets the default height of the node in canvas units (before scaling). Return null to use the default height from settings.
public virtual double? GetHeight(Node node, FlowCanvasSettings settings)
Parameters
nodeNodesettingsFlowCanvasSettings
Returns
GetMinHeight(Node, FlowCanvasSettings)
Gets the minimum height for resizing. Return null for no minimum.
public virtual double? GetMinHeight(Node node, FlowCanvasSettings settings)
Parameters
nodeNodesettingsFlowCanvasSettings
Returns
GetMinWidth(Node, FlowCanvasSettings)
Gets the minimum width for resizing. Return null for no minimum.
public virtual double? GetMinWidth(Node node, FlowCanvasSettings settings)
Parameters
nodeNodesettingsFlowCanvasSettings
Returns
GetWidth(Node, FlowCanvasSettings)
Gets the default width of the node in canvas units (before scaling). Return null to use the default width from settings.
public virtual double? GetWidth(Node node, FlowCanvasSettings settings)
Parameters
nodeNodesettingsFlowCanvasSettings
Returns
IsEditing(Control)
Gets whether the node is currently in edit mode.
public virtual bool IsEditing(Control visual)
Parameters
visualControl
Returns
UpdateSelection(Control, Node, NodeRenderContext)
Updates the visual state when selection changes.
public virtual void UpdateSelection(Control visual, Node node, NodeRenderContext context)
Parameters
visualControlThe node's visual control.
nodeNodeThe node data.
contextNodeRenderContextThe rendering context.
UpdateSize(Control, Node, NodeRenderContext, double, double)
Updates the size of an existing node visual.
public virtual void UpdateSize(Control visual, Node node, NodeRenderContext context, double width, double height)
Parameters
visualControlThe node's visual control.
nodeNodeThe node data.
contextNodeRenderContextThe rendering context.
widthdoubleThe new width in canvas units.
heightdoubleThe new height in canvas units.
Remarks
IMPORTANT: Implementations MUST update ALL child elements within the visual, not just the root container. Failing to update child elements will cause the visual to appear unchanged during resize operations until a full re-render occurs.
For composite visuals (e.g., a Grid containing Rectangles, Borders, or Canvases), iterate through children and update their Width/Height properties accordingly.
public void UpdateSize(Control visual, Node node, NodeRenderContext context, double width, double height)
{
var scaledWidth = width * context.Scale;
var scaledHeight = height * context.Scale;
if (visual is Grid grid)
{
grid.Width = scaledWidth;
grid.Height = scaledHeight;
// CRITICAL: Also update all child elements
foreach (var child in grid.Children)
{
if (child is Rectangle rect)
{
rect.Width = scaledWidth;
rect.Height = scaledHeight;
}
}
}
}