// 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.Input
{
///
/// Defines the phase of event delivery through the view hierarchy.
///
public enum EventPhase
{
///
/// Event is tunneling from the root down toward the target view.
///
Tunnel,
///
/// Event is bubbling from the target view up toward the root.
///
Bubble
}
///
/// A capturing view declares when it is consuming pointer
/// motion as ongoing input (e.g. a color wheel, a slider thumb, a drawing
/// canvas). Ancestor scroll views and similar containers must not steal
/// capture while an gesture is active.
///
public interface IDrag : IPointerGesture
{
}
///
/// A horizontal-axis drag that is willing to yield capture to a vertical-axis
/// ancestor whose drag intent appears stronger. Used by horizontal scroll views
/// nested inside vertical ones: the inner scrolls horizontally from the first
/// pointer move, but if the user's motion is dominantly vertical when crossing
/// the recognition threshold, the outer scroll view steals capture.
///
///
/// The capturing view is expected to "promote" itself by re-capturing with a
/// plain (e.g. ) once
/// horizontal motion has clearly committed to its axis (typical threshold:
/// 20pt of horizontal travel). After promotion, vertical ancestors can no
/// longer steal capture for this pointer.
///
public interface IDragHorizontalTentative : IDrag
{
}
///
/// A vertical drag willing to yield to a horizontal ancestor until its direction
/// commits. Promote to once vertical intent is clear.
///
public interface IDragVerticalTentative : IDrag
{
}
///
/// Marker interface attached to a captured pointer to describe what kind of
/// gesture the capturing view is performing. Ancestor views can inspect this
/// (via ) to negotiate handover —
/// for example a ScrollView will steal an after a
/// drag threshold but stand down for an .
///
public interface IPointerGesture
{
}
///
/// A capturing view declares when it is tracking a press
/// that may or may not become a tap (e.g. Button, Checkbox).
/// An ancestor that wants the pointer for a drag may steal capture after its
/// own threshold is exceeded.
///
public interface ITap : IPointerGesture
{
}
///
/// Defines the mouse or pointer button associated with a pointer event, based on the W3C Pointer Events specification.
///
public enum PointerButton : short
{
///
/// No button or touch/pen contact change occurred (-1).
///
None = -1,
///
/// Left mouse button, touch contact, or pen contact (0).
///
Left = 0,
///
/// Middle mouse button (usually the scroll wheel button) (1).
///
Middle = 1,
///
/// Right mouse button or pen barrel button (2).
///
Right = 2,
///
/// X1 (back) mouse button (3).
///
X1 = 3,
///
/// X2 (forward) mouse button (4).
///
X2 = 4,
///
/// Pen eraser button (5).
///
Eraser = 5,
}
///
/// Defines the set of mouse or pointer buttons currently pressed, based on the W3C Pointer Events specification.
///
[Flags]
public enum PointerButtons : short
{
///
/// No buttons are currently pressed.
///
None = 0,
///
/// Left mouse button, touch contact, or pen contact.
///
Left = 1 << 0,
///
/// Right mouse button or pen barrel button.
///
Right = 1 << 1,
///
/// Middle mouse button.
///
Middle = 1 << 2,
///
/// X1 (back) mouse button.
///
X1 = 1 << 3,
///
/// X2 (forward) mouse button.
///
X2 = 1 << 4,
///
/// Pen eraser button.
///
Eraser = 1 << 5,
}
///
/// Defines the type of action associated with a pointer event, based on the W3C Pointer Events specification.
///
public enum PointerEventType
{
///
/// The pointer has moved onto the element's hit region.
/// Corresponds to the "pointerover" event.
///
Over,
///
/// The pointer has entered the element or one of its descendants.
/// Corresponds to the "pointerenter" event.
///
Enter,
///
/// A pointer button has been pressed.
/// Corresponds to the "pointerdown" event.
///
Down,
///
/// The pointer has moved while being active.
/// Corresponds to the "pointermove" event.
///
Move,
///
/// A pointer button has been released.
/// Corresponds to the "pointerup" event.
///
Up,
///
/// The pointer input was canceled by the system.
/// Corresponds to the "pointercancel" event.
///
Cancel,
///
/// The pointer has moved off of the element's hit region.
/// Corresponds to the "pointerout" event.
///
Out,
///
/// The pointer has left the element and all its descendants.
/// Corresponds to the "pointerleave" event.
///
Leave,
///
/// The pointer has been captured by the element.
/// Corresponds to the "gotpointercapture" event.
///
GotCapture,
///
/// The pointer capture has been released from the element.
/// Corresponds to the "lostpointercapture" event.
///
LostCapture,
}
///
/// Singleton gesture markers used by simple widgets when capturing a pointer.
/// Reusing these avoids per-event heap allocation. Widgets that need to carry
/// extra state can implement on their own type
/// and pass an instance to CapturePointer instead.
///
public static class PointerGestures
{
/// Generic tap (e.g. Button, Checkbox) — may be stolen by an ancestor drag.
public static ITap Tap { get; }
/// Generic drag (e.g. color wheel, slider thumb) — ancestors must not steal.
public static IDrag Drag { get; }
///
/// A horizontal-axis drag that is tentatively willing to yield to a vertical-axis
/// ancestor (see ). Replace with
/// once horizontal motion has firmly committed.
///
public static IDragHorizontalTentative DragHorizontalTentative { get; }
/// A vertical drag that can yield to a horizontal ancestor before committing.
public static IDragVerticalTentative DragVerticalTentative { get; }
}
///
/// Defines the type of input device associated with a pointer event.
///
public enum PointerType
{
///
/// A mouse device generated the pointer event.
///
Mouse,
///
/// A touch contact (e.g., finger or capacitive touch) generated the pointer event.
///
Touch,
///
/// A pen, stylus, or similar fine-point device generated the pointer event.
///
Pen,
///
/// The pointer device type could not be determined.
///
Unknown,
}
/// An editing action from a software keyboard or its navigation controls.
public enum TextInputAction
{
/// Use the field's configured action; otherwise finish editing.
Default,
/// Focus the preceding text input, without wrapping.
Previous,
/// Focus the next control, or finish editing at the end.
Next,
/// Finish editing and release keyboard focus.
Done,
}
/// Semantic hints for platform suggestions and autofill.
public enum TextInputContentType
{
/// No specific semantic hint.
None,
/// A person's name.
Name,
/// An existing password. Masking is controlled separately by IsPassword.
Password,
}
/// Keyboard layout hint. Character validation remains the editor's responsibility.
public enum TextInputKeyboard
{
/// Ordinary text in the user's language.
Text,
/// ASCII letters, numbers and punctuation, for values such as hex colors.
Ascii,
/// Digits.
Number,
/// Digits and a decimal separator.
Decimal,
}
///
/// Platform-independent keyboard hints, read when a field receives focus.
/// These do not restrict pasted, dictated, or hardware-keyboard input; use InputFilter for validation.
///
public readonly record struct TextInputOptions(TextInputKeyboard Keyboard = TextInputKeyboard.Text, TextInputContentType ContentType = TextInputContentType.None, TextInputAction ReturnAction = TextInputAction.Default);
}
namespace Xui.Core.UI.Input
{
using Xui.Core.Abstract.Events;
using Xui.Core.Math2D;
///
/// Routes pointer, mouse, scroll, and touch events through the view tree,
/// performing hit testing, pointer capture, and enter/leave tracking.
///
public class EventRouter
{
/// Initializes a new rooted at the given view.
/// The root of the view tree to route events through.
public EventRouter(View rootView);
/// Dispatches a touch event, translating each touch point into a pointer event.
public void Dispatch(ref TouchEventRef touchEvent);
/// Dispatches a mouse button down event as a pointer down event.
public void Dispatch(ref MouseDownEventRef e);
/// Dispatches a mouse button up event as a pointer up event.
public void Dispatch(ref MouseUpEventRef e);
/// Dispatches a mouse move event as a pointer move event.
public void Dispatch(ref MouseMoveEventRef e);
/// Captures all subsequent pointer events for the given pointer ID to .
/// The view that will exclusively receive events for this pointer.
/// The pointer identifier to capture.
///
/// Optional marker describing what kind of gesture the view is tracking
/// (, , …). Ancestor views can read this
/// via to decide whether to steal capture.
///
public void CapturePointer(View view, int pointerId, IPointerGesture? gesture = null);
/// Releases pointer capture previously set by .
/// The view that currently holds the capture.
/// The pointer identifier to release.
public void ReleasePointer(View view, int pointerId);
///
/// Returns the gesture marker associated with the current capture for
/// , or null if the pointer is not
/// captured or was captured without a gesture marker.
///
public IPointerGesture? GetCapturedGesture(int pointerId);
///
/// Returns the view currently holding pointer capture for
/// , or null if the pointer is not captured.
///
public View? GetCapturedView(int pointerId);
///
/// Dispatches a scroll wheel event to the deepest view under
/// that handles it, bubbling up until is set.
///
public void Dispatch(ref ScrollWheelEventRef e, Point position);
/// Routes magnification to the innermost view under the anchor, then its ancestors.
public void Dispatch(ref ZoomEventRef e, Point position);
}
}
namespace Xui.Core.UI.Input
{
using Xui.Core.Canvas;
///
/// Represents a reference to a pointer event routed to a view, containing identification and pointer state information.
///
public ref struct PointerEventRef
{
///
/// Up to eight handlers pushed earlier during this event's down tunnel,
/// oldest first. Storage is shared by the routed event copies and exists
/// only for this dispatch; do not retain this span across events.
///
public readonly ReadOnlySpan PotentialGestures { get; }
///
/// Advertises a possible gesture without capturing the pointer. Call during
/// Down/Tunnel so descendants can adapt feedback while recognition is pending.
/// When full, drops the oldest handler and retains the newest eight.
/// This does not change capture or the handler's recognition rules.
///
public readonly void PushPotentialGesture(View handler, IPointerGesture gesture);
///
/// Gets the type of pointer event (e.g., Down, Move, Up, Enter, Leave).
///
public readonly PointerEventType Type;
///
/// Gets the unique ID of the pointer. Used to distinguish different active pointers (e.g., different fingers or pen tips).
///
public readonly int PointerId;
///
/// Gets the persistent device ID, if known. Identifies the underlying hardware across multiple pointer sessions.
///
public readonly long PersistentDeviceId;
///
/// Gets a value indicating whether this pointer is the primary pointer in a multi-pointer interaction (e.g., first touch).
///
public readonly bool IsPrimary;
///
/// Gets the current physical state of the pointer (position, pressure, tilt, etc.).
///
public readonly PointerState State;
///
/// Gets high-frequency coalesced samples recorded between the last and current events.
///
public readonly ReadOnlySpan CoalescedStates;
///
/// Gets future-predicted samples estimated from the current pointer movement.
///
public readonly ReadOnlySpan PredictedStates;
///
/// Optional text measure context for hit-testing text positions.
/// May be null on platforms that do not provide one.
///
public readonly ITextMeasureContext? TextMeasure;
///
/// Initializes a new instance of the struct.
///
public PointerEventRef(PointerEventType type, int pointerId, long persistentDeviceId, bool isPrimary, PointerState state, ReadOnlySpan coalescedStates, ReadOnlySpan predictedStates, ITextMeasureContext? textMeasure = null);
}
}
namespace Xui.Core.UI.Input
{
using System.Runtime.CompilerServices;
/// A handler advertising a possible gesture during pointer-down tunneling.
/// The view which may later claim capture.
/// The gesture it may recognize.
public readonly record struct PointerGestureCandidate(View Handler, IPointerGesture Gesture);
}
namespace Xui.Core.UI.Input
{
using Xui.Core.Math2D;
///
/// Describes the physical state of a pointer at a specific moment in time, including position, pressure, tilt, and button information.
///
public readonly struct PointerState
{
///
/// Gets the position of the pointer in global (window) coordinates.
///
public readonly Point Position;
///
/// Gets the size of the pointer's contact geometry, such as the area covered by a finger or stylus tip.
///
public readonly Size ContactSize;
///
/// Gets the normalized pressure applied by the pointer (range: 0.0 to 1.0).
///
public readonly nfloat Pressure;
/// Whether Pressure is a device measurement rather than a synthesized button value.
public readonly bool HasPressure;
///
/// Gets the normalized tangential (barrel) pressure applied by the pointer (range: -1.0 to 1.0).
///
public readonly nfloat TangentialPressure;
///
/// Gets the tilt of the pointer relative to the X and Y axes (in degrees).
///
public readonly Vector Tilt;
///
/// Gets the clockwise twist (rotation) of the pointer around its major axis, in degrees (0.0 to 359.9).
///
public readonly nfloat Twist;
///
/// Gets the altitude angle of the pointer relative to the surface (0 = horizontal, π/2 = vertical), in radians.
///
public readonly nfloat AltitudeAngle;
///
/// Gets the azimuth angle (compass direction) of the pointer around the vertical axis, in radians.
///
public readonly nfloat AzimuthAngle;
///
/// Gets the type of device generating the pointer input (mouse, touch, pen, etc.).
///
public readonly PointerType PointerType;
///
/// Gets which button was responsible for triggering this pointer state change (left, right, middle, eraser, etc.).
///
public readonly PointerButton Button;
///
/// Gets the set of all currently pressed buttons on the device.
///
public readonly PointerButtons Buttons;
///
/// Initializes a new instance of the struct.
///
/// The global position of the pointer.
/// The size of the contact area.
/// The normalized pressure applied.
/// The normalized tangential (barrel) pressure applied.
/// The tilt vector of the pointer.
/// The clockwise twist rotation of the pointer.
/// The altitude angle relative to the surface.
/// The azimuth angle (compass direction).
/// The type of input device.
/// The button that triggered the event.
/// The set of currently pressed buttons.
/// Whether the source supplies real pressure measurements.
public PointerState(Point position, Size contactSize, nfloat pressure, nfloat tangentialPressure, Vector tilt, nfloat twist, nfloat altitudeAngle, nfloat azimuthAngle, PointerType pointerType, PointerButton button, PointerButtons buttons, bool hasPressure = false);
/// Returns this state with a coordinate-space-specific position.
public PointerState WithPosition(Point position);
}
}
namespace Xui.Core.UI.Input
{
using System.Globalization;
/// Changes reported before and after a text editing transaction.
[Flags]
public enum TextEditingChange
{
/// The document or marked text changed.
Text = 1,
/// The insertion point or selected range changed.
Selection = 2,
}
///
/// Single-line editing state shared by canvas text views and native input adapters.
/// Offsets use UTF-16; selection and deletion respect Unicode grapheme boundaries.
///
public sealed class TextEditingState
{
/// Raised before an editing transaction, while old state is still readable.
public event Action? Changing;
/// Raised after an editing transaction.
public event Action? Changed;
/// Optional validation for committed input; composition is validated when committed.
public Func? InputFilter { get; set; }
/// The document. Assignment ends composition and places the caret at the end.
public string Text { get; set; }
/// The normalized selection. Assignments are clamped to the document and grapheme boundaries.
public TextRange Selection { get; set; }
/// The provisional IME composition range, or null.
public TextRange? MarkedRange { get; }
/// Finds the grapheme boundary at or before an offset.
public int Boundary(int offset);
/// Finds the previous grapheme boundary.
public int Previous(int offset);
/// Finds the next grapheme boundary.
public int Next(int offset);
/// Normalizes a range, expanding a nonempty range to whole graphemes.
public TextRange Normalize(TextRange range);
/// Replaces the selection (or composition) atomically with committed input.
public bool Insert(string value);
/// Replaces a range with validated single-line input.
public bool Replace(TextRange range, string value);
/// Deletes the selection or the grapheme before the caret.
public void DeleteBackward();
/// Deletes the selection or the grapheme after the caret.
public void DeleteForward();
/// Updates provisional IME text; the selection is relative to the marked text.
public void SetMarkedText(string value, TextRange relativeSelection);
/// Commits composition, or restores the pre-composition document if validation fails.
public void UnmarkText();
}
/// A UTF-16 range in a text document, with an exclusive end.
public readonly record struct TextRange(int Start, int End)
{
/// The number of UTF-16 code units in the range.
public int Length { get; }
}
}
namespace Xui.Core.UI.Input
{
using Xui.Core.DI;
/// Shared focus behavior for single-line editors and native keyboard actions.
public static class TextInputNavigation
{
/// Whether an action is available for the currently focused editor.
public static bool CanPerform(View view, TextInputAction action);
/// Moves through focus order without wrapping, or dismisses the keyboard.
public static void Perform(View view, TextInputAction action);
}
}