Vixen
02b45cc4
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 (18)

  • 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 int CaretIndex

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

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

  • protected UiElement TextPart

    The element the value is drawn on.

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

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 (13)

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

  • protected virtual string? Coerce(string? value)

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

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

Used by (81, showing 40)

  • ShellHelloUi
  • ColorPickerVixen.Ui.Controls.Advanced
  • ColorPickerTestsVixen.Ui.Controls.Advanced.Tests
  • ComboBoxVixen.Ui.Controls
  • DataGridVixen.Ui.Controls.Advanced
  • DataGridTestsVixen.Ui.Controls.Advanced.Tests
  • DisabledStateTestsVixen.Ui.Controls.Tests
  • DockingTestsVixen.Ui.Controls.Advanced.Tests
  • NavigationInteractionTestsVixen.Ui.Controls.Tests
  • NestedMemberTestsVixen.Ui.Controls.Advanced.Tests
  • NodeCanvasVixen.Ui.Controls.Advanced
  • NodePortEditorVixen.Ui.Controls.Advanced
  • NumericInputVixen.Ui.Controls
  • PropertyGridVixen.Ui.Controls.Advanced
  • PropertyGridTestsVixen.Ui.Controls.Advanced.Tests
  • SearchBoxVixen.Ui.Controls
  • SelectionTestsVixen.Ui.Controls.Tests
  • TextAreaVixen.Ui.Controls
  • TextBoxVixen.Ui.Controls
  • TextFieldTestsVixen.Ui.Controls.Tests
  • TreeViewVixen.Ui.Controls.Advanced
  • TreeViewTestsVixen.Ui.Controls.Advanced.Tests
  • AddComponentMenuVixen.Editor.App
  • AddComponentMenuTestsVixen.Editor.App.Tests
  • AnimationClipViewVixen.Editor.AssetEditors
  • AnimationGraphViewVixen.Editor.AssetEditors
  • AssetPickerVixen.Editor.App
  • AssetPickerTestsVixen.Editor.App.Tests
  • AudioMixerViewVixen.Editor.AssetEditors
  • BehaviorAuthoringTestsVixen.Editor.App.Tests
  • BuildSettingsViewVixen.Editor.App
  • ChromeFixtureVixen.Editor.Ui.Tests
  • CommandDispatcherVixen.Editor.Ui
  • CommandPaletteVixen.Editor.Ui
  • ComponentDrawerVixen.Editor.Inspector
  • ComponentTestsVixen.Editor.App.Tests
  • CompositorViewVixen.Editor.AssetEditors
  • ConsoleViewVixen.Editor.Ui
  • DialogServiceVixen.Editor.Ui
  • DialogTestsVixen.Editor.Ui.Tests