State

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.

All drawing operations produce a new State instance rather than mutating the existing one, following functional programming principles. This ensures:

  • Clear state history for undo/redo

  • Predictable state changes

  • Easy debugging and testing

See also

Constructors

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

Properties

Link copied to clipboard

Solid background color of the canvas (painted underneath bgPattern)

Link copied to clipboard

Optional repeating image tiled above bgColor and below all elements; runtime decoration only and not persisted by JSON/SVG export

Link copied to clipboard
Link copied to clipboard

Default fill color applied to new Element.Shapes (rect/circle/triangle). null means stroke-only — the shape renders without a fill. Mutated by Intent.SetFillColor; the selection form Intent.SetSelectedFillColor writes to selected elements instead.

Link copied to clipboard

Default font family key applied to new text elements. See Intent.SetFontFamily. Always resolves via the host's io.ak1.drawbox.text.FontRegistry at render time, so an unregistered key here falls back to sans without crashing the canvas.

Link copied to clipboard

Default font size in world pixels applied to text elements inserted via Mode.TEXT. Mutated by Intent.SetFontSize (the non-selection form); the selection form Intent.SetSelectedFontSize writes to the selected element instead and leaves this default untouched.

Link copied to clipboard

Whether the outline pass is drawn on new Element.Shapes. When false, new shapes render fill-only. Mutated by Intent.SetStrokeEnabled; the selection form Intent.SetSelectedStrokeEnabled writes to selected elements instead.

Link copied to clipboard

Default horizontal alignment for new text elements; see Intent.SetTextAlignment.

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

List of all drawable elements currently on canvas

Link copied to clipboard

World-space radius used by Mode.ERASER for hit-testing. Pressure-aware platforms can modulate this at the gesture layer without persisting the modulated value here.

Link copied to clipboard

Within a single erase gesture: has any tick actually removed an element yet? Used to guarantee at most one history snapshot per gesture, taken lazily on the first hit. A tap or drag that never intersects an element therefore consumes no undo slot. Cleared by Intent.BeginErase and Intent.EndErase; not persisted.

Link copied to clipboard

Stack of element snapshots for redo (populated when Undo runs).

Link copied to clipboard

Stack of prior element snapshots for undo. Newest entry is last.

Link copied to clipboard

Transient rectangle drawn while a marquee selection is in progress. Null when no marquee is active. Not undoable.

Link copied to clipboard
val mode: Mode

Current drawing mode determining what gets created on user input

Link copied to clipboard

Alpha channel for drawing (0.0 = transparent, 1.0 = opaque)

Link copied to clipboard

IDs of currently selected elements. Drives selection chrome rendering and the targets of move/resize/rotate/delete intents.

Link copied to clipboard

Color for drawing lines and shape strokes

Link copied to clipboard

Width/thickness of strokes in pixels

Link copied to clipboard
Link copied to clipboard

Per-tool memory: each drawing mode (PEN, RECTANGLE, CIRCLE, TRIANGLE, ARROW, LINE, TEXT) snapshots its own color / width / style / fill / corner / text settings. On Intent.SetMode the outgoing mode's current top-level fields are captured here, and the incoming mode's saved settings are restored to the top-level fields. Non-drawing modes (SELECT, ERASER, PAN) don't participate — they pass through settings untouched. Users get the "each pen remembers its own color" behavior Samsung Notes / OPPO Notes use.

Link copied to clipboard