// 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.Layer { using Xui.Core.Abstract.Events; using Xui.Core.Canvas; using Xui.Core.Math2D; using Xui.Core.UI.Input; /// /// A layer that draws a background fill, a border stroke, and optional padding around /// a child layer. Rendering logic is identical to but /// expressed as a composable struct with no heap allocation. /// /// The host type. Must implement . /// The inner layer that receives the inset rectangle. public struct BorderLayer : ILayer where TView : ILayerHost where TChild : struct, ILayer { /// The inner layer rendered inside the border and padding. public TChild Child; /// Per-side border thickness. public Frame BorderThickness; /// Corner radius for the background fill and border stroke. public CornerRadius CornerRadius; /// Background fill color. public Color BackgroundColor; /// Border stroke color. public Color BorderColor; /// Padding between the border edge and the child layer. public Frame Padding; /// Returns the desired border-edge size given the available space. public Size Measure(TView view, Size availableSize, IMeasureContext context); /// Finalises position and size within . public void Arrange(TView view, Rect rect, IMeasureContext context); /// Draws content. Called after Arrange. public void Render(TView view, IContext context); /// Advances time-based state (animations, blinking cursors, etc.). public void Animate(TView view, TimeSpan previousTime, TimeSpan currentTime); /// Handles a pointer event in the given dispatch phase. public void OnPointerEvent(TView view, ref PointerEventRef e, EventPhase phase); /// Handles a key-down event while the host view has focus. public void OnKeyDown(TView view, ref KeyEventRef e); /// Handles a character input event while the host view has focus. public void OnChar(TView view, ref KeyEventRef e); /// Called when the host view gains keyboard focus. public void OnFocus(TView view); /// Called when the host view loses keyboard focus. public void OnBlur(TView view); } /// /// A terminal layer that delegates layout and rendering to a child , /// bridging the layer tree back into the standard view hierarchy. /// Input routing is left to the which hit-tests the child /// view directly, so all input methods here are intentional no-ops. /// public struct ContentLayer : ILayer { /// The child view to measure, arrange, and render. public View? Child; /// Returns the desired border-edge size given the available space. public Size Measure(View view, Size availableSize, IMeasureContext context); /// Finalises position and size within . public void Arrange(View view, Rect rect, IMeasureContext context); /// Draws content. Called after Arrange. public void Render(View view, IContext context); /// Advances time-based state (animations, blinking cursors, etc.). public void Animate(View view, TimeSpan previousTime, TimeSpan currentTime); /// Handles a pointer event in the given dispatch phase. public void OnPointerEvent(View view, ref PointerEventRef e, EventPhase phase); /// Handles a key-down event while the host view has focus. public void OnKeyDown(View view, ref KeyEventRef e); /// Handles a character input event while the host view has focus. public void OnChar(View view, ref KeyEventRef e); /// Called when the host view gains keyboard focus. public void OnFocus(View view); /// Called when the host view loses keyboard focus. public void OnBlur(View view); } /// /// Container for dock layout types. /// Usage: DockLayer.Dock3<View, StepButton, NumberInputLayer, StepButton> public static class DockLayer { /// Determines how docked children are aligned on the cross axis. public enum Align { /// Align to the left edge. Left, /// Stretch to fill the available cross-axis space. Stretch, /// Align to the right edge. Right } /// Wraps a dockable child with its alignment setting. public struct Docked where T : struct { /// The cross-axis alignment for the docked child. public Align Align; /// The docked child layer. public T Child; } /// Two-slot dock layout. public struct Dock2 : ILayer where TView : ILayerHost where T1 : struct, ILayer where T2 : struct, ILayer { /// The first docked child. public Docked Child1; /// The second docked child. public Docked Child2; /// Returns the desired border-edge size given the available space. public Size Measure(TView view, Size available, IMeasureContext ctx); /// Finalises position and size within . public void Arrange(TView view, Rect rect, IMeasureContext ctx); /// Draws content. Called after Arrange. public void Render(TView view, IContext ctx); /// Advances time-based state (animations, blinking cursors, etc.). public void Animate(TView view, TimeSpan p, TimeSpan c); /// Handles a pointer event in the given dispatch phase. public void OnPointerEvent(TView view, ref PointerEventRef e, EventPhase phase); /// Handles a key-down event while the host view has focus. public void OnKeyDown(TView view, ref KeyEventRef e); /// Handles a character input event while the host view has focus. public void OnChar(TView view, ref KeyEventRef e); /// Called when the host view gains keyboard focus. public void OnFocus(TView view); /// Called when the host view loses keyboard focus. public void OnBlur(TView view); } /// Three-slot dock layout. Typical usage: Left button | Stretch content | Right button. public struct Dock3 : ILayer where TView : ILayerHost where T1 : struct, ILayer where T2 : struct, ILayer where T3 : struct, ILayer { /// The first docked child. public Docked Child1; /// The second docked child. public Docked Child2; /// The third docked child. public Docked Child3; /// Returns the desired border-edge size given the available space. public Size Measure(TView view, Size available, IMeasureContext ctx); /// Finalises position and size within . public void Arrange(TView view, Rect rect, IMeasureContext ctx); /// Draws content. Called after Arrange. public void Render(TView view, IContext ctx); /// Advances time-based state (animations, blinking cursors, etc.). public void Animate(TView view, TimeSpan p, TimeSpan c); /// Handles a pointer event in the given dispatch phase. public void OnPointerEvent(TView view, ref PointerEventRef e, EventPhase phase); /// Handles a key-down event while the host view has focus. public void OnKeyDown(TView view, ref KeyEventRef e); /// Handles a character input event while the host view has focus. public void OnChar(TView view, ref KeyEventRef e); /// Called when the host view gains keyboard focus. public void OnFocus(TView view); /// Called when the host view loses keyboard focus. public void OnBlur(TView view); } /// Four-slot dock layout. public struct Dock4 : ILayer where TView : ILayerHost where T1 : struct, ILayer where T2 : struct, ILayer where T3 : struct, ILayer where T4 : struct, ILayer { /// The first docked child. public Docked Child1; /// The second docked child. public Docked Child2; /// The third docked child. public Docked Child3; /// The fourth docked child. public Docked Child4; /// Returns the desired border-edge size given the available space. public Size Measure(TView view, Size available, IMeasureContext ctx); /// Finalises position and size within . public void Arrange(TView view, Rect rect, IMeasureContext ctx); /// Draws content. Called after Arrange. public void Render(TView view, IContext ctx); /// Advances time-based state (animations, blinking cursors, etc.). public void Animate(TView view, TimeSpan p, TimeSpan c); /// Handles a pointer event in the given dispatch phase. public void OnPointerEvent(TView view, ref PointerEventRef e, EventPhase phase); /// Handles a key-down event while the host view has focus. public void OnKeyDown(TView view, ref KeyEventRef e); /// Handles a character input event while the host view has focus. public void OnChar(TView view, ref KeyEventRef e); /// Called when the host view gains keyboard focus. public void OnFocus(TView view); /// Called when the host view loses keyboard focus. public void OnBlur(TView view); } } /// /// A variant that switches border color when the host /// view has keyboard focus. All layout and rendering is delegated to an inner /// ; only swaps the color, and /// / request a repaint. /// public struct FocusBorderLayer : ILayer where TView : ILayerHost where TChild : struct, ILayer { /// The inner border layer that owns all geometry and rendering. public BorderLayer Border; /// Border color used when the host view has keyboard focus. public Color FocusedBorderColor; /// Per-side border thickness. public Frame BorderThickness { get; set; } /// Corner radius for the background fill and border stroke. public CornerRadius CornerRadius { get; set; } /// Background fill color. public Color BackgroundColor { get; set; } /// Border stroke color. public Color BorderColor { get; set; } /// Padding between the border edge and the child layer. public Frame Padding { get; set; } /// Returns the desired border-edge size given the available space. public Size Measure(TView view, Size availableSize, IMeasureContext context); /// Finalises position and size within . public void Arrange(TView view, Rect rect, IMeasureContext context); /// Draws content. Called after Arrange. public void Render(TView view, IContext context); /// Advances time-based state (animations, blinking cursors, etc.). public void Animate(TView view, TimeSpan previousTime, TimeSpan currentTime); /// Handles a pointer event in the given dispatch phase. public void OnPointerEvent(TView view, ref PointerEventRef e, EventPhase phase); /// Handles a key-down event while the host view has focus. public void OnKeyDown(TView view, ref KeyEventRef e); /// Handles a character input event while the host view has focus. public void OnChar(TView view, ref KeyEventRef e); /// Called when the host view gains keyboard focus. public void OnFocus(TView view); /// Called when the host view loses keyboard focus. public void OnBlur(TView view); } /// /// A composable struct that handles a portion of a view's layout, rendering, and input. /// Layers are value types composed at compile time — no virtual dispatch, no allocations. /// The host provides resources and invalidation callbacks; /// the layer carries its own state and logic. /// /// /// The host type for this layer. Must implement . /// Almost always ; use a more derived type only when the layer /// needs access to host-specific APIs beyond the contract. /// public interface ILayer where TView : ILayerHost { /// Advances time-based state (animations, blinking cursors, etc.). void Animate(TView view, TimeSpan previousTime, TimeSpan currentTime); /// Returns the desired border-edge size given the available space. Size Measure(TView view, Size availableSize, IMeasureContext context); /// Finalises position and size within . void Arrange(TView view, Rect rect, IMeasureContext context); /// Draws content. Called after Arrange. void Render(TView view, IContext context); /// Handles a pointer event in the given dispatch phase. void OnPointerEvent(TView view, ref PointerEventRef e, EventPhase phase); /// Handles a key-down event while the host view has focus. void OnKeyDown(TView view, ref KeyEventRef e); /// Handles a character input event while the host view has focus. void OnChar(TView view, ref KeyEventRef e); /// Called when the host view gains keyboard focus. void OnFocus(TView view); /// Called when the host view loses keyboard focus. void OnBlur(TView view); } /// /// A that owns a single struct and delegates /// every layout, rendering, and input override to it, passing itself as the fully-typed /// host to every layer method. /// /// Because the compiler resolves statically, all delegation is /// devirtualised and inlined by the JIT — zero overhead compared to writing the overrides by hand. /// Child views: This class is a leaf by default (Count = 0). /// Subclasses that host child instances should override /// and , and manage attachment via . /// Use to bridge those views back into the layer tree. /// /// The concrete view subclass. Must be the class that inherits this. /// Pass when no specific host type is needed. /// The layer struct type. public class LayerView : View where TView : View where TLayer : struct, ILayer { /// The layer struct that owns all layout and rendering logic for this view. protected TLayer Layer; /// Override to animate this view and its children. protected override void AnimateCore(TimeSpan previousTime, TimeSpan currentTime); /// Override to compute the desired border-edge size. protected override Size MeasureCore(Size availableSize, 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); /// /// Called during event dispatch to handle a pointer event in a specific event phase. /// public override void OnPointerEvent(ref PointerEventRef e, EventPhase phase); /// /// Called when a key is pressed while this view has focus. /// public override void OnKeyDown(ref KeyEventRef e); /// /// Called when a character is input while this view has focus. /// public override void OnChar(ref KeyEventRef e); /// /// Called when this view receives keyboard focus. /// protected internal override void OnFocus(); /// /// Called when this view loses keyboard focus. /// protected internal override void OnBlur(); } } namespace Xui.Core.UI.Layer { /// /// Zero-allocation click handler for button layers. /// Implement as a private nested struct inside the owning view so /// receives the fully-typed host and can call any method on it without closures. /// public interface IButtonAction where THost : ILayerHost { /// Executes the button action on the given host view. /// The host view that owns the button. void Execute(THost host); } } namespace Xui.Core.UI.Layer { using Xui.Core.Math2D; using Xui.Core.UI.Input; /// /// The contract a host view must satisfy to be used with . /// Provides the invalidation, focus, pointer-capture, and service-resolution APIs /// that layers call on their host during layout, rendering, and input handling. /// public interface ILayerHost : IServiceProvider { /// The arranged frame of the host view, in parent-local coordinates. Rect Frame { get; } /// Whether the host view currently holds keyboard focus. bool IsFocused { get; } /// Requests keyboard focus for the host view. Returns true if focus was granted. bool Focus(); /// Marks the view as needing re-render. void InvalidateRender(); /// Marks the view as needing re-measure (and re-layout). void InvalidateMeasure(); /// Schedules an animation frame callback via AnimateCore. void RequestAnimationFrame(); /// Routes all subsequent pointer events for to this view. /// The platform-assigned pointer identifier. /// Optional gesture marker (see ) so ancestor containers can negotiate handover. void CapturePointer(int pointerId, IPointerGesture? gesture = null); /// Releases a previously captured pointer. void ReleasePointer(int pointerId); } } namespace Xui.Core.UI.Layer { using System.Buffers; using Xui.Core.Abstract.Events; using Xui.Core.Actual; using Xui.Core.Canvas; using Xui.Core.DI; using Xui.Core.Math1D; using Xui.Core.Math2D; using Xui.Core.UI.Input; /// /// A leaf layer that implements single-line text input: typing, selection, caret blinking, /// password masking, and mouse-driven selection. Shares document state with native text input adapters. /// /// The layer stores the arranged during /// so that and pointer hit-testing both know the exact text area, /// independent of any border or padding applied by a wrapping layer. /// public struct TextInputLayer : ILayer { /// The editing state shared with native adapters. public TextEditingState Editor { get; } /// Whether the platform draws and manipulates the selection. public bool NativeSelection { get; set; } /// Whether the input contains text, without allocating a string. public bool HasText { get; } /// Gets or sets the text content. public string Text { get; set; } /// /// Gets or sets the selection as a half-open interval [Start, End). /// Start == End represents the caret position. /// public Interval.ClosedOpen Selection { get; set; } /// When true, displays bullet characters instead of the actual text. public bool IsPassword { get; set; } /// When true (default), selects all text when the view gains focus. public bool SelectAllOnFocus { get; set; } /// Optional character filter. Return true to accept, false to reject. public Func? InputFilter { get; set; } /// Normal text color. public Color Color { get; set; } /// Color of text inside the selection highlight. public Color SelectedColor { get; set; } /// Background color drawn behind selected text. public Color SelectionBackgroundColor { get; set; } /// Corner radius of the selection highlight rectangle. Zero by default. public CornerRadius SelectionCornerRadius { get; set; } /// Inset applied to the arranged rect before text layout and hit-testing. public Frame Padding { get; set; } /// Font used for input measurement, hit testing, and rendering. public Font Font { get; set; } /// Returns the desired border-edge size given the available space. public Size Measure(View view, Size availableSize, IMeasureContext context); /// Finalises position and size within . public void Arrange(View view, Rect rect, IMeasureContext context); /// Draws content. Called after Arrange. public void Render(View view, IContext context); /// Advances time-based state (animations, blinking cursors, etc.). public void Animate(View view, TimeSpan previousTime, TimeSpan currentTime); /// Handles a pointer event in the given dispatch phase. public void OnPointerEvent(View view, ref PointerEventRef e, EventPhase phase); /// Handles a key-down event while the host view has focus. public void OnKeyDown(View view, ref KeyEventRef e); /// Handles a character input event while the host view has focus. public void OnChar(View view, ref KeyEventRef e); /// Called when the host view gains keyboard focus. public void OnFocus(View view); /// Called when the host view loses keyboard focus. public void OnBlur(View view); /// Returns caret geometry in window coordinates. public Rect GetCaretRect(View view, int offset, ITextMeasureContext measure); /// Hit-tests text using a point in window coordinates. public int GetTextPosition(View view, Point point, ITextMeasureContext measure); } }