Vixen
dd8b0a81
csharp
public class UiElement

One node of the user interface.

Read the guide page for this →

Remarks

Elements are classes, and that is a deliberate departure from the rest of the engine. An ECS component is a struct because there are a million of them in a hot loop; a UI node has identity, virtual behaviour and event handlers, and there are ten thousand of them. The struct-of-arrays discipline lives where the loops actually are — the layout store and, later, the draw list — and this type is a handle into them.

It holds no geometry and no style of its own. The cascade owns the computed style, the layout tree owns the result, and everything read from here is a lookup into one of the two. That is what keeps a hundred identical list rows from being a hundred copies of anything.

Fields and properties (69)

  • public AccessibleRole Role

    What kind of thing this element is, for assistive technology.

  • public bool IsInAccessibilityTree

    Whether this element is a node a screen reader sees.

  • public string? AccessibleName

    What this element is called, as a screen reader would say it.

  • public string? AccessibleDescription

    The longer sentence a screen reader reads after the name, if there is one.

  • public string? AccessibleValue

    What this element currently holds, for the kinds of element that hold something.

  • public AccessibleStates AccessibleState

    The conditions to announce with this element: what it is doing, plus whatever was declared on it.

  • public AccessibleStates DeclaredAccessibleState

    The bits an application declared on this element itself.

  • public IReadOnlyList<AccessibleRelationship> AccessibleRelationships

    Every relation declared on this element, in the order they were added.

  • protected internal virtual AccessibleRole NativeRole

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

  • protected internal virtual string? NativeAccessibleName

    What this kind of element calls itself, from what it already holds.

  • protected internal virtual string? NativeAccessibleValue

    What this kind of element currently holds, formatted the way it should be said.

  • protected internal virtual AccessibleStates NativeAccessibleState

    The states this kind of element computes from what it already holds.

  • public string? CommandScope

    The command scope this element declares, or null if it declares none.

  • public bool IsCommandTransparent

    Whether the focus landing here should leave the command route pointing where it was.

  • public bool IsInCommandTransparentSubtree

    Whether this element is inside anything that declares itself command-transparent.

  • public string? EffectiveCommandScope

    The scope in force here: this element's, or the nearest ancestor's that declares one.

  • public IEnumerable<string> CommandHandlerIds

    The ids this element handles, in the order they were declared.

  • public IReadOnlyList<IResponder> Responders

    The responders this element has appended at its own position on the chain.

  • public IEditableDocument? HostedDocument

    The document this element hosts, if it is the one that hosts it.

  • public bool AllowDrop
  • public bool HasInlineStyle

    Whether anything has been written on this element directly.

  • public UiDocument Document

    The document this belongs to.

  • public bool IsRemoved

    Whether it has been taken out of its document.

  • public string Tag

    Its element name, which selectors match on.

  • public string DeclaredTag

    The name this instance's own type answers to, whatever Tag it was given.

  • protected internal virtual string TagName

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

  • protected internal virtual UiElement ContentHost

    Where content written inside this element's tag actually goes.

  • public UiElement? Parent

    Its parent, or null for the root.

  • public UiSurface? SurfaceRoot

    The surface this element is the root of, if it is one.

  • public IReadOnlyList<UiElement> Children

    Its children, in document order.

  • public float LineHeight

    Its line-height in pixels, or NaN for the font's own.

  • public float LetterSpacing

    Its letter-spacing in pixels.

  • public float WordSpacing

    Its word-spacing in pixels: extra added to every word-separator character.

  • public float TextIndent

    Its text-indent in pixels: how far the first line is pushed in.

  • public FontFeatureSet FontFeatures

    The OpenType features its text is shaped with.

  • public ParagraphDirection ParagraphDirection

    The base direction its text is laid out at.

  • public int ZIndex

    Where it sits among its siblings when they overlap.

  • public ComputedStyle Style

    What the cascade decided. Interned, so two alike elements share one object.

  • public float FontSize

    Its resolved font size in pixels, which every em on it measures against.

  • public float Left

    Its left edge, relative to its parent, after the last layout pass.

  • public float Top

    Its top edge, relative to its parent.

  • public float Width

    Its width.

  • public float Height

    Its height.

  • public string? Language

    What language this element's own text is written in, as a BCP-47 tag.

  • public string ResolvedLanguage

    The language in force here: this element's, or the nearest ancestor's, or the document's.

  • public ElementState State

    Its interaction state — hover, focus, active — which selectors match on.

  • public char AccessKey
  • public bool Focusable
  • public int TabIndex
  • public bool IsFocusScope
  • public bool IsFocused

    Whether the focus is on it.

  • public string? Text
  • public float OffsetX
  • public float OffsetY
  • public float AbsoluteLeft

    Its left edge in document space, after the last layout pass.

  • public float AbsoluteTop

    Its top edge in document space.

  • public Rectangle Bounds

    Where it is in document space, after the last layout pass.

  • public UiTransform? Transform

    The affine its rotate and scale paint it under, or null for neither.

  • public bool IsHitTestVisible

    Whether a pointer can land on it. pointer-events: none and visibility: hidden each make it false.

  • public int IndexInParent

    Where this element sits among its siblings, or -1 if it has no parent.

  • public IUndoManager? UndoManager

    The undo manager this element hosts, if it is one.

  • public static readonly UiPropertyKey AllowDropProperty

    Identity for AllowDrop.

  • public static readonly UiPropertyKey AccessKeyProperty

    Identity for AccessKey.

  • public static readonly UiPropertyKey FocusableProperty

    Identity for Focusable.

  • public static readonly UiPropertyKey TabIndexProperty

    Identity for TabIndex.

  • public static readonly UiPropertyKey IsFocusScopeProperty

    Identity for IsFocusScope.

  • public static readonly UiPropertyKey TextProperty

    Identity for Text.

  • public static readonly UiPropertyKey OffsetXProperty

    Identity for OffsetX.

  • public static readonly UiPropertyKey OffsetYProperty

    Identity for OffsetY.

