Table of Contents

Interface IRenderTarget

Namespace
FlowGraph.Avalonia.Rendering
Assembly
FlowGraph.Avalonia.dll

Abstraction for adding temporary visual elements during interaction.

This interface provides a rendering-mode agnostic way to create temporary visuals such as connection preview lines, selection boxes, and drag previews. It handles coordinate transforms and container selection internally based on the current rendering mode (Visual Tree vs Direct Rendering).

Key principle: All coordinates passed to this interface are in canvas space. The implementation handles conversion to viewport coordinates when necessary (e.g., in Direct Rendering mode).

public interface IRenderTarget

Examples

// In ConnectingState
public override void Enter(InputStateContext context)
{
    var startCanvas = context.RenderModel.GetPortPosition(sourceNode, sourcePort, fromOutput);

    // Create temp line - coordinates are in canvas space
    _lineHandle = context.RenderTarget.CreateConnectionPreview(
        startCanvas, startCanvas, 
        context.Theme.EdgeStroke, 2.0);
}

public override StateTransitionResult HandlePointerMoved(InputStateContext context, PointerEventArgs e)
{
    var endCanvas = context.Coordinates.GetPointerCanvasPosition(e);

    // Update with canvas coordinates - transform handled internally
    context.RenderTarget.UpdateConnectionPreview(_lineHandle, startCanvas, endCanvas);
}

public override void Exit(InputStateContext context)
{
    _lineHandle?.Dispose();
}

Methods

CreateConnectionPreview(CanvasPoint, CanvasPoint, IBrush, double, double[]?)

Creates a temporary bezier connection line for previewing connections.

The line is styled with dashed strokes and reduced opacity to indicate it's a preview rather than a committed connection.

IConnectionPreviewHandle CreateConnectionPreview(CanvasPoint start, CanvasPoint end, IBrush stroke, double strokeThickness, double[]? dashArray = null)

Parameters

start CanvasPoint

Start point in canvas coordinates (port position).

end CanvasPoint

End point in canvas coordinates (cursor or snap target).

stroke IBrush

Stroke brush for the line.

strokeThickness double

Stroke thickness (in screen pixels, not canvas units).

dashArray double[]

Optional dash pattern. Defaults to [5, 3] for preview style.

Returns

IConnectionPreviewHandle

A handle that can be used to update or dispose the preview line.

CreateSelectionBox(CanvasRect, IBrush?, IBrush, double)

Creates a temporary selection rectangle.

Used during box selection to show the selection area.

ISelectionBoxHandle CreateSelectionBox(CanvasRect bounds, IBrush? fill, IBrush stroke, double strokeThickness)

Parameters

bounds CanvasRect

Rectangle bounds in canvas coordinates.

fill IBrush

Optional fill brush (typically semi-transparent).

stroke IBrush

Stroke brush for the border.

strokeThickness double

Border thickness (in screen pixels).

Returns

ISelectionBoxHandle

A handle that can be used to update or dispose the selection box.

Invalidate()

Invalidates the render target, triggering a redraw.

In Visual Tree mode, this may do nothing (elements update automatically). In Direct Rendering mode, this calls InvalidateVisual() on the renderer.

void Invalidate()