Package-level declarations

Types

Link copied to clipboard
data class BackgroundPattern(val painter: Painter, val tint: Color? = null)

Repeating image painted behind drawing elements, sitting on top of the solid State.bgColor but underneath all strokes and shapes.

Link copied to clipboard

Keys for the SDK's built-in font families. Hosts can register additional families via the controller; these three are always available.

Link copied to clipboard
data class DrawingExportDto(val bgColor: String, val elements: List<ElementDto>)
Link copied to clipboard
Link copied to clipboard
sealed class Element

Base sealed class for all drawable elements on the canvas.

Link copied to clipboard
data class ElementDto(val id: String, val type: String, val zIndex: Int, val points: List<String>, val strokeColor: String, val strokeWidth: Float, val alpha: Float? = null, val shapeType: String? = null, val fillColor: String? = null, val rotation: Float? = null, val cornerRadius: Float? = null, val strokeStyle: String? = null, val bend: String? = null, val startBinding: String? = null, val endBinding: String? = null, val createdAt: Long? = null, val modifiedAt: Long? = null, val samples: List<String>? = null, val strokeEnabled: Boolean? = null, val imageData: String? = null, val intrinsicWidth: Float? = null, val intrinsicHeight: Float? = null, val opacity: Float? = null, val text: String? = null, val fontFamilyKey: String? = null, val fontSize: Float? = null, val alignment: String? = null, val textTopLeft: String? = null, val wrapWidth: Float? = null)
Link copied to clipboard
sealed class Event
Link copied to clipboard
sealed class Intent

Represents a user action or system event that should change the drawing state.

Link copied to clipboard
sealed class Mode

Represents the current drawing mode, determining what type of element is created when the user interacts with the canvas.

Link copied to clipboard
data class PayLoad(val bgColor: Color, val elements: List<Element>)
Link copied to clipboard

Resize handle positions around a selected element's bounding box. Eight handles in total: four corners and four edge midpoints.

Link copied to clipboard
@Serializable
data class SerializableDrawing(val bgColor: String, val elements: List<SerializableElement>)
Link copied to clipboard
@Serializable
data class SerializableElement(val id: String, val type: String, val zIndex: Int, val points: List<String>, val strokeColor: String, val strokeWidth: Float, val alpha: Float? = null, val shapeType: String? = null, val fillColor: String? = null, val rotation: Float? = null, val cornerRadius: Float? = null, val strokeStyle: String? = null, val bend: String? = null, val startBinding: String? = null, val endBinding: String? = null, val createdAt: Long? = null, val modifiedAt: Long? = null, val samples: List<String>? = null, val strokeEnabled: Boolean? = null, val imageData: String? = null, val intrinsicWidth: Float? = null, val intrinsicHeight: Float? = null, val opacity: Float? = null, val text: String? = null, val fontFamilyKey: String? = null, val fontSize: Float? = null, val alignment: String? = null, val textTopLeft: String? = null, val wrapWidth: Float? = null)
Link copied to clipboard
sealed class ShapeType

Defines how Element.Shape is rendered on the canvas.

Link copied to clipboard
data class State(val elements: List<Element> = emptyList(), val history: List<List<Element>> = emptyList(), val future: List<List<Element>> = emptyList(), val selectedIds: Set<String> = emptySet(), val marqueeRect: Rect? = null, val viewport: Viewport = Viewport(), val tempPanActive: Boolean = false, val strokeColor: Color = Color.Red, val strokeWidth: Float = 10.0f, val currentItemCornerRadius: Float = 0.0f, val currentItemStrokeStyle: StrokeStyle = StrokeStyle.SOLID, val currentItemFillColor: Color? = null, val currentItemStrokeEnabled: Boolean = true, val toolMemory: Map<Mode, ToolSettings> = emptyMap(), val currentItemFontSize: Float = 24.0f, val currentItemFontFamilyKey: String = DEFAULT_FONT_FAMILY_KEY, val currentItemTextAlignment: TextAlignment = TextAlignment.LEFT, val opacity: Float = 1.0f, val bgColor: Color = Color.Black, val bgPattern: BackgroundPattern? = null, val mode: Mode = Mode.PEN, val eraserSize: Float = 20.0f, val erasingSessionDirty: Boolean = false)