Events (1)

Methods (53)

  • public void ClearRole()

    Hands the role back to NativeRole.

  • public UiElement? AccessibleRelationTarget(AccessibleRelation relation)

    The first element this one is related to in a given way, if there is one.

  • public void AddAccessibleRelation(AccessibleRelation relation, UiElement target)

    Says that this element is related to another one in a way the tree does not show.

  • public bool RemoveAccessibleRelation(AccessibleRelation relation, UiElement target)

    Stops saying so.

  • public int ClearAccessibleRelations(AccessibleRelation relation)

    Drops every relation of one kind, whatever it pointed at.

  • protected void InvalidateAccessibility()

    Tells the document that something a bridge is showing may have changed.

  • public void Provide<T>(T value) where T : notnull

    Makes a value available to everything inside this element.

  • public bool Unprovide<T>()

    Takes a provided value back off this element.

  • public bool Provides<T>()

    Whether this element itself provides one, ignoring its ancestors.

  • public T? Inject<T>()

    The nearest provided value of that type, looking up from here.

  • public bool TryInject<T>(out T? value)

    The same, told apart from a provided null-shaped default.

  • public bool RequestClose(UiCloseReason reason = DocumentClosed)

    Asks whether what this element holds may be closed.

  • public void AddCommandHandler(string id, Action execute, Func<bool>? canExecute = null, Func<string?>? title = null, Func<bool>? isChecked = null)

    Declares that this element handles a command.

  • public bool RemoveCommandHandler(string id)

    Stops handling a command.

  • public bool TryGetCommandHandler(string id, out CommandHandler handler)

    The handler this element declared for a command id, if it declared one.

  • public void AddResponder(IResponder responder)

    Appends a responder at this element's position on the chain.

  • public bool RemoveResponder(IResponder responder)

    Takes a responder back off.

  • public IEditableDocument? FindHostedDocument()

    The nearest document on the way up, or the UI document's, or none.

  • public void SetStyle(string property, string? value)

    Writes a declaration onto this element, over anything a stylesheet said.

  • public void SetStyle(string property, string? value, bool important)

    The same, for a declaration that carried !important.

  • public string? GetStyle(string property)

    Reads back a declaration written with SetStyle.

  • public void ClearStyle()

    Takes every inline declaration off this element.

  • public UiElement()

    Creates a detached element.

  • protected internal virtual UiElement? NamedHost(string name)

    Where content addressed to one of this control's named slots goes.

  • public UiElement Add(string tag, string? id = null, params ReadOnlySpan<string> classNames)

    Adds a child element.

  • public T Add<T>(string? tag = null, string? id = null, params ReadOnlySpan<string> classNames) where T : UiElement, new()

    Adds a child of a particular element type.

  • public bool AddClass(string className)

    Adds a class, and invalidates what that could have changed.

  • public bool RemoveClass(string className)

    Removes a class.

  • public bool HasClass(string className)

    Whether it carries a class.

  • public string? Attribute(string name)

    An attribute's value, if it has one.

  • public void SetAttribute(string name, string value)

    Sets an attribute.

  • public TextLayout? Block()

    Its text, shaped and wrapped to the width it is being laid out in.

  • public TextLayout? Block(float width)

    Its text wrapped to a given width.

  • public TextLayout? Ellipsized(float contentWidth)

    Its text as it should be drawn in a box this wide: the same block as Block unless text-overflow: ellipsis is in force and a line does not fit, in which case that line ends in an ellipsis.

  • protected internal virtual void OnCreated()

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

  • protected internal virtual void OnChildAdded(UiElement child)

    Called on the parent, once a child of it has been created and initialised.

  • protected internal virtual void OnRemoved()

    Called once, as the element leaves the document.

  • protected internal virtual void OnPropertyChanged(UiPropertyKey key)

    Raised after any generated UI property changes.

  • protected void RaisePropertyChanged(UiPropertyKey key)

    Tells the override and the subscribers that a property changed.

  • protected internal virtual void OnDraw(DrawContext context)

    Draws whatever this element is, beyond what a stylesheet can describe.

  • public void AddHandler<T>(Action<UiElement, T> handler, RoutingStrategy strategy = Bubble, bool handledEventsToo = false) where T : UiEvent

    Listens for an event on its way through this element.

  • public bool RemoveHandler<T>(Action<UiElement, T> handler) where T : UiEvent

    Stops listening.

  • public void Raise<T>(T args) where T : UiEvent

    Sends an event to this element and along its route.

  • public void Remove()

    Takes this element and everything under it out of its document.

  • public IUndoManager? FindUndoManager()

    The nearest undo manager on the way up, or the document's, or none.

  • public void ClearAllowDrop()

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

  • public void ClearAccessKey()

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

  • public void ClearFocusable()

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

  • public void ClearTabIndex()

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

  • public void ClearIsFocusScope()

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

  • public void ClearText()

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

  • public void ClearOffsetX()

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

  • public void ClearOffsetY()

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

