Vixen
dd8b0a81
csharp
public abstract class TextField

Anything the user types into.

No guide page documents this yet — the page shows what the code says about itself.

Remarks

One editing core under every field in the set. A text box, a search box, a numeric input and a combo box's editable half are one caret, one selection and one keyboard map wearing four skins; writing the map four times is how a control library ends up with a field where Ctrl-Left works and one where it does not.

⚠ Single line unless AcceptsNewlines says otherwise, which only TextArea does. A one-line field's value scrolls sideways rather than wrapping; a text area wraps, takes a newline from Enter, and moves its caret between lines. Both are the same caret, the same selection and the same keyboard map — the difference is three predicates rather than a second control.

⚠ A text area does not scroll vertically yet. Its lines are drawn where they fall and a value taller than the box is clipped by it, which is honest and is not enough: the box is sized by the theme (textarea { min-height }) and a caller that expects to hold a long document should say how tall it wants to be. A scroll region round the text is owed.

The caret is an index into the value and the selection is a second one. Both are UTF-16 indices on grapheme boundaries, which is what ShapedText works in — so moving the caret over an emoji or a Devanagari syllable steps over the whole of it, and the arithmetic that decides is the conformance-tested code in the text assembly rather than a loop here that would get the interesting scripts wrong.

Fields and properties (36)

  • protected override string TagName

    The element name this type answers to when a caller does not choose one.

  • public string? Value
  • public string? Placeholder
  • public bool ReadOnly
  • public int MaxLength
  • public bool Required
  • public Func<string?, string?>? Validator

    What decides whether the value is acceptable, for a caller that will not subclass.

  • public string? ValidationMessage

    Why the value is not acceptable, or null when it is.

  • public bool IsValid

    Whether the value is acceptable.

  • public int CaretIndex

    Where the caret is, as a UTF-16 index into Value.

  • public TimeSpan CaretBlink

    How long the caret spends on, and then off. Zero draws it solid.

  • public CaretAffinity CaretAffinity

    Which of the two characters either side of CaretIndex the caret is on.

  • public int SelectionAnchor

    Where the selection started, as a UTF-16 index. Equal to the caret when nothing is selected.

  • public int SelectionStart

    The lower end of the selection.

  • public int SelectionEnd

    The upper end.

  • public bool HasSelection

    Whether anything is selected.

  • public string SelectedText

    The selected text.

  • public string Composition

    What an input method is composing at the caret, and has not committed.

  • public bool IsComposing

    Whether an input method has an uncommitted pre-edit in this field.

  • public int DisplayCaret

    Where the caret is in the string the field is displaying.

  • protected UiElement TextPart

    The element the value is drawn on.

  • protected override AccessibleRole NativeRole

    The role this kind of element has when nobody says otherwise.

  • protected override string? NativeAccessibleName
  • protected override string? NativeAccessibleValue
  • protected override AccessibleStates NativeAccessibleState
  • public bool CanCopy

    Whether there is something to put on the clipboard, and somewhere to put it.

  • public bool CanPaste

    Whether there is text on the clipboard and this field would take it.

  • protected virtual bool AcceptsNewlines

    Whether Enter puts a line break in the value rather than submitting it.

  • protected bool ShowsCaret

    Whether the caret is drawn: a field that cannot be typed into has none.

  • public Rectangle CaretArea
  • public bool AcceptsTextInput
  • public static readonly UiPropertyKey ValueProperty

    Identity for Value.

  • public static readonly UiPropertyKey PlaceholderProperty

    Identity for Placeholder.

  • public static readonly UiPropertyKey ReadOnlyProperty

    Identity for ReadOnly.

  • public static readonly UiPropertyKey MaxLengthProperty

    Identity for MaxLength.

  • public static readonly UiPropertyKey RequiredProperty

    Identity for Required.

Events (2)

  • public Action<TextField, string?>? ValueChanged

    Raised after the value changes, whoever changed it.

  • public Action<TextField>? Submitted

    Raised when Enter is pressed in the field.

