// Generated API outline. Implementation bodies omitted.
#nullable enable
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Net.Http;
using System.Threading.Tasks;
using System.Threading;
using System;
using nfloat = System.Runtime.InteropServices.NFloat;
using static Xui.Core.Math2D.Constants;
namespace Xui.Core.UI
{
using Xui.Core.Math2D;
/// Immutable input to an arrangement operation.
public readonly struct ArrangeConstraints
{
/// Initializes arrangement constraints.
public ArrangeConstraints(Size availableSize, Size desiredSize, Point anchor, LayoutSizeMode xSize = LayoutSizeMode.Exact, LayoutSizeMode ySize = LayoutSizeMode.Exact, LayoutAlign xAlign = LayoutAlign.Start, LayoutAlign yAlign = LayoutAlign.Start);
/// Available margin-box size.
public Size AvailableSize { get; }
/// Desired margin-box size from measurement.
public Size DesiredSize { get; }
/// Reference point for alignment.
public Point Anchor { get; }
/// Horizontal sizing mode.
public LayoutSizeMode XSize { get; }
/// Vertical sizing mode.
public LayoutSizeMode YSize { get; }
/// Horizontal anchor alignment.
public LayoutAlign XAlign { get; }
/// Vertical anchor alignment.
public LayoutAlign YAlign { get; }
}
///
/// A transient in-window overlay acquired via GetService<IOverlay>().
/// Rendered by on top of all other content — no native window is created.
/// Works on every platform (Windows, macOS, iOS, Android, Browser) with no platform-specific code.
///
///
/// Use this for cross-platform scenarios: mobile, simulators, web/SPA, or
/// in-app surfaces like top-of-screen search fields that must stay within the window.
/// For native OS-level popups that can extend outside the app window,
/// use instead.
///
/// Usage pattern:
///
/// var overlay = this.GetService<IOverlay>();
/// overlay.Show(content, anchorRect, PopupPlacement.Below);
///
/// The overlay auto-dismisses when the user clicks outside.
/// Disposing the overlay closes it if still visible.
///
public interface IOverlay : IDisposable
{
///
/// Shows the overlay with the given content, positioned relative to
/// (in the owning window's coordinate space).
///
/// The view to display inside the overlay.
///
/// The rect of the triggering element in window coordinates.
/// Used to position the overlay (for example, below a button).
///
/// Preferred placement direction.
///
/// Desired overlay size. If null, a default size is used.
///
/// Visual backdrop effect (reserved for future use).
void Show(View content, Rect anchorRect, PopupPlacement placement = PopupPlacement.Below, Size? size = null, PopupEffect effect = PopupEffect.None);
/// Closes the overlay if visible.
void Close();
/// Whether the overlay is currently visible.
bool IsVisible { get; }
/// Raised when the overlay is dismissed (click-outside, explicit close, or parent window close).
event Action? Closed;
}
///
/// A transient native popup surface acquired via GetService<IPopup>().
/// Each call returns a new instance backed by a platform-specific child window,
/// which can extend beyond the parent window bounds.
///
///
/// Available on platforms that support native popups (Windows, macOS).
/// For cross-platform in-window overlays that work on all platforms including
/// mobile, web, and simulators, use instead.
///
/// Usage pattern (similar to ):
///
/// var popup = this.GetService<IPopup>();
/// popup.Show(content, anchorRect, PopupPlacement.Below);
///
/// The popup auto-dismisses when the user clicks outside.
/// Disposing the popup closes it if still visible.
///
public interface IPopup : IDisposable
{
///
/// Shows the popup with the given content, positioned relative to
/// (in the owning window's coordinate space).
///
/// The view to display inside the popup.
///
/// The rect of the triggering element in window coordinates.
/// The platform uses this to position the popup so that (for example)
/// a selected item aligns with the anchor text.
///
/// Preferred placement direction.
///
/// Desired popup size. If null, the platform falls back to a default size.
///
/// Visual backdrop effect to apply to the popup window.
void Show(View content, Rect anchorRect, PopupPlacement placement = PopupPlacement.Below, Size? size = null, PopupEffect effect = PopupEffect.None);
/// Closes the popup if visible.
void Close();
/// Whether the popup is currently visible.
bool IsVisible { get; }
/// Raised when the popup is dismissed (click-outside, explicit close, or parent window close).
event Action? Closed;
}
///
/// Per-view results written by an update. The caller owns this value and passes it by reference,
/// so sibling updates cannot share or overwrite one another's results.
///
public struct LayoutMeasurements
{
/// Desired margin-box size produced by measurement.
public Size DesiredSize;
/// Final border-edge rectangle produced by arrangement.
public Rect ArrangedRect;
}
/// Immutable input to a measurement operation.
public readonly struct MeasureConstraints
{
/// Initializes measurement constraints.
public MeasureConstraints(Size availableSize, LayoutSizeMode xSize = LayoutSizeMode.AtMost, LayoutSizeMode ySize = LayoutSizeMode.AtMost);
/// Available margin-box size.
public Size AvailableSize { get; }
/// Horizontal sizing mode.
public LayoutSizeMode XSize { get; }
/// Vertical sizing mode.
public LayoutSizeMode YSize { get; }
}
///
/// 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.
///
///
/// 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 partial class View
{
///
/// Gets this view's conservative bounds in its parent coordinate space for render culling.
///
///
/// A container may override this when its rendered geometry differs from its layout frame.
/// Computing the union of descendant culling frames is deliberately deferred: it can be
/// more expensive than rendering for small subtrees.
///
public virtual Rect CullingFrame { get; }
///
/// Maps a point from this view's parent coordinate space into this view's local coordinate space.
///
///
/// Layout still supplies frames using the existing coordinate model. The default identity
/// mapping deliberately preserves that behaviour until a container opts into a local
/// coordinate transform. Containers such as can override this
/// to map input into their content space.
///
public virtual Point TransformPoint(Point point);
///
/// Maps a point from this view's local coordinate space into its parent coordinate space.
///
///
/// This must be the inverse of for points that can be hit
/// tested. It is separate so a view can support coordinate mappings that are not yet
/// represented by the canvas transform API.
///
public virtual Point InverseTransformPoint(Point point);
///
/// Conservatively maps an axis-aligned rectangle from this view's parent coordinate space
/// into this view's coordinate space.
///
///
/// For non-translation transforms, an override must return the smallest parent-axis-aligned
/// rectangle that encloses every transformed corner.
///
public virtual Rect TransformRect(Rect rect);
///
/// Conservatively maps an axis-aligned rectangle from this view's coordinate space into its
/// parent coordinate space.
///
///
/// For non-translation transforms, an override must return the smallest parent-axis-aligned
/// rectangle that encloses every transformed corner.
///
public virtual Rect InverseTransformRect(Rect rect);
///
/// Maps a point in this view's local coordinate space into root/window coordinate space.
///
public Point LocalToGlobal(Point point);
///
/// Maps a point in root/window coordinate space into this view's local coordinate space.
///
public Point GlobalToLocal(Point point);
}
///
/// 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.
///
///
/// 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 partial class View
{
///
/// An optional unique identifier for this view, used for lookup via
/// .
///
public string? Id { get; set; }
///
/// The set of class names assigned to this view, used for lookup via
/// .
///
public ClassNameCollection ClassName;
///
/// The parent view in the visual hierarchy. This is set automatically when the view is added to a container.
///
public View? Parent { get; }
///
/// The border edge of this view in global coordinates relative to the top-left of the window.
///
public Rect Frame { get; protected set; }
/// Gets or sets the external spacing around the view.
public Frame Margin { get; set; }
/// Gets or sets the horizontal alignment within the layout anchor region.
public HorizontalAlignment HorizontalAlignment { get; set; }
/// Gets or sets the vertical alignment within the layout anchor region.
public VerticalAlignment VerticalAlignment { get; set; }
/// Gets or sets the writing direction.
public Direction Direction { get; set; }
/// Gets or sets the writing mode.
public WritingMode WritingMode { get; set; }
/// Gets or sets the child flow behavior.
public Flow Flow { get; set; }
/// Gets or sets the minimum border-edge width.
public nfloat MinimumWidth { get; set; }
/// Gets or sets the minimum border-edge height.
public nfloat MinimumHeight { get; set; }
/// Gets or sets the maximum border-edge width.
public nfloat MaximumWidth { get; set; }
/// Gets or sets the maximum border-edge height.
public nfloat MaximumHeight { get; set; }
///
/// Determines whether the given point (in this view's local coordinates) hits this view's visual bounds.
/// Used for input dispatch and hit testing.
///
/// The point to test, relative to this view's coordinate space.
///
/// true if the point is inside the view's frame; otherwise false.
public virtual bool HitTest(Point point);
}
}
namespace Xui.Core.UI
{
using Xui.Core.Debug;
///
/// Passed to when a view is added to the visual tree.
/// Carries tree-wide shared resources (e.g. instrumentation) down the DFS walk so
/// every view in the subtree receives them without per-view service lookups.
///
public ref struct AttachEventRef
{
///
/// Instrumentation sink for the visual tree. Views receive this during attach
/// and store it so invalidation methods (e.g. ,
/// ) can log consistently with the
/// render-surface instrumentation carried by .
///
public InstrumentsAccessor Instruments;
/// Initializes a new .
public AttachEventRef();
}
///
/// 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.
///
///
/// 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 partial class View
{
///
/// Flags used internally by a to track invalidation state across
/// measure, arrangement, rendering, and hit testing phases.
/// These flags allow the framework to selectively recompute only dirty subtrees
/// during recursive passes.
///
[Flags]
public enum ViewFlags
{
///
/// This view is animated.
/// It has properties that are calculated based on the current UI time.
/// It requires an animation notification on the next frame.
///
Animated = 1 << 0,
///
/// This view has animated children.
/// While this view directly does not depend on the next frame time,
/// it must propagate an animation notification to its animated children.
///
DescendantAnimated = 1 << 1,
///
/// The has changed since its last measure.
/// It will likely return a different desired size if measured again
/// with the same constraints.
///
MeasureChanged = 1 << 2,
///
/// The has changed in a way that may cause it to arrange
/// its children differently, even if the available rectangle and measure
/// context are the same.
///
ArrangeChanged = 1 << 3,
///
/// One or more descendants of this have had their
/// flag set since the last validation.
/// This flag does not indicate that this view itself needs re-arranging,
/// but rather that some descendant may need to be re-arranged with its
/// existing rectangle (e.g., a visual state change that affects only
/// internal layout).
///
DescendantArrangeChanged = 1 << 4,
///
/// The has changed visually since its last render pass,
/// and produce different output even if rendered within the same frame and context.
///
RenderChanged = 1 << 5,
///
/// One or more descendants of this have had their
/// flag set since the last validation.
/// This is a hint that rendering work exists below, even if this view itself
/// does not need re-rendering.
///
DescendantRenderChanged = 1 << 6,
///
/// This view's changed.
/// It will probably return a new results for the same .
///
HitTestChanged = 1 << 7,
///
/// One or more descendants of this have their hit testing changed.
/// They will probably return a new result for the same .
///
DescendantHitTestChanged = 1 << 8,
///
/// This view is active — it is part of a live visual tree and will receive
/// events, render, and animate. Set by and
/// cleared by .
///
Active = 1 << 9,
///
/// This view is attached — it has been added to a visual tree that is itself
/// attached to the platform (e.g. a window). Set by
/// and cleared by .
///
Attached = 1 << 10,
}
///
/// 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 ViewFlags Flags { get; }
/// Whether graphics changed, or this view last rendered into a different context.
/// Use when declaring a retained child surface before calling the child's Render method.
public bool RequiresRender(Xui.Core.Canvas.IContext context);
///
/// Whether this view or its descendants have graphics updates for the current render.
/// Unlike Flags, this remains available inside RenderCore after the render shell clears
/// the incoming invalidation flags. Suitable for GroupOptions.HasUpdates; the context
/// still decides whether content must be drawn, including on first use or SVG export.
///
protected bool HasRenderUpdates { get; }
///
/// Invalidates every phase affected by a change to the view's layout contract.
/// Used by the base layout properties so cached measurements cannot survive a
/// change to constraints, alignment, or spacing.
///
protected void Invalidate();
///
/// Assigns a layout-affecting property when its value changes, then invalidates
/// the view's measure, arrange, and render state.
///
///
/// true when changed.
protected bool SetViewProperty(ref T field, T value);
/// Assigns a render-only property when its value changes.
///
/// true when changed.
protected bool SetViewRenderProperty(ref T field, T value);
///
/// Requests another animation frame for this view on the next UI tick.
/// Sets and notifies ancestors (via
/// ) so they carry
/// .
///
public void RequestAnimationFrame();
///
/// Called when a direct or indirect child has requested another animation frame
/// for the next UI tick. The default implementation marks
/// and forwards the notification up
/// the visual tree.
///
/// The child view that requested the animation frame.
protected virtual void OnChildRequestedAnimationFrame(View child);
///
/// Marks this view as having changed in a way that may affect its measured size.
/// Causes to be invoked on the parent.
///
public void InvalidateMeasure();
///
/// 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 to be invoked on the parent.
///
protected void InvalidateArrange();
///
/// Marks this view as having changed visually in a way that requires re-rendering.
/// Causes to be invoked on the parent.
///
public void InvalidateRender();
///
/// 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 to be invoked on the parent.
///
protected void InvalidateHitTest();
///
/// Clears the 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();
///
/// Clears the flag on this view, indicating that
/// a parent or container has acknowledged the child’s arrange change.
///
public void ValidateArrange();
///
/// Clears the 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();
///
/// Clears the 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();
///
/// 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.
///
/// The child view whose measure state has changed.
protected virtual void OnChildMeasureChanged(View child);
///
/// 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.
///
/// The child view whose arrange state has changed.
protected virtual void OnChildArrangeChanged(View child);
///
/// 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.
///
/// The child view whose render state has changed.
protected virtual void OnChildRenderChanged(View child);
///
/// 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.
///
/// The child view whose hit testing state has changed.
protected virtual void OnChildHitTestChanged(View child);
///
/// Captures the pointer with the specified identifier so that it continues to
/// receive pointer events even if the pointer moves outside its bounds.
///
/// The platform-assigned pointer identifier.
///
/// Optional marker describing what kind of gesture this view is tracking
/// (e.g. for a button,
/// for a slider). Ancestor
/// containers (e.g. ScrollView) inspect this via
/// EventRouter.GetCapturedGesture to decide whether they may steal capture.
///
public void CapturePointer(int pointerId, Xui.Core.UI.Input.IPointerGesture? gesture = null);
///
/// Releases a previously captured pointer so that pointer events are routed
/// according to normal hit testing rules.
///
/// The platform-assigned pointer identifier.
public void ReleasePointer(int pointerId);
///
/// Returns the gesture marker for the view currently capturing
/// , or null if the pointer is not captured
/// or was captured without a gesture marker.
///
public Xui.Core.UI.Input.IPointerGesture? GetCapturedGesture(int pointerId);
}
}
namespace Xui.Core.UI
{
using Xui.Core.Canvas;
using Xui.Core.Math2D;
using Xui.Core.UI.Layer;
///
/// A view that draws a background, border, and padding around a single child content view.
/// All rendering is owned by composed with
/// . The child view lives in Layer.Child.Child and is
/// managed via the standard lifecycle.
///
public class Border : LayerView>
{
/// Gets or sets the content view displayed inside the border.
public View? Content { get; set; }
/// Gets or sets the per-side border thickness.
public Frame BorderThickness { get; set; }
/// Gets or sets the corner radius.
public CornerRadius CornerRadius { get; set; }
/// Gets or sets the background fill color.
public Color BackgroundColor { get; set; }
/// Gets or sets the border stroke color.
public Color BorderColor { get; set; }
/// Gets or sets the padding between the border edge and the content.
public Frame Padding { get; set; }
///
/// Returns the number of child views. Used by layout containers and traversal logic.
/// Leaf views should return 0.
///
public override int Count { get; }
///
/// Indexer to access child views by index.
/// Layout containers should implement this to expose their children.
///
public override View this[int index] { get; }
}
}
namespace Xui.Core.UI
{
using System.Collections;
///
/// A compact collection of CSS-like class name strings for a view.
/// Stores up to 3 class names inline without allocation. If more are added,
/// spills over into a .
///
public struct ClassNameCollection : IEnumerable
{
///
/// Returns the number of class names in the collection.
///
public readonly int Count { get; }
///
/// Returns true if the collection contains the specified class name.
///
public readonly bool Contains(string className);
///
/// Adds a class name to the collection. Returns true if it was added (not already present).
///
public bool Add(string className);
///
/// Removes a class name from the collection. Returns true if it was found and removed.
///
public bool Remove(string className);
/// Adds a class name to the collection and returns the updated collection.
public static ClassNameCollection operator +(ClassNameCollection collection, string className);
/// Removes a class name from the collection and returns the updated collection.
public static ClassNameCollection operator -(ClassNameCollection collection, string className);
/// Returns an enumerator that iterates over all class names in the collection.
public readonly IEnumerator GetEnumerator();
}
}
namespace Xui.Core.UI
{
///
/// Passed to when a view is removed from the visual tree.
///
public ref struct DetachEventRef
{
/// Initializes a new .
public DetachEventRef();
}
///
/// Indicates the semantic inline direction of content, such as left-to-right or right-to-left.
/// Used to resolve text alignment, layout flow, and mirroring behavior.
///
public enum Direction : byte
{
///
/// Inherit direction from the parent view.
///
Inherit = 0,
///
/// Left-to-right flow (default for Western languages).
///
LeftToRight = 1,
///
/// Right-to-left flow (used in Arabic, Hebrew, etc).
///
RightToLeft = 2
}
///
/// Controls whether layout and rendering should respect directionality and writing mode.
/// Used to suppress mirroring and bidi-aware behavior for diagrams, graphs, and non-linguistic views.
///
public enum Flow : byte
{
///
/// Inherit flow behavior from the parent view.
///
Inherit = 0,
///
/// Enable direction-aware and writing-mode-aware behavior.
///
Aware = 1,
///
/// Disable all direction-aware layout and rendering. Used for charts, maps, etc.
///
Unaware = 2
}
///
/// Represents the resolved physical direction of layout flow along an axis.
/// This is derived from and ,
/// and is used to control stacking, alignment, and layout flow along block or inline axes.
///
public enum FlowDirection : byte
{
///
/// Content flows from left to right.
///
LeftToRight = 0,
///
/// Content flows from right to left.
///
RightToLeft = 1,
///
/// Content flows from top to bottom.
///
TopToBottom = 2,
///
/// Content flows from bottom to top.
///
BottomToTop = 3
}
///
/// Specifies how a view should be aligned horizontally within its layout bounds.
/// Used by parent containers during layout to position the view along the inline axis.
///
public enum HorizontalAlignment : byte
{
///
/// Stretch to fill the full available horizontal space.
///
Stretch = 0,
///
/// Align to the left edge (or start edge in LTR layouts).
///
Left = 1,
///
/// Center horizontally within the available space.
///
Center = 2,
///
/// Align to the right edge (or start edge in RTL layouts).
///
Right = 3
}
///
/// Service interface for programmatic focus navigation.
/// Resolved via this.GetService<IFocus>() from any .
/// provides the default implementation.
///
public interface IFocus
{
/// Moves focus to the next focusable element (same order as Tab).
void Next();
/// Moves focus to the previous focusable element (same order as Shift+Tab).
void Previous();
/// Returns the next focusable view without moving focus. Does not wrap by default.
View? GetNext(bool wrap = false);
/// Returns the preceding focusable view without moving focus. Does not wrap by default.
View? GetPrevious(bool wrap = false);
///
/// Gets or sets the view that currently holds keyboard focus.
/// Setting to null clears focus. Setting fires /
/// on the affected views.
///
View? FocusedView { get; set; }
}
/// Declares whether root content supplies an opaque background for the entire window.
///
/// This is a coverage promise, not a layout hint. Return true only when every draw
/// covers the whole display area with opaque pixels. Hosts may skip their clear.
/// Wrappers must forward the promise explicitly, and changes must invalidate the view.
///
public interface IFullScreenView
{
/// Whether the current state paints the whole display area opaquely.
bool DrawsOpaqueFullScreen { get; }
}
/// Defines an anchor alignment on one layout axis.
public enum LayoutAlign : byte
{
/// Align to the start edge.
Start,
/// Align to the center.
Center,
/// Align to the end edge.
End,
}
/// Passes that may be requested during a render-surface update.
[Flags]
public enum LayoutPass : byte
{
/// Advance time-based state.
Animate = 1 << 0,
/// Measure desired size.
Measure = 1 << 1,
/// Arrange final frame.
Arrange = 1 << 2,
/// Render the view.
Render = 1 << 3,
}
/// Defines how an axis participates in a layout pass.
public enum LayoutSizeMode : byte
{
/// The view must exactly match the available size.
Exact,
/// The view may size to content without exceeding the available size.
AtMost,
}
/// Pass selection and per-pass immutable constraints for one view update.
public readonly struct LayoutUpdate
{
/// Initializes a layout update.
public LayoutUpdate(LayoutPass pass, MeasureConstraints measure, ArrangeConstraints arrange);
/// Requested passes.
public LayoutPass Pass { get; }
/// Measurement constraints.
public MeasureConstraints Measure { get; }
/// Arrangement constraints.
public ArrangeConstraints Arrange { get; }
/// Whether animation is requested.
public bool IsAnimate { get; }
/// Whether measurement is requested.
public bool IsMeasure { get; }
/// Whether arrangement is requested.
public bool IsArrange { get; }
/// Whether rendering is requested.
public bool IsRender { get; }
}
///
/// Controls the visual backdrop material of a popup surface.
/// Mirrors
/// for popup-specific use.
///
public enum PopupEffect
{
///
/// Standard opaque popup with no translucency.
///
None = 0,
///
/// Translucent popup using the system's standard popup/popover material.
/// On macOS this uses NSVisualEffectView with the Popover material,
/// which on macOS 26+ automatically gains the liquid-glass treatment.
///
Translucent = 1,
}
///
/// Specifies the preferred placement of a popup relative to its anchor rect.
/// The platform may adjust placement to keep the popup on screen.
///
public enum PopupPlacement
{
/// Show below the anchor (default for dropdowns/comboboxes).
Below,
/// Show above the anchor.
Above,
/// Show to the right of the anchor (e.g. nested/submenu).
Right,
/// Show to the left of the anchor.
Left,
}
///
/// Specifies how a view should be aligned vertically within its layout bounds.
/// Used by parent containers to control vertical positioning along the block axis.
///
public enum VerticalAlignment : byte
{
///
/// Stretch to fill the full available vertical space.
///
Stretch = 0,
///
/// Align to the top edge (or start edge in top-down layouts).
///
Top = 1,
///
/// Center vertically within the available space.
///
Middle = 2,
///
/// Align to the bottom edge (or start edge in bottom-up layouts).
///
Bottom = 3
}
///
/// 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.
///
///
/// 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 partial class View : IServiceProvider, Layer.ILayerHost
{
///
/// Resolves a service of the given type by walking up the parent chain.
/// Returns null if no ancestor provides the service.
///
public virtual object? GetService(Type serviceType);
}
///
/// 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.
///
///
/// 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 partial class View
{
/// Gets or sets an extra on this view.
public nint this[Extra key] { get; set; }
/// Gets or sets an extra on this view.
public nfloat this[Extra key] { get; set; }
/// Gets or sets a extra on this view.
public string? this[Extra key] { get; set; }
/// Gets or sets a extra on this view.
public bool this[Extra key] { get; set; }
///
/// Fallback indexer for extras whose value type is not covered by a typed overload (e.g. enums).
/// Values are boxed. Prefer the typed overloads for , ,
/// , and where possible.
///
public object? this[Extra key] { get; set; }
///
/// Non-generic base for . Used as a dictionary key when storage is implemented.
///
public abstract class Extra
{
}
///
/// A typed key for attaching extra layout or styling data to any .
/// Declare one static instance per logical property (e.g. Grid.Row, FlexBox.Grow)
/// and use it with the view indexer: view[Grid.Row] = 2.
///
/// The type of the value stored under this key.
public sealed class Extra : Extra
{
/// The value returned when no data has been stored for this key on a given view.
public T DefaultValue { get; }
/// Returned by the indexer getter until a value is explicitly set.
public Extra(T defaultValue = default !);
///
/// Returns the value stored for this key on ,
/// or if nothing has been set.
///
public T Get(View view);
}
}
///
/// 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.
///
///
/// 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 partial class View
{
///
/// Returns the number of child views. Used by layout containers and traversal logic.
/// Leaf views should return 0.
///
public virtual int Count { get; }
///
/// Indexer to access child views by index.
/// Layout containers should implement this to expose their children.
///
public virtual View this[int index] { get; }
///
/// 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);
///
/// 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);
///
/// 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(ref T? field, T? value)
where T : View;
}
///
/// 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.
///
///
/// 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 partial class View
{
///
/// 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);
///
/// Called when this view is removed from the visual tree.
/// Override to release any resources acquired in .
///
protected virtual void OnDetach(ref DetachEventRef e);
///
/// 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();
///
/// 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();
}
///
/// Specifies the orientation and flow direction of text and block layout.
/// Affects which axis is considered "block" and "inline".
///
public enum WritingMode : byte
{
///
/// Inherit direction from the parent view.
///
Inherit,
///
/// Horizontal writing mode. Text flows left-to-right, lines stack top-to-bottom.
///
HorizontalTB,
///
/// Vertical writing mode. Lines stack right-to-left, text flows top-to-bottom.
///
VerticalRL,
///
/// Vertical writing mode. Lines stack left-to-right, text flows top-to-bottom.
///
VerticalLR,
///
/// Sideways vertical mode. Lines stack right-to-left, but glyphs are rotated to remain horizontal.
///
SidewaysRL,
///
/// Sideways vertical mode. Lines stack left-to-right, with horizontal glyph orientation.
///
SidewaysLR
}
}
namespace Xui.Core.UI
{
using Xui.Core.Canvas;
using Xui.Core.Math2D;
///
/// A layout container that arranges its children horizontally from left to right.
///
/// Each child is measured with unconstrained width and a constrained height.
/// The container expands to fit the combined width of all children.
///
public class HorizontalStack : ViewCollection
{
/// Override to compute the desired border-edge size.
protected override Size MeasureCore(Size availableBorderEdgeSize, IMeasureContext context);
/// Override to arrange children within this view's final frame.
protected override void ArrangeCore(Rect rect, IMeasureContext context);
}
///
/// A layout container that arranges its children in a horizontal stack,
/// assigning each child the same width.
///
///
///
/// If the parent provides a constrained width, the container divides
/// the available width equally among all children.
///
///
/// If the width is unconstrained (infinite), the container measures each child
/// to determine the maximum width, and assigns that uniform width to all columns.
///
///
/// The height of the container is based on the tallest child.
///
///
public class HorizontalUniformStack : ViewCollection
{
///
/// Measures the desired size of this layout container and its children,
/// based on the available space provided by the parent.
///
///
/// The space available for layout, excluding padding and borders.
///
/// The measure context used for child measurement.
///
/// The desired size of this container based on its layout strategy.
///
protected override Size MeasureCore(Size availableBorderEdgeSize, IMeasureContext context);
/// Override to arrange children within this view's final frame.
protected override void ArrangeCore(Rect rect, IMeasureContext context);
}
///
/// A view that displays a single line of styled text.
///
public class Label : View
{
///
/// Gets or sets the text content displayed by the label.
///
public string Text { get; set; }
///
/// Gets or sets the color used to fill the text.
///
public Color TextColor { get; set; }
/// Gets or sets the complete font used for text measurement and rendering.
public Font Font { get; set; }
/// Gets or sets the font family used for rendering the text.
public string FontFamily { get; set; }
///
/// Gets or sets the font size in points.
///
public nfloat FontSize { get; set; }
///
/// Gets or sets the font style (e.g., normal, italic, oblique).
///
public FontStyle FontStyle { get; set; }
///
/// Gets or sets the font weight (e.g., normal, bold, numeric weight).
///
public FontWeight FontWeight { get; set; }
///
/// Gets or sets the font stretch (e.g., condensed, semi-expanded etc.).
///
public FontStretch FontStretch { get; set; }
///
/// Gets or sets the line height of the text, in user units.
///
///
/// If set to a numeric value, this value overrides the default line height computation from the font metrics.
/// If set to , the line height will be automatically computed based on the font's ascender,
/// descender, and line gap, or fallback to a platform-specific multiplier of the (typically 1.2×).
///
public nfloat LineHeight { get; set; }
/// Override to compute the desired border-edge size.
protected override Size MeasureCore(Size availableBorderEdgeSize, IMeasureContext context);
/// Override to render this view and its children.
protected override void RenderCore(IContext context);
}
///
/// A layout container that arranges its children vertically from top to bottom.
///
/// Each child is measured with an unconstrained height and is allowed to take up as much vertical space as needed.
/// The container expands to fit the combined height of all children.
///
public class VerticalStack : ViewCollection
{
/// Override to compute the desired border-edge size.
protected override Size MeasureCore(Size availableBorderEdgeSize, IMeasureContext context);
/// Override to arrange children within this view's final frame.
protected override void ArrangeCore(Rect rect, IMeasureContext context);
}
///
/// A layout container that arranges its children in a vertical stack,
/// giving each child the same height.
///
///
///
/// If the parent provides a constrained height, the container divides
/// the available height equally among all children.
///
///
/// If the height is unconstrained (infinite), the container measures each child
/// to determine the maximum height, and uses that height for all rows.
///
///
public class VerticalUniformStack : ViewCollection
{
/// Override to compute the desired border-edge size.
protected override Size MeasureCore(Size availableBorderEdgeSize, IMeasureContext context);
/// Override to arrange children within this view's final frame.
protected override void ArrangeCore(Rect rect, IMeasureContext context);
}
///
/// A base class for container views that hold and manage a list of child views.
/// Provides methods for adding, removing, rendering, and hit testing children.
///
public class ViewCollection : View
{
///
/// The internal list of child views contained within this view.
///
protected readonly List children;
///
/// Gets the number of child views in this collection.
///
public override int Count { get; }
///
/// Gets the child view at the specified index.
///
public override View this[int index] { get; }
///
/// Adds the provided views to this container during object initialization.
/// This property is intended for use with C# object initializers and will not clear existing children.
///
public ReadOnlySpan Content { init; }
///
/// Adds a view to this container.
///
/// Thrown if the view already has a parent.
public virtual void Add(View child);
///
/// Removes a view from this container.
///
public virtual void Remove(View child);
///
/// Removes all child views from this container.
///
public virtual void Clear();
}
}
namespace Xui.Core.UI
{
using Xui.Core.Canvas;
using Xui.Core.Math2D;
using Xui.Core.UI.Input;
/// A canvas text editor that a native text-input service can manipulate.
public interface ITextEditingClient : ITextInputClient
{
/// The document and selection shared with the native input system.
TextEditingState Editor { get; }
/// Whether a native interaction owns caret, selection handles, and touch selection.
bool NativeSelection { get; set; }
/// The input's hit-test bounds, in logical window coordinates.
Rect InputBounds { get; }
/// Returns the caret rectangle for a UTF-16 offset, in logical window coordinates.
Rect GetCaretRect(int offset, ITextMeasureContext measure);
/// Hit-tests a logical window point, returning a UTF-16 grapheme boundary.
int GetTextPosition(Point point, ITextMeasureContext measure);
}
}
namespace Xui.Core.UI
{
using Xui.Core.UI.Input;
///
/// Basic text-entry capabilities of a focusable view. Focus requests the software
/// keyboard; the responder can query these traits without copying the text buffer.
/// This does not imply support for marked text, IME composition, or native range editing.
///
public interface ITextInputClient
{
/// Whether the input contains any text.
bool HasText { get; }
/// Whether the input is a masked password field.
bool IsPassword { get; }
/// Keyboard layout, content semantics and return-key action.
TextInputOptions InputOptions { get; }
/// Whether a keyboard action is currently available.
bool CanPerformInputAction(TextInputAction action);
/// Handles a keyboard action, including focus navigation or finishing editing.
void PerformInputAction(TextInputAction action);
}
}
namespace Xui.Core.UI
{
using Xui.Core.Canvas;
using Xui.Core.DI;
using Xui.Core.Math2D;
///
/// A view that displays an image. Works like HTMLImageElement: it holds an
/// handle (acquired from the service chain) and sets its source
/// via . The platform catalog handles caching and device-lost
/// rehydration transparently.
///
public class ImageView : View
{
///
/// Gets or sets the URI of the image to display.
/// Setting this property triggers a load if the view is already active.
///
public string? Source { get; set; }
///
/// 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 override void OnActivate();
///
/// 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 override void OnDeactivate();
/// Override to compute the desired border-edge size.
protected override Size MeasureCore(Size availableBorderEdgeSize, IMeasureContext context);
/// Override to render this view and its children.
protected override void RenderCore(IContext context);
}
}
namespace Xui.Core.UI
{
using Xui.Core.Canvas;
using Xui.Core.Debug;
///
/// Immutable services and timing shared by every view visited during one render-surface update.
///
public readonly struct LayoutFrameContext
{
/// Initializes a frame context.
public LayoutFrameContext(TimeSpan previousTime, TimeSpan currentTime, IMeasureContext? measureContext, IContext? renderContext, InstrumentsAccessor instruments);
/// Time of the preceding frame.
public TimeSpan PreviousTime { get; }
/// Time of this frame.
public TimeSpan CurrentTime { get; }
/// Measurement services for this render surface.
public IMeasureContext? MeasureContext { get; }
/// Rendering context for this render surface.
public IContext? RenderContext { get; }
/// Instrumentation associated with this render surface.
public InstrumentsAccessor Instruments { get; }
}
}
namespace Xui.Core.UI
{
using Xui.Core.Abstract.Events;
using Xui.Core.Abstract;
using Xui.Core.Canvas.Composition.Graphics;
using Xui.Core.Canvas;
using Xui.Core.Debug;
using Xui.Core.Math2D;
using Xui.Core.UI.Input;
///
/// The root container view that bridges a with its UI content hierarchy.
///
public class RootView : View, IContent, IFocus
{
/// The render-surface instruments that own this visual tree, if instrumentation is enabled.
public IRenderSurfaceInstrumentsSink? RenderSurfaceInstruments { get; }
/// The input event router for this view tree.
public EventRouter EventRouter { get; }
/// The window that owns this root view.
public Window Window { get; }
/// The currently focused view within this tree, or null if none.
public View? FocusedView { get; set; }
/// Gets or sets the single content view hosted by this root view.
public View? Content { get; set; }
/// The content followed by visible in-window overlays, in render and hit-test order.
public override int Count { get; }
/// Gets the child view at the given index.
public override View this[int index] { get; }
/// Override to compute the desired border-edge size.
protected override Size MeasureCore(Size available, IMeasureContext context);
/// Override to arrange children within this view's final frame.
protected override void ArrangeCore(Rect rect, IMeasureContext context);
/// Override to render this view and its children.
protected override void RenderCore(IContext context);
/// Initializes a new RootView for the given window.
/// The window that owns this root view.
public RootView(Window window);
///
/// Resolves a service of the given type by walking up the parent chain.
/// Returns null if no ancestor provides the service.
///
public override object? GetService(Type serviceType);
/// Called when a child view signals that its rendered state has changed.
protected override void OnChildRenderChanged(View child);
}
}
namespace Xui.Core.UI
{
using Xui.Core.Abstract.Events;
using Xui.Core.Abstract;
using Xui.Core.Animation;
using Xui.Core.Canvas.Composition.Graphics;
using Xui.Core.Canvas;
using Xui.Core.DI;
using Xui.Core.Math2D;
using Xui.Core.UI.Input;
///
/// Controls which axis (or axes) a scrolls along.
///
public enum ScrollDirection
{
/// Scrolls vertically only (default).
Vertical,
/// Scrolls horizontally only.
Horizontal,
/// Scrolls both axes simultaneously (map-panning style).
Both
}
///
/// A container that clips its content and allows scrolling via pointer drag/fling
/// and scroll wheel input. Supports vertical, horizontal, or both axes.
/// Displays thin overlay scrollbar indicators on the relevant edges.
///
public partial class ScrollView : View
{
/// Current scroll displacement, including elastic overscroll.
public Vector ScrollOffset { get; }
/// Raised after the content's scroll transform changes, including during inertia and rebound.
public event Action? ScrollChanged;
/// A viewport-sized foreground view that stays outside the content's scroll transform.
/// Its input still participates in this scroll view's gesture negotiation.
public View? Overlay { get; set; }
/// Width of the scrollbar track in points.
public nfloat ScrollbarWidth { get; set; }
/// Inset at each end of the scrollbar. When unset, adapts to the screen corners.
public nfloat ScrollbarEndInset { get; set; }
///
/// Gets or sets whether content is clipped and culled to the viewport.
/// Disable this for a root scroller that is laid out inside a safe area but
/// is allowed to paint underneath the system areas while it scrolls.
///
public bool ClipToViewport { get; set; }
/// Retains this viewport as a native composition surface where supported.
public bool UseCompositionGroup { get; set; }
///
/// Gets or sets which axis (or axes) this scroll view responds to.
///
public new ScrollDirection Direction { get; set; }
///
/// Gets or sets the single child view to scroll.
///
public View? Content { get; set; }
/// Number of child views.
public override int Count { get; }
/// Gets the child view at the given index.
public override View this[int index] { get; }
///
/// 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 override void OnActivate();
/// Override to compute the desired border-edge size.
protected override Size MeasureCore(Size available, IMeasureContext context);
/// Override to arrange children within this view's final frame.
protected override void ArrangeCore(Rect rect, IMeasureContext context);
///
/// Maps a point from this view's parent coordinate space into this view's local coordinate space.
///
///
/// Layout still supplies frames using the existing coordinate model. The default identity
/// mapping deliberately preserves that behaviour until a container opts into a local
/// coordinate transform. Containers such as can override this
/// to map input into their content space.
///
public override Point TransformPoint(Point point);
///
/// Maps a point from this view's local coordinate space into its parent coordinate space.
///
///
/// This must be the inverse of for points that can be hit
/// tested. It is separate so a view can support coordinate mappings that are not yet
/// represented by the canvas transform API.
///
public override Point InverseTransformPoint(Point point);
///
/// Conservatively maps an axis-aligned rectangle from this view's parent coordinate space
/// into this view's coordinate space.
///
///
/// For non-translation transforms, an override must return the smallest parent-axis-aligned
/// rectangle that encloses every transformed corner.
///
public override Rect TransformRect(Rect rect);
///
/// Conservatively maps an axis-aligned rectangle from this view's coordinate space into its
/// parent coordinate space.
///
///
/// For non-translation transforms, an override must return the smallest parent-axis-aligned
/// rectangle that encloses every transformed corner.
///
public override Rect InverseTransformRect(Rect rect);
///
/// Determines whether the given point (in this view's local coordinates) hits this view's visual bounds.
/// Used for input dispatch and hit testing.
///
/// The point to test, relative to this view's coordinate space.
///
/// true if the point is inside the view's frame; otherwise false.
public override bool HitTest(Point point);
/// Override to render this view and its children.
protected override void RenderCore(IContext context);
///
/// Called during event dispatch to handle a pointer event in a specific event phase.
///
public override void OnPointerEvent(ref PointerEventRef e, EventPhase phase);
/// Override to animate this view and its children.
protected override void AnimateCore(TimeSpan previous, TimeSpan current);
///
/// 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 override void OnDeactivate();
}
}
namespace Xui.Core.UI
{
using Xui.Core.Animation;
///
/// A container that clips its content and allows scrolling via pointer drag/fling
/// and scroll wheel input. Supports vertical, horizontal, or both axes.
/// Displays thin overlay scrollbar indicators on the relevant edges.
///
public partial class ScrollView
{
}
}
namespace Xui.Core.UI
{
using Xui.Core.Abstract.Events;
using Xui.Core.DI;
///
/// A container that clips its content and allows scrolling via pointer drag/fling
/// and scroll wheel input. Supports vertical, horizontal, or both axes.
/// Displays thin overlay scrollbar indicators on the relevant edges.
///
public partial class ScrollView
{
///
/// Called when a scroll wheel or trackpad scroll event is dispatched to this view.
/// Override to handle scroll input. Set to stop propagation.
///
public override void OnScrollWheel(ref ScrollWheelEventRef e);
}
}
namespace Xui.Core.UI
{
using Xui.Core.Canvas;
using Xui.Core.Math1D;
using Xui.Core.Math2D;
using Xui.Core.UI.Input;
using Xui.Core.UI.Layer;
///
/// A single-line text input view implemented as
/// LayerView<View, FocusBorderLayer<View, TextInputLayer>>.
/// All text editing state, selection, caret blinking, and hit-testing live in
/// ; focus-aware border drawing lives in
/// .
///
public class TextBox : LayerView>, ITextEditingClient
{
/// Gets whether this view can receive keyboard focus. Always true for .
public override bool Focusable { get; }
/// Keyboard hints, applied when this field receives focus.
public TextInputOptions InputOptions { get; set; }
/// Whether a keyboard action is currently available.
public bool CanPerformInputAction(TextInputAction action);
/// Handles a keyboard action, including focus navigation or finishing editing.
public void PerformInputAction(TextInputAction action);
/// The document and selection shared with the native input system.
public Xui.Core.UI.Input.TextEditingState Editor { get; }
/// Whether a native interaction owns caret, selection handles, and touch selection.
public bool NativeSelection { get; set; }
/// The input's hit-test bounds, in logical window coordinates.
public Rect InputBounds { get; }
/// Returns the caret rectangle for a UTF-16 offset, in logical window coordinates.
public Rect GetCaretRect(int offset, ITextMeasureContext measure);
/// Hit-tests a logical window point, returning a UTF-16 grapheme boundary.
public int GetTextPosition(Point point, ITextMeasureContext measure);
/// Whether the input contains any text.
public bool HasText { get; }
///
/// 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 override void OnDeactivate();
/// Initializes a new with default styling.
public TextBox();
/// Gets or sets the text content of this input.
public string Text { get; set; }
/// Gets or sets the current text selection range.
public Interval.ClosedOpen Selection { get; set; }
/// Gets or sets whether input is masked as a password.
public bool IsPassword { get; set; }
/// Gets or sets whether all text is selected when the view receives focus.
public bool SelectAllOnFocus { get; set; }
/// Gets or sets the character filter predicate for input validation.
public Func? InputFilter { get; set; }
/// Gets or sets the text color.
public Color Color { get; set; }
/// Gets or sets the color of selected text.
public Color SelectedColor { get; set; }
/// Gets or sets the background color of the selection.
public Color SelectionBackgroundColor { get; set; }
/// Gets or sets the complete text font.
public Font Font { get; set; }
/// Gets or sets the font family name.
public string FontFamily { get; set; }
/// Gets or sets the font size.
public nfloat FontSize { get; set; }
/// Gets or sets the font style.
public FontStyle FontStyle { get; set; }
/// Gets or sets the font weight.
public FontWeight FontWeight { get; set; }
/// Gets or sets the font stretch.
public FontStretch FontStretch { get; set; }
}
}
namespace Xui.Core.UI
{
using Xui.Core.Canvas.Composition.Graphics;
using Xui.Core.Canvas;
using Xui.Core.Math2D;
///
/// Hosts one child and presents it through an affine transform without changing
/// its layout rectangle. Input and render culling are mapped through the inverse
/// transform so a translated or scaled child remains interactive and cullable.
///
public class TransformView : View
{
/// Retain the complete child drawing while only its native surface transform changes.
public bool UseCompositionGroup { get; set; }
/// Gets or sets the single child presented by this host.
public View? Content { get; set; }
///
/// Gets or sets the transform from this view's layout coordinates into its
/// parent presentation coordinates.
///
public AffineTransform Transform { get; set; }
///
/// Returns the number of child views. Used by layout containers and traversal logic.
/// Leaf views should return 0.
///
public override int Count { get; }
///
/// Indexer to access child views by index.
/// Layout containers should implement this to expose their children.
///
public override View this[int index] { get; }
///
/// Gets this view's conservative bounds in its parent coordinate space for render culling.
///
///
/// A container may override this when its rendered geometry differs from its layout frame.
/// Computing the union of descendant culling frames is deliberately deferred: it can be
/// more expensive than rendering for small subtrees.
///
public override Rect CullingFrame { get; }
///
/// Maps a point from this view's parent coordinate space into this view's local coordinate space.
///
///
/// Layout still supplies frames using the existing coordinate model. The default identity
/// mapping deliberately preserves that behaviour until a container opts into a local
/// coordinate transform. Containers such as can override this
/// to map input into their content space.
///
public override Point TransformPoint(Point point);
///
/// Maps a point from this view's local coordinate space into its parent coordinate space.
///
///
/// This must be the inverse of for points that can be hit
/// tested. It is separate so a view can support coordinate mappings that are not yet
/// represented by the canvas transform API.
///
public override Point InverseTransformPoint(Point point);
///
/// Conservatively maps an axis-aligned rectangle from this view's parent coordinate space
/// into this view's coordinate space.
///
///
/// For non-translation transforms, an override must return the smallest parent-axis-aligned
/// rectangle that encloses every transformed corner.
///
public override Rect TransformRect(Rect rect);
///
/// Conservatively maps an axis-aligned rectangle from this view's coordinate space into its
/// parent coordinate space.
///
///
/// For non-translation transforms, an override must return the smallest parent-axis-aligned
/// rectangle that encloses every transformed corner.
///
public override Rect InverseTransformRect(Rect rect);
///
/// Determines whether the given point (in this view's local coordinates) hits this view's visual bounds.
/// Used for input dispatch and hit testing.
///
/// The point to test, relative to this view's coordinate space.
///
/// true if the point is inside the view's frame; otherwise false.
public override bool HitTest(Point point);
/// Override to render this view and its children.
protected override void RenderCore(IContext context);
/// Renders content after has been applied.
protected virtual void RenderTransformedContent(IContext context);
}
}
namespace Xui.Core.UI
{
using Xui.Core.DI;
///
/// 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.
///
///
/// 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 partial class View
{
///
/// Called when this view receives keyboard focus.
///
protected internal virtual void OnFocus();
///
/// Called when this view loses keyboard focus.
///
protected internal virtual void OnBlur();
///
/// Gets whether this view can receive keyboard focus via Tab navigation.
///
public virtual bool Focusable { get; }
/// Whether focusing this view requests the platform's software keyboard.
public virtual bool RequiresKeyboard { get; }
///
/// Gets whether this view currently has keyboard focus.
///
public bool IsFocused { get; }
///
/// Requests keyboard focus for this view.
///
public bool Focus();
///
/// Releases keyboard focus from this view.
///
public void Blur();
}
}
namespace Xui.Core.UI
{
using Xui.Core.Abstract.Events;
using Xui.Core.UI.Input;
///
/// 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.
///
///
/// 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 partial class View
{
///
/// Called during event dispatch to handle a pointer event in a specific event phase.
///
public virtual void OnPointerEvent(ref PointerEventRef e, EventPhase phase);
///
/// Called when a scroll wheel or trackpad scroll event is dispatched to this view.
/// Override to handle scroll input. Set to stop propagation.
///
public virtual void OnScrollWheel(ref ScrollWheelEventRef e);
/// Handles a platform magnification gesture. Set Handled to stop bubbling.
public virtual void OnZoom(ref ZoomEventRef e);
///
/// Called when a key is pressed while this view has focus.
///
public virtual void OnKeyDown(ref KeyEventRef e);
///
/// Called when a character is input while this view has focus.
///
public virtual void OnChar(ref KeyEventRef e);
}
}
namespace Xui.Core.UI
{
using Xui.Core.Canvas;
using Xui.Core.Debug;
using Xui.Core.Math2D;
///
/// 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.
///
///
/// 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 partial class View
{
/// The active render culling rectangle in this view's coordinate space, if any.
protected Rect? RenderCullingFrame { get; }
/// Drives the requested passes using shared frame state and per-view constraints.
public virtual void Update(in LayoutFrameContext frame, in LayoutUpdate update, ref LayoutMeasurements measurements);
/// Advances animation state for this view and all descendants.
public void Animate(TimeSpan previousTime, TimeSpan currentTime);
/// Measures the view and returns the desired margin-box size.
public Size Measure(Size availableSize, IMeasureContext context);
/// Arranges the view within , finalising its position and size.
public Rect Arrange(Rect rect, IMeasureContext context, Size? desiredSize = null);
/// Renders the view. Must be called after layout is complete.
public void Render(IContext context);
/// Performs bookkeeping and animation for this view.
protected void AnimateShell(in LayoutFrameContext frame);
/// Measures this view using the supplied immutable constraints.
protected void MeasureShell(in LayoutFrameContext frame, in MeasureConstraints constraints, ref LayoutMeasurements measurements);
/// Arranges this view using the supplied immutable constraints.
protected void ArrangeShell(in LayoutFrameContext frame, in ArrangeConstraints constraints, ref LayoutMeasurements measurements);
/// Performs bookkeeping and renders this view.
protected void RenderShell(in LayoutFrameContext frame, Rect? parentCullingFrame = null);
/// Override to animate this view and its children.
protected virtual void AnimateCore(TimeSpan previousTime, TimeSpan currentTime);
/// Override to compute the desired border-edge size.
protected virtual Size MeasureCore(Size availableBorderEdgeSize, IMeasureContext context);
/// Override to arrange children within this view's final frame.
protected virtual void ArrangeCore(Rect rect, IMeasureContext context);
/// Override to render this view and its children.
protected virtual void RenderCore(IContext context);
///
/// Applies the drawing defaults used at the start of every view render.
/// The active transform and clip are intentionally inherited from the parent.
///
protected virtual void SetDefaultRenderState(IContext context);
/// Renders a child while preserving this view's active culling rectangle.
protected internal void RenderChild(IContext context, View child);
/// Renders a child using an explicit culling rectangle in this view's coordinate space.
protected internal void RenderChild(IContext context, View child, Rect cullingFrame);
}
}
namespace Xui.Core.UI
{
using System.Diagnostics.CodeAnalysis;
///
/// Provides extension methods for navigating the Xui view tree.
///
public static class ViewExtensions
{
///
/// Returns an allocation-free enumerable that walks up the parent chain of a view.
///
/// The view whose parent chain should be traversed.
/// An enumerable of the view's parents, from immediate to root.
public static ParentsEnumerable Parents(this View view);
///
/// Attempts to find the first parent of a specific type in the view tree.
/// Zero allocations. Returns true if a matching parent was found.
///
/// The type of view to search for.
/// The view whose parent chain will be searched.
/// The found parent of type , or null if not found.
/// True if a matching parent was found; otherwise, false.
public static bool TryFindParent(this View view, [NotNullWhen(true)] out T? result)
where T : View;
///
/// Performs a depth-first search of the view subtree (including itself)
/// and returns the first view whose matches .
///
/// The matching view, or null if not found.
public static View? FindViewById(this View root, string id);
///
/// Performs a depth-first search of the view subtree (including itself)
/// and collects all views whose contains .
///
public static void FindViewsByClass(this View root, string className, List results);
///
/// Allocation-free enumerable for walking up the parent chain of a view.
///
public readonly ref struct ParentsEnumerable
{
///
/// Creates a new starting from the given view.
///
/// The starting view.
public ParentsEnumerable(View? start);
///
/// Returns an enumerator that iterates over the view's parents.
///
public Enumerator GetEnumerator();
///
/// Enumerator for , walking up the view hierarchy.
///
public ref struct Enumerator
{
///
/// Initializes a new instance of the struct.
///
/// The starting view for traversal.
public Enumerator(View? start);
///
/// Gets the current parent view in the traversal.
///
public View Current { get; }
///
/// Moves to the next parent view.
///
/// True if there is a next parent; otherwise, false.
public bool MoveNext();
}
}
}
}