Represents the complete immutable state of the drawing canvas.

Link copied to clipboard

Stroke pattern applied when rendering a stroked (non-filled) Element.Shape.

Link copied to clipboard

Horizontal alignment inside an Element.Text's wrap box.

Link copied to clipboard
data class ToolSettings(val strokeColor: Color, val strokeWidth: Float, val strokeStyle: StrokeStyle, val cornerRadius: Float, val fillColor: Color?, val strokeEnabled: Boolean, val fontSize: Float, val fontFamilyKey: String, val textAlignment: TextAlignment)

Per-tool snapshot captured by State.toolMemory. Restored to State's top-level style fields when the user swaps back to a tool.

Link copied to clipboard
data class Viewport(val offset: Offset = Offset.Zero, val scale: Float = 1.0f)

Camera transform for the infinite canvas. Elements are stored in world coordinates; the viewport projects them onto the screen using a translate

Properties

Link copied to clipboard

Default font family key used when no Element.Text.fontFamilyKey is specified and as the fallback when a referenced key isn't registered.

Link copied to clipboard

The mode currently driving user input. Equals State.mode unless the user is holding the space bar (or has otherwise activated a temporary pan), in which case it returns Mode.PAN. The original State.mode is preserved so release of the temp-pan modifier restores the previous tool.

Link copied to clipboard

The spatial positions of every sample in a freehand stroke, in order. Use this when the caller only cares about geometry (bounds, hit testing, path tessellation); reach for Element.Path.samples directly when widths are also needed.

Functions

Link copied to clipboard
fun angleFromCenter(center: Offset, pointer: Offset): Float

Angle in degrees from center to pointer measured from the positive x-axis, clockwise positive (matching Compose's rotation direction).

Link copied to clipboard

World-space point on the curve at t = 0.5 — the spot where the bend handle sits.

Link copied to clipboard

Point on this shape's outline closest to the ray from the shape's center toward target. Used by arrow connectors to terminate at the boundary instead of sinking into the shape.

Link copied to clipboard

Axis-aligned bounding box of the element in unrotated logical space.

Link copied to clipboard

World-space attachment point for an arrow connector binding to this shape.

Link copied to clipboard

Quadratic-bezier control point for a curved ShapeType.LINE / ShapeType.ARROW.

Link copied to clipboard
fun Element.hitTest(point: Offset, tolerance: Float = 8.0f): Boolean

Hit test against a world-space point. Inverse-rotates the point into the element's logical space, then applies a per-type test that accounts for stroke width and the provided pick tolerance.

Link copied to clipboard

Whether mode participates in State.toolMemory save/restore on Intent.SetMode.

Link copied to clipboard
fun resizeBounds(originalBounds: Rect, rotation: Float, handle: ResizeHandle, pointer: Offset): Rect

Compute new bounds when dragging handle of originalBounds to world-space pointer pointer. The opposite corner / edge midpoint stays anchored in world space, even when the element is rotated.

Link copied to clipboard
fun resizeBoundsForElement(element: Element, handle: ResizeHandle, pointer: Offset): Rect

Type-aware variant of resizeBounds. The returned bounds is sized so that element.withBounds(returnedBounds).bounds() == returnedBounds — i.e., no second-pass snapping inside withBounds can shift the result.

Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard

Encode a Element.PathSample as a comma-separated string. Chosen over a JSON-object form to keep PEN strokes (which can have thousands of samples) small on the wire.

Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
fun topmostHit(elements: List<Element>, point: Offset, tolerance: Float = 8.0f): Element?

Topmost element under point, picked by descending zIndex.

Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
fun Element.touched(now: Long = kotlin.time.Clock.System.now().toEpochMilliseconds()): Element

Stamp Element.modifiedAt with now (defaults to current epoch ms). Call this on every mutation site so sync layers see a fresh LWW timestamp.

Link copied to clipboard
Link copied to clipboard

Translate all points by delta. Rotation unchanged.

Link copied to clipboard
fun Element.withBounds(newBounds: Rect): Element

Scale points so the bounding box matches newBounds. For two-point shapes this snaps start/end to the new bbox corners (preserving orientation of the original drag direction). For freedraw paths every point is scaled linearly. Rotation unchanged.

Link copied to clipboard

Absolute rotation in degrees.