CanvasTextField
A canvas-native, single-line editable text field.
Constructors
Properties
Alignment
#public TextAlignment Alignment { get; set; }
Horizontal alignment of the text within Bounds. Only relevant while the text fits; overflowing text always scrolls to keep the caret in view.
Background
#public Color Background { get; set; }
Background colour behind the field, used only to render the digit-scrub balloon icon. Set by the host each draw so it tracks the theme.
Deliberately not initialised from SystemColors: fields are constructed inside object constructors, which run on thread-pool threads during plugin loading, and on WPF the system colours are read off theme brushes owned by whichever thread touched them first. Reading one here from the wrong thread throws, and takes the owning object's constructor down with it.
CaretAtEnd
#Gets whether the caret sits behind the last character with no selection, i.e. a plain rightwards step has nowhere to go inside this field.
CaretAtStart
#Gets whether the caret sits in front of the first character with no selection, i.e. a plain leftwards step has nowhere to go inside this field.
CaretDeparting
#Invoked when a key press wants to leave this field: an arrow at a boundary the caret cannot cross, a backspace in front of the first character, or a vertical step, which a single-line field can never absorb. Return true once the caret has been moved to a neighbouring context, which marks the key as handled; returning false (or leaving this unset) keeps the caret put.
CaretX
#Gets the content-space x coordinate of the caret. Only meaningful after the field has been drawn at least once (its character ranges are laid out during Draw).
HasScrubTarget
#Gets whether a numeric block is currently under the cursor, as of the last MouseOver(ResponseMouseArgs), and a scrub would therefore have something to drag. Hosts which only forward the press conditionally need this to decide.
Inset
#Horizontal margin kept clear inside Bounds when typesetting. The text is laid out within the inset rectangle, so a caret at either end of the content lands just beside the boundary rather than on top of it. Hit testing and clipping still use the full bounds, so the margin remains part of the field.
Invalid
#Gets whether the current state of the text is considered invalid. This property returns true when the ErrorMessage has been set.
Tinting
#Optional per-grapheme colour override, for syntax hinting. Given the grapheme index within the text and the grapheme cluster itself, it returns the colour to draw it in. When null, every grapheme uses the colour passed to Draw(Context, Color, string, string).
Assign this directly for something bespoke or trivial. For anything which needs to actually parse the text, build a CanvasTextField.CharTints instead: it resolves the whole string once and reduces this callback to an array lookup.
Methods
Defocus
#public void Defocus()
DeleteBackwards
#public void DeleteBackwards()
Delete the grapheme cluster in front of the caret, as a backspace would. Used by hosts which accept an eating departure from a neighbouring field.
Draw
#Draw the text, caret and selection.
FocusAtEnd
#public void FocusAtEnd()
Focuses the field and places the caret behind the last character, clearing any selection. Used when hopping into a field from its right.
FocusAtStart
#public void FocusAtStart()
Focuses the field and places the caret in front of the first character, clearing any selection. Used when hopping into a field from its left.
FocusAtX
#Focuses the field and places the caret nearest a content-space x coordinate, clearing any selection. Used to preserve the horizontal position when hopping between vertically-stacked fields.
Parameters:
| x (float) |
MouseOver
#Re-evaluate the digit-scrub target under a content-space point (call on hover while the scrub modifier is down). Returns true if the balloon state changed.
Parameters:
| e (ResponseMouseArgs) |
SetText
#Replaces the content without raising TextChanged. Ignored while focused.
Parameters:
| text (string) |
TintFromExpression
#Create a CanvasTextField.CharTints for fields containing expression code, as understood by Expression. Unlike TintFromKind(Func<char, CanvasTextField.Syntax>) this scans the text left to right, so it can recognise what a character on its own can never reveal: decimal points, exponents, signed literals and quoted strings.
TintFromKind
#Create a CanvasTextField.CharTints which colours single characters by the role
classify assigns them. Multi-character grapheme clusters and CanvasTextField.Syntax.Plain characters keep the field's own colour.Parameters:
| classify (Func<char, CanvasTextField.Syntax>) | Maps a character to its syntactic role. |
TintFromMappingSyntax
#Create a CanvasTextField.CharTints for fields containing path mapping notation, as understood by PathMap. The path portion (inside curly braces) and the item portion (inside square brackets) each use their own palette, and within each portion wildcards, integer constants, and variables including their operators are told apart.
TintFromTreeSyntax
#Create a CanvasTextField.CharTints for fields containing data-tree selection notation, as understood by SiteRule.