CanvasTextField

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

Constructors

CanvasTextField

#
public CanvasTextField(string initial = null)
initial (string = null)

CanvasTextField

#
public CanvasTextField(TextWithCaret initial = null)
initial (Prose.TextWithCaret = null)

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.

Bounds

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

CaretAtEnd

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

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

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

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

EnterPressed

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

ErrorMessage

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

EscapePressed

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

Font

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

GotFocus

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

HasFocus

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

HasScrubTarget

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

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

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

Placeholder

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

Text

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

Tinting

#
public Func<int, string, Color?> Tinting { get; set; }
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

ClearYanker

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

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

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

Focus

#
public void Focus(bool selectAll)
selectAll (bool)

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

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

KeyDown

#
public Response KeyDown(KeyEventArgs e)
e (KeyEventArgs)

MouseDoubleClick

#
public Response MouseDoubleClick(ResponseMouseArgs e)
e (ResponseMouseArgs)

MouseDown

#
public Response MouseDown(ResponseMouseArgs e)
e (ResponseMouseArgs)

MouseDrag

#
public Response MouseDrag(ResponseMouseArgs e)
e (ResponseMouseArgs)

MouseOver

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

MouseUp

#
public Response MouseUp(ResponseMouseArgs e)
e (ResponseMouseArgs)

SetText

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

TextInput

#
public Response TextInput(TextInputEventArgs e)
e (TextInputEventArgs)

TintFromExpression

#
public static CanvasTextField.CharTints 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

#
public static CanvasTextField.CharTints TintFromKind(Func<char, Syntax> classify)
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.
classify (Func<char, CanvasTextField.Syntax>)Maps a character to its syntactic role.

TintFromMappingSyntax

#
public static CanvasTextField.CharTints 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

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

Events

TextChanged

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