Vixen
02b45cc4
csharp
public sealed class UiDocument

An element tree, its stylesheets, and the pass that turns one into geometry.

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

Remarks

Three subsystems that were built and tested apart finally run together here: the cascade decides what applies, LayoutStyleBuilder turns that into lengths, and the flexbox engine turns those into rectangles. Everything before this point could be judged by a conformance suite; this is the first thing that can be judged by looking at it.

The pass is four walks and they cannot be merged. The cascade needs parents resolved before children because inheritance reads the parent's resolved table; font size needs the same order for the same reason and cannot be folded into the cascade because it is a computed value the cascade has no opinion about; the layout style depends on the font size; and layout itself is the flexbox algorithm, which is not a walk at all.

Elements can be removed as well as added — see Remove — but a removed style slot is tombstoned rather than reused, so a document that builds and tears down a list every frame grows without bound. DeadCount is the number that says so, and compaction is owed.

Fields and properties (29)

  • public UiCursor Cursor

    What the pointer should look like where it currently is.

  • public UiElement? Focused

    The element the keyboard is talking to.

  • public UiElement? Hovered

    The deepest element the pointer is over, or null if it is over nothing.

  • public bool KeyboardMode

    Whether the most recent input came from the keyboard.

  • public int StylesResolved

    How many elements the last pass cascaded.

  • public bool LastPassWasCold

    Whether the last pass had to resolve every element rather than a few.

  • public IReadOnlyList<UiSurface> Surfaces

    Everywhere this document is shown, the primary one first.

  • public UiSurface Primary

    The surface the document was created with.

  • public StyleEngine Styles

    The cascade.

  • public EffectScheduler Effects

    Where this document's bindings queue, and what a frame drains.

  • public StyleUpdater Restyler

    What holds every element's computed style and keeps it that way.

  • public LayoutTree Layout

    The flexbox engine.

  • public LayoutStyleBuilder Builder

    The step between them.

  • public DrawList Drawing

    The commands the last Draw produced.

  • public LengthContext Viewport

    The primary surface's size and root font size.

  • public UiElement Root

    The element every other one descends from.

  • public int StylesApplied

    How many elements had a layout style written on the last pass.

  • public int StyleCompactions

    How many times the style store has been compacted.

  • public const int SettlePasses

    How many times a pass will re-run for handlers that changed something.

  • public bool Settled

    Whether the last Update reached a fixed point.

  • public int SettlingPasses

    How many extra passes the last Update ran for its handlers.

  • public TimeSpan Now

    The last time Tick was given.

  • public GestureRecognizer Gestures

    Taps, long presses and drags read out of the pointer stream.

  • public UiSurface? PointerSurface

    Which surface the last pointer event was dispatched into.

  • public UiElement? Captured

    The element currently receiving every pointer event, if any.

  • public FontRegistry Fonts

    The faces a font-family declaration can name.

  • public ShapingCache Shaping

    The shaping every element's text goes through.

  • public IUiWindowHost? Windows

    What turns a surface of this document into a window, if anything can.

  • public bool CanOpenWindows

    Whether a control may ask this document for a window of its own.

Events (4)

  • public Action<UiDocument, UiSurface>? SurfaceAdded

    Raised when a surface is added or taken away.

  • public Action<UiDocument, UiSurface>? SurfaceRemoved
  • public Action<UiDocument>? LayoutFinished

    Raised when every box in the document is final for this frame.

  • public Action<UiDocument, TimeSpan>? Ticked

    Raised on every Tick.

