Inline Text Editor
Built-in inline text editor for Element.Text. Renders as the element it edits — same font family, font size, alignment, color, wrap width, and position — so the caret is the only visible "you are editing" affordance. The element underneath is expected to be hidden by the host via io.ak1.drawbox.DrawBox's hiddenElementIds parameter to avoid ghosting.
Embedders are free to ignore this composable and ship their own editor (modal, side-panel, IME-driven, etc.) — the SDK's InsertText / UpdateText intents and Element.Text model don't depend on it. This exists as the "drop-in" path for hosts that don't want to write one.
Pixel fidelity with the renderer
The implementation deliberately mirrors the SDK's text rendering path:
TextStyle.fontSizeis(element.fontSize × viewport.scale).spdirectly — NOT.toSp().Density.toSp(Float)treats its input as dp-equivalent and divides byfontScale; feeding it screen pixels would shrink the editor by1 / fontScalewhenever the system text scale is non-unit. Going.spdirect routes editor and renderer through the same final conversion (fontSize × density × fontScale), so on-screen pixels match across any density / fontScale / viewport.scale combination.width = element.wrapWidth × viewport.scale(nofillMaxWidth) — the field wraps at the same point asTextMeasurer.measure(constraints = Constraints(maxWidth = wrapWidth)).lineHeightis left unspecified in both editor and renderer so line breaks land identically.Position via
Modifier.offset { IntOffset(...) }re-reads Viewport.worldToScreen each composition — pan / zoom while editing reposition smoothly.
State
draft / onDraftChange are hoisted so the host's outside-tap overlay can read the current draft when committing, without coordinating focus events. Recommended host flow:
When the user enters TEXT mode and taps, the SDK dispatches
Intent.InsertText("")from the canvas tap handler.Host detects a new empty
Element.Text(e.g. via aLaunchedEffect(state.elements)), records its id aseditingId, seedsdraft = "".Host passes
hiddenElementIds = setOf(editingId)toDrawBox.Host renders this composable + a full-screen click-catcher overlay. Tapping outside the field triggers commit (
updateText(id, draft)if non-empty, elseIntent.DeleteElement(id)).
Font family
The family is resolved internally from FontRegistry via Element.Text.fontFamilyKey. Hosts that want a different family register a new key on app launch and set io.ak1.drawbox.presentation.viewmodel.DrawBoxController.setFontFamily before the next insert.
Parameters
the text element being edited.
the current camera transform — used to project the element's world position into screen space and to scale font size.
current edit content. Hosted by the caller so a sibling "outside-tap commits" overlay can read the latest value at any time.
fires on every keystroke with the new draft.