Table of Contents

Class View

Namespace
Xui.Core.UI
Assembly
Xui.Core.dll

Base class for all UI elements in the Xui layout engine. A view participates in layout, rendering, and input hit testing, and may contain child views.

public class View : ILayerHost, IServiceProvider
Inheritance
View
Implements
Derived
Inherited Members
Extension Methods

Fields

ClassName

The set of class names assigned to this view, used for lookup via FindViewsByClass(View, string, List<View>).

public ClassNameCollection ClassName

Field Value

ClassNameCollection

Properties

Count

Returns the number of child views. Used by layout containers and traversal logic. Leaf views should return 0.

public virtual int Count { get; }

Property Value

int

Direction

The writing direction of this view, which determines the block or inline flow direction. Inherited from the parent flow context if set to Inherit.

public Direction Direction { get; set; }

Property Value

Direction

Flags

Gets the current change flags for this view. These flags indicate which aspects (measure, arrange, render, hit test) have changed since the last time the parent acknowledged them via the corresponding Validate* method.

public View.ViewFlags Flags { get; }

Property Value

View.ViewFlags

Flow

Controls how the layout system treats this view's children. Can be inherited or explicitly overridden for advanced layout containers.

public Flow Flow { get; set; }

Property Value

Flow

Focusable

Gets whether this view can receive keyboard focus via Tab navigation.

public virtual bool Focusable { get; }

Property Value

bool

Frame

The border edge of this view in global coordinates relative to the top-left of the window.

public Rect Frame { get; protected set; }

Property Value

Rect

HorizontalAlignment

The horizontal alignment of this view inside its layout anchor region. Used during layout when the view has remaining space within its container.

public HorizontalAlignment HorizontalAlignment { get; set; }

Property Value

HorizontalAlignment

Id

An optional unique identifier for this view, used for lookup via FindViewById(View, string).

public string? Id { get; set; }

Property Value

string

IsFocused

Gets whether this view currently has keyboard focus.

public bool IsFocused { get; }

Property Value

bool

this[int]

Indexer to access child views by index. Layout containers should implement this to expose their children.

public virtual View this[int index] { get; }

Parameters

index int

Property Value

View

Margin

The margin around this view. Margins participate in collapsed margin logic during layout, and are external spacing relative to the parent or surrounding siblings.

public Frame Margin { get; set; }

Property Value

Frame

MaximumHeight

The maximum height of the border edge box.

public NFloat MaximumHeight { get; set; }

Property Value

NFloat

MaximumWidth

The maximum width of the border edge box.

public NFloat MaximumWidth { get; set; }

Property Value

NFloat

MinimumHeight

The minimum height of the border edge box.

public NFloat MinimumHeight { get; set; }

Property Value

NFloat

MinimumWidth

The minimum width of the border edge box.

public NFloat MinimumWidth { get; set; }

Property Value

NFloat

Parent

The parent view in the visual hierarchy. This is set automatically when the view is added to a container.

public View? Parent { get; }

Property Value

View

VerticalAlignment

The vertical alignment of this view inside its layout anchor region. Used during layout when the view has remaining space within its container.

public VerticalAlignment VerticalAlignment { get; set; }

Property Value

VerticalAlignment

WritingMode

The writing mode of this view (e.g. horizontal top-to-bottom or vertical right-to-left). Inherited from the parent if set to Inherit.

public WritingMode WritingMode { get; set; }

Property Value

WritingMode

Methods

AddProtectedChild(View)

Attaches a child view to this parent, setting Parent and performing basic validation. Intended for internal use by container views and single-child hosts.

protected void AddProtectedChild(View child)

Parameters

child View

Animate(TimeSpan, TimeSpan)

Advances animation state for this view and all descendants for the current frame.

public void Animate(TimeSpan previousTime, TimeSpan currentTime)

Parameters

previousTime TimeSpan
currentTime TimeSpan

AnimateCore(TimeSpan, TimeSpan)

Per-frame animation hook. Mutate time-based state and call RequestAnimationFrame() if the animation should continue. The default implementation recurses into children; override to customise child traversal.

protected virtual void AnimateCore(TimeSpan previousTime, TimeSpan currentTime)

Parameters

previousTime TimeSpan
currentTime TimeSpan

AnimateShell(ref LayoutGuide)

Resets animation flags then calls AnimateCore(TimeSpan, TimeSpan), which by default recurses into children.

protected void AnimateShell(ref LayoutGuide guide)

Parameters

guide LayoutGuide

Arrange(Rect, IMeasureContext, Size?)

Arranges the view within rect, finalising its position and size.

public Rect Arrange(Rect rect, IMeasureContext context, Size? desiredSize = null)

Parameters

rect Rect
context IMeasureContext
desiredSize Size?

Returns

Rect