Methods (23)

  • protected override void OnCreated()

    Builds whatever this element is made of, once, as it joins a document.

  • public void MoveCaret(int index, bool extend = false)

    Moves the caret, and either drops the selection or extends it.

  • public void MoveCaret(int index, CaretAffinity affinity, bool extend = false)

    Moves the caret to one side of an index, and either drops the selection or extends it.

  • public void SelectAll()

    Selects the whole value.

  • public void SelectWord(int index)

    Selects the word an index falls inside.

  • public void Replace(string insertion)

    Replaces the selection — or, with none, inserts at the caret.

  • public bool Undo()

    Takes back the last edit, if this field is under an undo manager.

  • public bool Redo()

    Puts back the last undone edit.

  • public bool Copy()

    Puts the selection on the clipboard.

  • public bool Cut()

    Puts the selection on the clipboard and deletes it.

  • public bool Paste()

    Replaces the selection with the clipboard's text.

  • protected virtual string? Coerce(string? value)

    What the field does with a value on its way in.

  • protected virtual string? Shown(string? value)

    What the field draws for a value on its way out.

  • protected virtual string? Validate(string? value)

    Whether a value is acceptable, and why not when it is not.

  • public void Revalidate()

    Asks Validate again and republishes the answer.

  • protected virtual void OnSubmit()

    Called when Enter is pressed, before Submitted is raised.

  • protected virtual void SelectAt(int index, int count)

    What a repeated tap selects.

  • protected override void OnDraw(DrawContext context)
  • public void ClearValue()

    Unsets Value, so it takes its default or its ancestor's value again.

  • public void ClearPlaceholder()

    Unsets Placeholder, so it takes its default or its ancestor's value again.

  • public void ClearReadOnly()

    Unsets ReadOnly, so it takes its default or its ancestor's value again.

  • public void ClearMaxLength()

    Unsets MaxLength, so it takes its default or its ancestor's value again.

  • public void ClearRequired()

    Unsets Required, so it takes its default or its ancestor's value again.

Used by (130, showing 40)

  • GalleryHelloUi
  • AccessibilityTreeTestsVixen.Ui.Controls.Tests
  • AccessibleNameLocalisationTestsVixen.Ui.Controls.Advanced.Tests
  • BindReachTestsVixen.Ui.Controls.Tests
  • CaretAffinityTestsVixen.Ui.Controls.Tests
  • CaretBlinkTestsVixen.Ui.Controls.Tests
  • CaretColourPixelTestsVixen.Ui.Controls.Tests
  • ClipboardTestsVixen.Ui.Controls.Tests
  • ColorPickerVixen.Ui.Controls.Advanced
  • ColorPickerTestsVixen.Ui.Controls.Advanced.Tests
  • ComboBoxVixen.Ui.Controls
  • ComboEditorVixen.Ui.Controls
  • CommandBindingTestsVixen.Ui.Controls.Tests
  • ControlThemeVisualTestsVixen.Ui.Controls.Tests
  • DataCellVixen.Ui.Controls.Advanced
  • DataGridVixen.Ui.Controls.Advanced
  • DataGridTestsVixen.Ui.Controls.Advanced.Tests
  • DialogServiceVixen.Ui.Controls
  • DialogTestsVixen.Ui.Controls.Tests
  • DisabledStateTestsVixen.Ui.Controls.Tests
  • DockingTestsVixen.Ui.Controls.Advanced.Tests
  • EditingParityTestsVixen.Ui.Controls.Advanced.Tests
  • ElementStateBitTestsVixen.Ui.Controls.Tests
  • FieldProbeVixen.Ui.Controls.Tests
  • FieldValidationTestsVixen.Ui.Controls.Tests
  • MarkupTestsVixen.Ui.Controls.Tests
  • NavigationInteractionTestsVixen.Ui.Controls.Tests
  • NestedMemberTestsVixen.Ui.Controls.Advanced.Tests
  • NodeCanvasVixen.Ui.Controls.Advanced
  • NodePortEditorVixen.Ui.Controls.Advanced
  • NumericInputVixen.Ui.Controls
  • ProbeVixen.Ui.Desktop.Tests
  • PropertyGridVixen.Ui.Controls.Advanced
  • PropertyGridTestsVixen.Ui.Controls.Advanced.Tests
  • RtlFieldMirroringTestsVixen.Ui.Controls.Tests
  • ScrubTestsVixen.Ui.Controls.Tests
  • SearchBoxVixen.Ui.Controls
  • SearchableReachTestsVixen.Ui.Controls.Tests
  • SearchableSheetVixen.Ui.Controls.Tests
  • SecureTextBoxVixen.Ui.Controls