Vixen
02b45cc4
csharp
public class UiElement

One node of the user interface.

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

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

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

  • 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 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 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 bool IsHitTestVisible

    Whether a pointer can land on it. pointer-events: none makes it false.

  • public int IndexInParent

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

  • 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 (29)

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

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

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

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

  • protected internal virtual void OnCreated()

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

  • 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 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 (404, showing 40)

  • ShellHelloUi
  • UiHostHelloUi
  • DocumentBenchmarksVixen.Benchmarks.Ui
  • AccessKeyTestsVixen.Ui.Tests
  • AccordionVixen.Ui.Controls
  • AdvancedFixtureVixen.Ui.Controls.Advanced.Tests
  • AlertVixen.Ui.Controls
  • AvatarVixen.Ui.Controls
  • BareVixen.Ui.Tests
  • BatchTestsVixen.Ui.Tests
  • BoundVixen.Ui.Tests
  • BranchingVixen.Ui.Tests
  • BreadcrumbVixen.Ui.Controls
  • BreadcrumbItemVixen.Ui.Controls
  • BuildContextVixen.Ui
  • ButtonBaseVixen.Ui.Controls
  • ButtonTestsVixen.Ui.Controls.Tests
  • CardVixen.Ui.Tests
  • CardVixen.Ui.Controls
  • CheckBoxVixen.Ui.Controls
  • ClickableVixen.Ui.Tests
  • CodeEditorVixen.Ui.Controls.Advanced
  • CodeEditorTestsVixen.Ui.Controls.Advanced.Tests
  • CodeGutterRowVixen.Ui.Controls.Advanced
  • CodeLineVixen.Ui.Controls.Advanced
  • CodeOverlayVixen.Ui.Controls.Advanced
  • CodeSpanVixen.Ui.Controls.Advanced
  • ColorFieldVixen.Ui.Controls.Advanced
  • ColorInputVixen.Ui.Controls.Advanced
  • ColorInputTestsVixen.Ui.Controls.Advanced.Tests
  • ColorPickerVixen.Ui.Controls.Advanced
  • ColorPickerTestsVixen.Ui.Controls.Advanced.Tests
  • ColorStripVixen.Ui.Controls.Advanced
  • ColorSwatchVixen.Ui.Controls.Advanced
  • ComboBoxVixen.Ui.Controls
  • ComponentVixen.Ui
  • CompositionTestsVixen.Ui.Tests
  • ContextMenuVixen.Ui.Controls
  • ControlVixen.Ui.Controls
  • ControlFixtureVixen.Ui.Controls.Tests