Methods (45)

  • public bool InvokeAccessKey(char key)

    Activates whatever an access key names, if anything does.

  • public UiCursor CursorOf(ComputedStyle style)

    What a computed style asks the pointer to look like.

  • public bool Focus(UiElement? element)

    Moves the focus.

  • public bool MoveFocus(FocusDirection direction)

    Moves the focus one step round the tab order.

  • public static List<UiElement> TabOrder(UiElement scope)

    The elements Tab visits inside a subtree, in the order it visits them.

  • public UiElement? Dispatch(WheelEvent args)

    Sends a wheel event to whatever is under it.

  • public UiElement? Dispatch(UiSurface surface, WheelEvent args)

    Sends a wheel event to whatever is under it in one surface.

  • public UiElement? Dispatch(KeyEvent args)

    Sends a key event to whatever has the focus.

  • public UiElement? Dispatch(TextInputEvent args)

    Sends typed text to whatever has the focus.

  • public bool MoveFocus(NavigationDirection direction)

    Moves the focus to whatever lies in a direction.

  • public UiElement? FindInDirection(UiElement origin, NavigationDirection direction)

    What lies in a direction from an element.

  • public void Reparent(UiElement element, UiElement parent, int index = -1)

    Moves an element, and everything under it, to a different parent.

  • public int PropertyId(string name)

    Interns a property name, so a control can read it without a dictionary probe per frame.

  • public Color4? ColorOf(ComputedStyle style, int property)

    The colour a computed style gives a property, if it gives one.

  • public float? LengthOf(ComputedStyle style, int property)

    The length in pixels a computed style gives a property, if it gives an absolute one.

  • public float? NumberOf(ComputedStyle style, int property)

    The bare number a computed style gives a property, if it gives one.

  • public Color4 ForegroundOf(UiElement element)

    An element's color, which is what a control draws itself in.

  • public UiSurface CreateSurface(float width, float height, float dpiScale = 1, UiElement? owner = null)

    Adds somewhere else to show part of this document.

  • public bool RemoveSurface(UiSurface surface)

    Takes a surface, and everything still in it, out of the document.

  • public void Resize(UiSurface surface, float width, float height, float dpiScale)

    Changes a surface's size, and the scale of the display it is on.

  • public UiSurface? SurfaceOf(UiElement element)

    Which surface an element is shown in.

  • public UiDocument(float width, float height, float rootFontSize = 16)

    Creates a document over a surface of a given size.

  • public Component? ComponentAt(UiElement element)

    The component whose host this element is, if it is one.

  • public int Load(string css, StyleOrigin origin = Author)

    Loads a stylesheet.

  • public bool LoadOnce(object key, string css, StyleOrigin origin = Author)

    Loads a stylesheet once for a key, however many times it is asked for.

  • public void ReloadStyles(int sheet, string css)

    Replaces a loaded stylesheet with new text.

  • public void Resize(float width, float height)

    Changes the surface's size.

  • public void Invalidate()

    Marks the document as needing a fresh pass over every element.

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

    Creates an element.

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

    Creates an element of a particular type.

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

    Makes an element this document already has an instance of part of it.

  • public void Move(UiElement element, int index)

    Moves an element to another position among its siblings.

  • public void Remove(UiElement element)

    Removes an element and everything under it.

  • public bool CompactStyles()

    Reclaims the style slots removal left behind.

  • public bool Update()

    Runs the passes, if anything has changed since the last one.

  • public void Tick(TimeSpan now)

    Lets time pass, for the things that happen because nothing happened.

  • public bool Draw()

    Rebuilds the draw list from the current layout and styles.

  • public bool Draw(UiSurface surface)

    Rebuilds one surface's draw list.

  • public UiElement? HitTest(float x, float y)

    The element a pointer would land on.

  • public UiElement? HitTest(UiSurface surface, float x, float y)

    The element a pointer would land on in one surface.

  • public UiElement? Dispatch(PointerEvent args)

    Sends a pointer event to whatever is under it.

  • public UiElement? Dispatch(UiSurface surface, PointerEvent args)

    Sends a pointer event to whatever is under it in one surface.

  • public void CapturePointer(UiElement element)

    Sends every pointer event to one element until it is released.

  • public void ReleasePointer()

    Stops sending every pointer event to one element.

  • public void Dispose()

    Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.

Used by (225, showing 40)

  • FontsHelloUi
  • ShellHelloUi
  • UiHostHelloUi
  • DocumentBenchmarksVixen.Benchmarks.Ui
  • AccessKeyTestsVixen.Ui.Tests
  • AdvancedFixtureVixen.Ui.Controls.Advanced.Tests
  • AdvancedThemeVixen.Ui.Controls.Advanced
  • AlertVixen.Ui.Controls
  • BatchTestsVixen.Ui.Tests
  • BuildContextVixen.Ui
  • ButtonBaseVixen.Ui.Controls
  • ButtonTestsVixen.Ui.Controls.Tests
  • CardVixen.Ui.Controls
  • CheckBoxVixen.Ui.Controls
  • CodeEditorVixen.Ui.Controls.Advanced
  • CodeEditorTestsVixen.Ui.Controls.Advanced.Tests
  • 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
  • ComboBoxVixen.Ui.Controls
  • ComponentVixen.Ui
  • CompositionTestsVixen.Ui.Tests
  • ContextMenuVixen.Ui.Controls
  • ControlVixen.Ui.Controls
  • ControlFixtureVixen.Ui.Controls.Tests
  • ControlHarnessVixen.Ui.Controls.Tests
  • ControlThemeVixen.Ui.Controls
  • CurveEditorVixen.Ui.Controls.Advanced
  • CurveEditorTestsVixen.Ui.Controls.Advanced.Tests
  • DataGridVixen.Ui.Controls.Advanced
  • DataGridTestsVixen.Ui.Controls.Advanced.Tests
  • DialogVixen.Ui.Controls
  • DisabledStateTestsVixen.Ui.Controls.Tests
  • DockGroupViewVixen.Ui.Controls.Advanced
  • DockSplitterViewVixen.Ui.Controls.Advanced
  • DockingHostVixen.Ui.Controls.Advanced
  • DockingTestsVixen.Ui.Controls.Advanced.Tests