Used by (887, showing 40)

  • ActionBarMmo.Ui
  • BagGridMmo.Ui
  • ChatPanelMmo.Ui
  • GalleryHelloUi
  • HierarchyHelloUi
  • HudMmo.Ui
  • InspectorHelloUi
  • LootRollMmo.Ui
  • QuestTrackerMmo.Ui
  • ShellHelloUi
  • StylesheetTestsMmo.Ui.Tests
  • UnitFrameMmo.Ui
  • VendorPanelMmo.Ui
  • DocumentBenchmarksVixen.Benchmarks.Ui
  • EditorShellBenchmarksVixen.Benchmarks.Ui
  • EditorShellSceneVixen.Benchmarks.Ui
  • AccessKeyTestsVixen.Ui.Tests
  • AccessibilityCoverageTestsVixen.Ui.Controls.Advanced.Tests
  • AccessibilityCoverageTestsVixen.Ui.Controls.Tests
  • AccessibilityNodeVixen.Ui
  • AccessibilityNotificationTestsVixen.Ui.Controls.Tests
  • AccessibilitySnapshotVixen.Ui.Testing
  • AccessibilityTestsVixen.Ui.Tests
  • AccessibilityTreeVixen.Ui
  • AccessibilityTreeSourceVixen.Ui
  • AccessibilityTreeTestsVixen.Ui.Tests
  • AccessibilityTreeTestsVixen.Ui.Controls.Tests
  • AccessibilityTreeTestsVixen.Ui.Controls.Advanced.Tests
  • AccessibleNameLocalisationTestsVixen.Ui.Controls.Tests
  • AccessibleNameLocalisationTestsVixen.Ui.Controls.Advanced.Tests
  • AccessibleRelationshipVixen.Ui
  • AccordionVixen.Ui.Controls
  • AdvancedFixtureVixen.Ui.Controls.Advanced.Tests
  • AlertVixen.Ui.Controls
  • AmbientAcrossDockingTestsVixen.Ui.Controls.Advanced.Tests
  • AmbientConsumerVixen.Ui.Controls.Tests
  • AmbientProviderVixen.Ui.Controls.Tests
  • AmbientValueTestsVixen.Ui.Controls.Tests
  • AnimationTestsVixen.Ui.Tests
  • ApplicationBarTestsVixen.Ui.Controls.Tests