ArrangeCore(Rect, IMeasureContext)

Positions children within the border-edge rectangle. Frame assignment and alignment offset are handled by ArrangeShell(ref LayoutGuide).

protected virtual void ArrangeCore(Rect rect, IMeasureContext context)

Parameters

rect Rect
context IMeasureContext

ArrangeShell(ref LayoutGuide)

Computes the border-edge rectangle from anchor, alignment and available space, assigns Frame, then calls ArrangeCore(Rect, IMeasureContext). Writes the result into ArrangedRect.

protected void ArrangeShell(ref LayoutGuide guide)

Parameters

guide LayoutGuide

Blur()

Releases keyboard focus from this view.

public void Blur()

CapturePointer(int)

Captures the pointer with the specified identifier so that it continues to receive pointer events even if the pointer moves outside its bounds.

public void CapturePointer(int pointerId)

Parameters

pointerId int

The platform-assigned pointer identifier.

Focus()

Requests keyboard focus for this view.

public bool Focus()

Returns

bool

GetService(Type)

Gets the service object of the specified type.

public virtual object? GetService(Type serviceType)

Parameters

serviceType Type

An object that specifies the type of service object to get.

Returns

object

A service object of type serviceType.

-or-

null if there is no service object of type serviceType.

HitTest(Point)

Determines whether the given point (in local coordinates) hits this view's visual bounds. Used for input dispatch and hit testing.

public virtual bool HitTest(Point point)

Parameters

point Point

The point to test, relative to this view's coordinate space.

Returns

bool

true if the point is inside the view's frame; otherwise false.

InvalidateArrange()

Marks this view as having changed in a way that may cause it to arrange its children differently, even with the same rectangle and context. Causes OnChildArrangeChanged(View) to be invoked on the parent.

protected void InvalidateArrange()

InvalidateHitTest()

Marks this view as having changed in a way that may cause hit testing to yield different results, even for the same input coordinates. Causes OnChildHitTestChanged(View) to be invoked on the parent.

protected void InvalidateHitTest()

InvalidateMeasure()

Marks this view as having changed in a way that may affect its measured size. Causes OnChildMeasureChanged(View) to be invoked on the parent.

public void InvalidateMeasure()

InvalidateRender()

Marks this view as having changed visually in a way that requires re-rendering. Causes OnChildRenderChanged(View) to be invoked on the parent.

public void InvalidateRender()

Measure(Size, IMeasureContext)

Measures the view and returns the desired margin-box size.

public Size Measure(Size availableSize, IMeasureContext context)

Parameters

availableSize Size
context IMeasureContext

Returns

Size

MeasureCore(Size, IMeasureContext)

Returns the desired border-edge size given the available border-edge space. Margin, min/max clamping, and fixed-size short-circuit are handled by MeasureShell(ref LayoutGuide).

protected virtual Size MeasureCore(Size availableBorderEdgeSize, IMeasureContext context)

Parameters

availableBorderEdgeSize Size
context IMeasureContext

Returns

Size

MeasureShell(ref LayoutGuide)

Applies fixed-size short-circuit, min/max clamping, and logging around MeasureCore(Size, IMeasureContext). Writes the result into DesiredSize.

protected void MeasureShell(ref LayoutGuide guide)

Parameters

guide LayoutGuide

OnActivate()

Called when this view becomes active — it will receive events, render, and animate. Override this to start animations, subscribe to data sources, or acquire resources.

protected virtual void OnActivate()

OnAttach(ref AttachEventRef)

Called when this view is added to the visual tree and platform contexts become available. Override to acquire resources that depend on text measurement or bitmap factories.

protected virtual void OnAttach(ref AttachEventRef e)

Parameters

e AttachEventRef

OnBlur()

Called when this view loses keyboard focus.

protected virtual void OnBlur()

OnChar(ref KeyEventRef)

Called when a character is input while this view has focus.

public virtual void OnChar(ref KeyEventRef e)

Parameters

e KeyEventRef

OnChildArrangeChanged(View)

Called when a direct or indirect child view has changed in a way that may affect its arrangement of children. The default implementation forwards the notification up the visual tree to the parent.

protected virtual void OnChildArrangeChanged(View child)

Parameters

child View

The child view whose arrange state has changed.

OnChildHitTestChanged(View)

Called when a direct or indirect child view has changed in a way that may cause hit testing results to change. The default implementation forwards the notification up the visual tree to the parent.

protected virtual void OnChildHitTestChanged(View child)

Parameters

child View

The child view whose hit testing state has changed.

OnChildMeasureChanged(View)

Called when a direct or indirect child view has changed in a way that may affect its measured size. The default implementation forwards the notification up the visual tree to the parent.

protected virtual void OnChildMeasureChanged(View child)

Parameters

child View

The child view whose measure state has changed.

