TextTool is the editor's text-authoring tool, following the standard design-tool contract: a click on existing text opens an in-canvas editing session on that element with the caret at the clicked character, a click-drag on empty canvas draws a text box, and a double-click on empty canvas starts point text (a plain click on empty canvas creates nothing - it only commits any active session). Typing, Enter (hard line break), Backspace/Delete, and caret movement edit the live <text> element through the DOM mutation seam; box text wraps greedily to the box width using the engine's measured character geometry. Cmd/Ctrl+B/I/U toggle bold, italic, and underline on the element. Escape, clicking away, or switching tools commits the session as a single undoable operation (an empty session on a newly created element deletes it, leaving the document unchanged; emptying an existing element deletes it as an undoable edit).
More...
#include <array>
#include <chrono>
#include <cstddef>
#include <optional>
#include <span>
#include <string>
#include <vector>
#include "donner/base/Box.h"
#include "donner/base/Transform.h"
#include "donner/base/Vector2.h"
#include "donner/editor/SelectionTransformHandles.h"
#include "donner/editor/Tool.h"
#include "donner/svg/SVGTextElement.h"
TextTool is the editor's text-authoring tool, following the standard design-tool contract: a click on existing text opens an in-canvas editing session on that element with the caret at the clicked character, a click-drag on empty canvas draws a text box, and a double-click on empty canvas starts point text (a plain click on empty canvas creates nothing - it only commits any active session). Typing, Enter (hard line break), Backspace/Delete, and caret movement edit the live <text> element through the DOM mutation seam; box text wraps greedily to the box width using the engine's measured character geometry. Cmd/Ctrl+B/I/U toggle bold, italic, and underline on the element. Escape, clicking away, or switching tools commits the session as a single undoable operation (an empty session on a newly created element deletes it, leaving the document unchanged; emptying an existing element deletes it as an undoable edit).
◆ donner::editor::TextTool::EditingChrome
| struct donner::editor::TextTool::EditingChrome |
Caret + frame chrome for the active editing session, in document space.
| Class Members |
|
Vector2d |
caretBottomDoc |
|
|
Vector2d |
caretTopDoc |
Caret line endpoints (top, bottom). |
|
optional< array< Vector2d, 4 > > |
frameCornersDoc |
Session frame corners (local TL, TR, BR, BL mapped through the text's transform): the authored box for box text, the laid-out ink bounds for point text. An ORIENTED quad - after a rotate it stays aligned to the text's rotation, never the axis-aligned envelope. Absent when the session has no frame yet (empty point text). |
|
float |
frameOpacity = 1.0f |
Opacity for the point-text frame and handles. Box-text frames remain fully opaque. New point text starts at zero, pointer movement reveals it, and text input fades it back to zero. |
◆ donner::editor::TextTool::DragPreviewChrome
| struct donner::editor::TextTool::DragPreviewChrome |
Drag-to-create preview chrome (document space): the live box being dragged out, the first text baseline it would create (one default font size below the box top, clamped into the box), and an I-beam marker at the future caret position. Distinct from the selection marquee so the gesture reads as "creating a text box".
| Class Members |
|
Vector2d |
baselineEndDoc |
|
|
Vector2d |
baselineStartDoc |
First-baseline segment endpoints (left, right - inset from the frame). |
|
Box2d |
boxDoc |
The live drag rectangle. |
|
Vector2d |
ibeamBottomDoc |
|
|
Vector2d |
ibeamTopDoc |
I-beam bar endpoints at the future caret position (top, bottom). |