CanvasTextField

public sealed class CanvasTextField
A canvas-native, single-line editable text field.

Constructors

CanvasTextField

#
public CanvasTextField(
initial = null
)

CanvasTextField

#
public CanvasTextField(
initial = null
)

Properties

Alignment

#
Horizontal alignment of the text within Bounds. Only relevant while the text fits; overflowing text always scrolls to keep the caret in view.
public TextAlignment Alignment { get; set; }

Background

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

public Color Background { get; set; }

Bounds

#
Anchor rectangle in canvas content coordinates.
public RectangleF Bounds { get; set; }

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.
public bool CaretAtEnd { get; }

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.
public bool CaretAtStart { get; }

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.
public Func<Prose.CaretDeparture, bool> CaretDeparting { get; set; }

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).
public float CaretX { get; }

EnterPressed

#
Invoked when the user commits with Enter.
public Action EnterPressed { get; set; }

ErrorMessage

#
Gets or sets the error message associated with the current state of the text.
public string ErrorMessage { get; set; }

EscapePressed

#
Invoked when the user cancels with Escape.
public Action EscapePressed { get; set; }

Font

#
Font used to typeset and hit-test the text.
public Font Font { get; set; }

GotFocus

#
Invoked when the field gains focus, before any edit is made.
public Action GotFocus { get; set; }

HasFocus

#
Gets whether this field currently owns the edit focus.
public bool HasFocus { get; }

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.
public bool HasScrubTarget { get; }

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.
public int Inset { get; set; }

Invalid

#
Gets whether the current state of the text is considered invalid. This property returns true when the ErrorMessage has been set.
public bool Invalid { get; }

Placeholder

#
Faint text shown when the field is empty and unfocused.
public string Placeholder { get; set; }

Text

#
Gets the current text content.
public string Text { get; }

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.

public Func<int, string, Color?> Tinting { get; set; }

Methods

ClearYanker

#
Clears the scrub target (call when the mouse leaves). Returns true if it changed.
public bool ClearYanker()

Defocus

#
public void Defocus()

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.
public void DeleteBackwards()

Draw

#
Draw the text, caret and selection.
public void Draw(
context,
Graphics context.
Color
colour,
Colour of text.
prefix = null,
Optional prefix to draw in a transparent version of the colour.
suffix = null
Optional suffix to draw in a transparent version of the colour.
)

Focus

#
public void Focus(
selectAll
)

FocusAtEnd

#
Focuses the field and places the caret behind the last character, clearing any selection. Used when hopping into a field from its right.
public void FocusAtEnd()

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.
public void FocusAtStart()

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.
public void FocusAtX()

KeyDown

#
public Response KeyDown(
KeyEventArgs
e
)

MouseDoubleClick

#
public Response MouseDoubleClick()

MouseDown

#
public Response MouseDown()

MouseDrag

#
public Response MouseDrag()

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.
public bool MouseOver()

MouseUp

#
public Response MouseUp()

SetText

#
Replaces the content without raising TextChanged. Ignored while focused.
public void SetText(
text
)

TextInput

#
public Response TextInput(
TextInputEventArgs
e
)

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.
public static CanvasTextField.CharTints TintFromExpression()

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.
public static CanvasTextField.CharTints TintFromKind(
classify
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.
public static CanvasTextField.CharTints TintFromMappingSyntax()

TintFromTreeSyntax

#
Create a CanvasTextField.CharTints for fields containing data-tree selection notation, as understood by SiteRule.
public static CanvasTextField.CharTints TintFromTreeSyntax()

Events

TextChanged

#
Raised whenever the text string changes.
public event EventHandler<string> TextChanged