OnChildRenderChanged(View)

Called when a direct or indirect child view has changed visually and requires re-rendering. The default implementation forwards the notification up the visual tree.

protected virtual void OnChildRenderChanged(View child)

Parameters

child View

The child view whose render state has changed.

OnChildRequestedAnimationFrame(View)

Called when a direct or indirect child has requested another animation frame for the next UI tick. The default implementation marks DescendantAnimated and forwards the notification up the visual tree.

protected virtual void OnChildRequestedAnimationFrame(View child)

Parameters

child View

The child view that requested the animation frame.

OnDeactivate()

Called when this view becomes dormant — it should stop animations, timers, and event subscriptions. The view may remain in the tree (e.g., in a virtualizing panel's recycle pool).

protected virtual void OnDeactivate()

OnDetach(ref DetachEventRef)

Called when this view is removed from the visual tree. Override to release any resources acquired in OnAttach(ref AttachEventRef).

protected virtual void OnDetach(ref DetachEventRef e)

Parameters

e DetachEventRef

OnFocus()

Called when this view receives keyboard focus.

protected virtual void OnFocus()

OnKeyDown(ref KeyEventRef)

Called when a key is pressed while this view has focus.

public virtual void OnKeyDown(ref KeyEventRef e)

Parameters

e KeyEventRef

OnPointerEvent(ref PointerEventRef, EventPhase)

Called during event dispatch to handle a pointer event in a specific event phase.

public virtual void OnPointerEvent(ref PointerEventRef e, EventPhase phase)

Parameters

e PointerEventRef
phase EventPhase

OnScrollWheel(ref ScrollWheelEventRef)

Called when a scroll wheel or trackpad scroll event is dispatched to this view. Override to handle scroll input. Set Handled to stop propagation.

public virtual void OnScrollWheel(ref ScrollWheelEventRef e)

Parameters

e ScrollWheelEventRef

ReleasePointer(int)

Releases a previously captured pointer so that pointer events are routed according to normal hit testing rules.

public void ReleasePointer(int pointerId)

Parameters

pointerId int

The platform-assigned pointer identifier.

RemoveProtectedChild(View)

Detaches a child view from this parent, clearing Parent. Intended for internal use by container views and single-child hosts.

protected void RemoveProtectedChild(View child)

Parameters

child View

Render(IContext)

Renders the view. Must be called after layout is complete.

public void Render(IContext context)

Parameters

context IContext

RenderCore(IContext)

Draws this view's content and recurses into children.

protected virtual void RenderCore(IContext context)

Parameters

context IContext

RenderShell(ref LayoutGuide)

Validates render state then calls RenderCore(IContext).

protected void RenderShell(ref LayoutGuide guide)

Parameters

guide LayoutGuide

RequestAnimationFrame()

Requests another animation frame for this view on the next UI tick. Sets Animated and notifies ancestors (via OnChildRequestedAnimationFrame(View)) so they carry DescendantAnimated.

public void RequestAnimationFrame()

SetProtectedChild<T>(ref T?, T?)

Sets a single protected child field, automatically detaching the old child (if any) and attaching the new child (if any). Use this for single-child containers.

protected void SetProtectedChild<T>(ref T? field, T? value) where T : View

Parameters

field T
value T

Type Parameters

T

Update(LayoutGuide)

Drives one or more layout passes for this view.

The default implementation dispatches each requested pass to its shell method in order. Views that can handle all four passes in a single DFS traversal (LuminarFlow) should override this method and check IsLuminarFlow to do so. A fork — a container that must measure all children before it can position any of them — cannot do a single-pass walk and should leave this method as-is, calling the public convenience methods Animate(TimeSpan, TimeSpan), Measure(Size, IMeasureContext), Arrange(Rect, IMeasureContext, Size?), Render(IContext) separately from its parent.

public virtual LayoutGuide Update(LayoutGuide guide)

Parameters

guide LayoutGuide

Returns

LayoutGuide

ValidateArrange()

Clears the ArrangeChanged flag on this view, indicating that a parent or container has acknowledged the child’s arrange change.

public void ValidateArrange()

ValidateHitTest()

Clears the HitTestChanged flag on this view, indicating that hit-test caches (if any) have been updated or the parent has otherwise accounted for the changed hit-test behavior.

public void ValidateHitTest()

ValidateMeasure()

Clears the MeasureChanged flag on this view, indicating that a parent or container has acknowledged the child’s measure change and handled it (e.g., decided to keep the same column width in a grid regardless of the child’s new desired size). Use this when the parent has considered the change and no re-measure is required for this child.

public void ValidateMeasure()

ValidateRender()

Clears the RenderChanged flag on this view, indicating that the parent (or the rendering pipeline) has acknowledged the visual change and re-rendering for this view has been completed.

public void ValidateRender()