Table of Contents

Interface IViewportState

Namespace
FlowGraph.Core.Rendering
Assembly
FlowGraph.Core.dll

Mutable viewport state for controlling pan/zoom operations.

Use this interface to programmatically control the viewport, such as centering on elements, fitting to bounds, or implementing custom navigation.

public interface IViewportState : IReadOnlyViewportState, ICoordinateTransformer
Inherited Members
Extension Methods

Methods

CenterOn(Point)

Centers the viewport on a specific canvas point.

After this call, the specified canvas point will be at the center of the viewport. Zoom level is not changed.

void CenterOn(Point canvasPoint)

Parameters

canvasPoint Point

The point in canvas coordinates to center on.

FitToBounds(Rect, double)

Adjusts zoom and pan to fit the specified canvas bounds within the viewport.

Use this to implement "fit to content" or "zoom to selection" features. The resulting view will show all of canvasBounds with the specified padding around the edges.

void FitToBounds(Rect canvasBounds, double padding = 50)

Parameters

canvasBounds Rect

The bounds to fit, in canvas coordinates. Pass the bounding box of all elements you want to show.

padding double

Padding in screen pixels to leave around the bounds. Default is 50.

Pan(double, double)

Pans the viewport by the specified delta in screen coordinates.

Positive deltaX moves the view right (canvas moves left). Positive deltaY moves the view down (canvas moves up).

void Pan(double deltaX, double deltaY)

Parameters

deltaX double

Pan amount in X direction (screen pixels).

deltaY double

Pan amount in Y direction (screen pixels).

Reset()

Resets the viewport to default state (zoom = 1.0, centered on origin).

void Reset()

SetOffset(double, double)

Sets the pan offset directly.

void SetOffset(double offsetX, double offsetY)

Parameters

offsetX double

New X offset in screen coordinates.

offsetY double

New Y offset in screen coordinates.

SetZoom(double, Point?)

Sets the zoom level, optionally zooming toward a specific screen point.

When zoomCenter is provided, the canvas point under that screen position will remain stationary after zooming. This creates a natural "zoom toward cursor" behavior.

void SetZoom(double zoom, Point? zoomCenter = null)

Parameters

zoom double

The new zoom level. Values are typically clamped to a min/max range (e.g., 0.1 to 5.0).

zoomCenter Point?

Optional viewport coordinate to zoom toward. If null, zooms toward the center of the viewport.