Skip to content

Shape behavior ​

What a person can do to a shape comes from its definition in pure Dart. The engine and the Flutter canvas read the same declaration; an overlay never decides on its own whether an operation is allowed. Part of it you declare as behavior; the rest follows from the shape's anatomy.

Declare behavior ​

dart
import 'package:vyuh_diagram_core/extension_api.dart';
import 'package:vyuh_diagram_core/vyuh_diagram_core.dart';

final note = ShapeDefinition(
  type: 'app.note',
  size: const DiagramSize(240, 120),
  behavior: const ShapeBehavior(
    rotatable: false,
    textSizing: ShapeTextSizing.fitHeight,
  ),
  body: const ShapeText('body', text: 'Height follows the text'),
);

The note cannot rotate, and its height follows its text, so only its left and right resize handles show.

ShapeBehavior propertyDefaultEffect
selectabletrueWhether the shape can be selected.
deletabletrueWhether the shape can be deleted.
movabletrueWhether the shape can be moved.
resizabletrueWhether the shape can be resized; false shows no resize handles.
rotatabletrueWhether the shape can be rotated, from a corner or the rotation handle.
rotationHandlefalseShows a stem-and-circle rotation control above a rotatable shape.
textSizingShapeTextSizing.fixedfixed keeps the authored frame; growHeight treats the authored height as a minimum and grows downward; fitHeight makes the height follow the content exactly.

Resize handles follow from these: all eight when resizable, only the left and right sides when the height fits the content, and none when not resizable. behavior.resizeHandles lists them. Handle names describe the shape's local sides; their positions follow shape rotation. The rotation stem is presentation only: it cannot enable rotation when rotatable is false.

What follows from the anatomy ​

Editing is not declared with flags. It follows from what the shape is made of:

The shape hasSo a person can editRead it as
An outlineFill and strokedefinition.paintsSurface
An outline that rounds its corners (rect(), regularPolygon(), editablePath(), or a path with cornerRadius: true)Corner radiusdefinition.cornerRadiusEditable
An editable ShapeText, or content such as a tableTextdefinition.textEditable
A PathValueField read by an editable path outlinePointsdefinition.pathValue
A regular polygon outlineIts number of sidesdefinition.sidesValue
An ImageValueFieldThe imagedefinition.imageValue
Any other valueThat value, with one control eachdefinition.customValues

definition.propertyEditors lists the resulting inspector sections in order. To remove a control, change the anatomy: a shape with outline: null has no fill or stroke, ShapeOutline.rect(cornerRadius: false) has square corners, a ShapeText(..., editable: false) is text people cannot edit on the canvas, and body: null hosts no text.

Containers ​

A shape that owns child elements declares a container:

dart
import 'package:vyuh_diagram_core/extension_api.dart';

final lane = ShapeDefinition(
  type: 'app.lane',
  container: const ShapeContainer(clips: true, resizesChildren: false),
  behavior: const ShapeBehavior(rotatable: false),
);
ShapeContainer propertyDefaultEffect
clipsfalseInstances may clip their children to the outline with clipContent. A clipping container always shows its border, so its extent stays visible.
resizesChildrentrueWhether resizing the container scales its children. Movement and rotation always carry them.

A container may also declare collapse: ShapeCollapseDefinition(...) for a compact presentation. See frames and ownership.

Definition policy versus instance state ​

Behavior is fixed on each registered definition; there is no per-instance behavior callback. Locking an instance keeps it selectable but stops moving, resizing, rotating, deleting and editing it, while preserving its appearance. A collapsed container cannot resize or rotate, and its text does not size it. Content can narrow behavior too: a table whose controls disable resizeTable makes its shape not resizable. resolved.behavior on a resolved shape combines all of these. Command admission additionally checks the diagram's DiagramRules and operation preconditions.

For a different permanent behavior, register another shape definition. Do not replace a loaded registry definition or hide handles in an overlay as a substitute for engine policy.

See shape anatomy to package this definition in an extension and Canvas foundations to render it.