Text

data class Text(val id: String = Uuid.random().toString(), val type: String = "Text", val text: String, val fontFamilyKey: String = DEFAULT_FONT_FAMILY_KEY, val fontSize: Float, val color: Color, val alignment: TextAlignment = TextAlignment.LEFT, val topLeft: Offset, val wrapWidth: Float, val measuredHeight: Float, val opacity: Float = 1.0f, val zIndex: Int = 0, val rotation: Float = 0.0f, val createdAt: Long = 0, val modifiedAt: Long = 0) : Element

Block-level plain-text element. Single style applies to the whole block; rich-text features (inline bold / italic spans, links, cursor-within-text editing) are intentionally NOT in scope here and are tracked separately.

Two-piece geometry — the user owns the wrap width, the renderer owns the measured height. After every layout, if the rendered height drifts from measuredHeight, the renderer dispatches a non-snapshotting io.ak1.drawbox.domain.model.Intent.SyncTextMeasuredHeight to bring the model back in sync — so bounds is always accurate without the data layer needing a androidx.compose.ui.text.TextMeasurer.

Resize semantics follow from this split: dragging a horizontal handle changes wrapWidth (causing a re-wrap and a height update on the next frame); dragging a vertical handle is a no-op since height is auto.

Constructors

Link copied to clipboard
constructor(id: String = Uuid.random().toString(), type: String = "Text", text: String, fontFamilyKey: String = DEFAULT_FONT_FAMILY_KEY, fontSize: Float, color: Color, alignment: TextAlignment = TextAlignment.LEFT, topLeft: Offset, wrapWidth: Float, measuredHeight: Float, opacity: Float = 1.0f, zIndex: Int = 0, rotation: Float = 0.0f, createdAt: Long = 0, modifiedAt: Long = 0)

Properties

Link copied to clipboard

Horizontal alignment inside the wrap box.

Link copied to clipboard

Text color.

Link copied to clipboard
open override val createdAt: Long

Epoch milliseconds at which this element was first created. Used for ordered replay (and later as a tie-break source for collab clocks). 0L means "unknown" — element predates the timestamp field; consumers that sort by createdAt should treat 0 as "earliest".

Link copied to clipboard

Logical name resolved via the host-side io.ak1.drawbox.presentation.viewmodel.DrawBoxController.registerFont registry. Unknown keys fall back to sans.

Link copied to clipboard

Em size in world pixels.

Link copied to clipboard
open override val id: String

Unique identifier for this element

Link copied to clipboard

Renderer-owned cached height. Initialized to a single-line guess at insertion time and refreshed by the sync intent after the first layout pass. Never written by user gestures.

Link copied to clipboard
open override val modifiedAt: Long

Epoch milliseconds at which any property of this element last changed. On creation, equals createdAt. Bumped via touched on every mutation path so sync layers can resolve concurrent edits with LWW semantics.

Link copied to clipboard

Render-time alpha (0.0..1.0), independent of color's own alpha channel.

Link copied to clipboard
open override val rotation: Float

Rotation in degrees, applied around the element's axis-aligned bounding box center at render time. Points stored on the element are in the unrotated (logical) coordinate space.

Link copied to clipboard

Raw string content. Newlines (\n) are honored as hard breaks; auto-wrap fills each visual line up to wrapWidth.

Link copied to clipboard

World-space top-left corner of the wrap box.

Link copied to clipboard
open override val type: String

String identifier of the element type for serialization

Link copied to clipboard

World-space wrap width — the only knob the user manipulates via resize handles.

Link copied to clipboard
open override val zIndex: Int

Layering order (higher values appear on top)

Functions

Link copied to clipboard

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

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
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

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.