Table of Contents

Class ShapeRendererRegistry

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

Registry for shape renderers, allowing custom renderers for different shape types.

public class ShapeRendererRegistry
Inheritance
ShapeRendererRegistry
Inherited Members

Examples

// Register a custom renderer via singleton
ShapeRendererRegistry.Instance.Register("custom-shape", new CustomShapeRenderer());

// Or via FlowCanvas property
canvas.ShapeRenderers.Register("custom-shape", new CustomShapeRenderer());

// Get a renderer for a shape
var renderer = ShapeRendererRegistry.Instance.GetRenderer(shape.Type);

Remarks

The registry follows the same pattern as NodeRendererRegistry and EdgeRendererRegistry, providing a consistent extensibility model for all element types.

Shape types are identified by their Type property (e.g., "rectangle", "line", "text", "ellipse").

Constructors

ShapeRendererRegistry()

Creates a new ShapeRendererRegistry with built-in renderers registered.

public ShapeRendererRegistry()

ShapeRendererRegistry(IShapeRenderer)

Creates a new ShapeRendererRegistry with a custom default renderer.

public ShapeRendererRegistry(IShapeRenderer defaultRenderer)

Parameters

defaultRenderer IShapeRenderer

The default renderer to use when no type-specific renderer is found.

Properties

Instance

Gets the shared singleton instance for global access.

public static ShapeRendererRegistry Instance { get; }

Property Value

ShapeRendererRegistry

Methods

GetRegisteredTypes()

Gets all registered shape types.

public IEnumerable<string> GetRegisteredTypes()

Returns

IEnumerable<string>

An enumerable of registered shape type identifiers.

GetRenderer(ShapeElement)

Gets the renderer for a specific shape element.

public IShapeRenderer GetRenderer(ShapeElement shape)

Parameters

shape ShapeElement

The shape element.

Returns

IShapeRenderer

The appropriate renderer for the shape.

GetRenderer(string)

Gets the renderer for the specified shape type. Falls back to the default renderer if no specific renderer is registered.

public IShapeRenderer GetRenderer(string shapeType)

Parameters

shapeType string

The shape type to get a renderer for.

Returns

IShapeRenderer

The renderer for the shape type, or the default renderer.

Exceptions

InvalidOperationException

Thrown if no renderer is found and no default is set.

HasRenderer(string)

Checks if a renderer is registered for the specified type.

public bool HasRenderer(string shapeType)

Parameters

shapeType string

The shape type to check.

Returns

bool

True if a renderer is registered; otherwise, false.

Register(string, IShapeRenderer)

Registers a renderer for a specific shape type.

public void Register(string shapeType, IShapeRenderer renderer)

Parameters

shapeType string

The shape type identifier (e.g., "rectangle", "line").

renderer IShapeRenderer

The renderer implementation.

Reset()

Resets the registry to built-in renderers only. Useful for testing.

public void Reset()

SetDefaultRenderer(IShapeRenderer)

Sets the default renderer used when no type-specific renderer is found.

public void SetDefaultRenderer(IShapeRenderer renderer)

Parameters

renderer IShapeRenderer

The default renderer.