kagura_ui

    Backend-agnostic retained UI-tree abstraction for Kagura (UINode, layout constraints, input/render adapters; extracted from kagura_engine)

    Download zip
    Author
    Version
    0.7.2
    License
    Apache-2.0
    Last updated
    2 days ago
    Downloads
    181

    #kagura_ui

    レイアウト、入力イベント、フォーカス、UI snapshotを提供する共通UIモジュールです。

    #ドラッグ&ドロップ

    UIDragController は InputSnapshot からマウス・タッチを取得し、Array[UIEvent] を返します。DOMや描画方式に依存しないため、Canvasのカード、インベントリ、エディタの項目などで使えます。OSのファイルドロップは別のホスト入力として扱います。

    let drag = @ui.UIDragController::new(threshold=8.0)
    // 毎フレーム呼ぶ。sources / targets は描画にも使う LayoutResult の配列。
    let events = drag.update(
    input,
    source_at=fn(x, y) { @ui.hit_test(sources, x, y) },
    target_at=fn(source, x, y) {
    match @ui.hit_test(targets, x, y) {
    Some(target) => if accepts(source, target) { Some(target) } else { None }
    None => None
    }
    },
    )
    for event in events {
    match event {
    @ui.UIEvent::Drag({ phase: @ui.UIDragPhase::Drop, source, target: Some(target), .. }) =>
    apply_drop(source, target)
    _ => ()
    }
    }

    source_at はドラッグできる要素を、target_at は現在の位置で受け入れ可能な対象を返します。対象が重なる場合の優先順位も呼び出し側で決めます。既存の UITree のIDを使うか、UINodeId::new で描画側のIDを渡せます。IDは操作中に安定させ、要素の削除、画面変更、フォーカス喪失では cancel() を呼びます。移動するデータやゲームルールは呼び出し側が管理し、コントローラーは変更しません。

    イベント意味
    Click(source)移動量がしきい値に達する前に離した
    Drag(Start)しきい値に達した。既定は論理座標で8
    Drag(Move)ドラッグ開始または座標の変更
    Drag(Enter / Leave)受け入れ可能な対象への出入り。対象変更はLeave → Enter
    Drag(Drop)離した位置の対象が受け入れ可能
    Drag(Cancel(reason))明示的な取消、入力取消、無効化、対象外へのドロップ
    Drag(End(success))開始済みのドラッグの終了。Dropの後だけtrue

    UIDragEvent は開始位置・現在位置、source、target、pointerを保持する不変の値です。Enter / Leaveのtargetは入った対象 / 離れた対象を示します。Startの後に必ずEndが1回あり、正常終了はDrop → End(true)、取消はCancel → End(false)です。しきい値前の取消はCancelだけを返します。

    snapshot() は表示用の読み取り専用状態を返し、dragging でクリック候補とドラッグを区別できます。離す直前にも対象を再判定するため、対象の移動や受け入れ条件の変更を反映します。

    UIPointerInputAdapter は最初の指を離すまで同じTouch IDを追跡します。他の指やマウスへ操作を引き継がず、マウス操作中に触れた指も無視します。Esc / 右・中央クリックは取消入力になります。座標変換は入力元で済ませてください。enabled=false でも update を毎フレーム呼ぶことで、無効中の入力が再開時に持ち越されません。

    独自のホスト入力では handle_pointer(UIPointerFrame, ...) を使い、press / move / release / cancelを渡せます。pointer() は update が使う入力アダプターのフレームを返します。update の返り値には従来のPointer / Key / Scrollイベントも含まれます。UIEvent を網羅的にmatchしている利用側は、新しいPointerCancel / Click / Dragも扱ってください。

    just ui-dnd-test # JS / nativeの共通UIテストと警告チェック

    #モーダル

    UIModalController は描画・内容を持たず、モーダルのスタック、入力スコープ、フォーカスの制限と復帰を管理します。

    let modals = @ui.UIModalController::new()
    let _ = modals.open(dialog_id, opener=Some(button_id), focusable=[close_id, next_id])
    // モーダルがある間は accepts(dialog_id) のスコープだけへ入力を送る。
    modals.cycle(1) // Tab / 下方向。-1 は Shift+Tab / 上方向。
    let closed = modals.close(@ui.UIModalCloseReason::Cancel)
    // closed.restore_focus を呼び出し側の表示・入力フォーカスに反映する。

    current() はID・フォーカス・操作可能IDのコピーを返します。focus(id) は最上位モーダル内だけを受け入れ、重複IDの open はfalse、空スタックの close はNoneです。入れ子を閉じると親に戻ります。Explicit / Cancel / Backdrop で閉じた理由を区別できます。フォーカス先がないポップアップはそのルートをフォーカスします。

    描画側は背後を暗く描き、背後への入力を止めます。Sceneでは group(ui_hidden=true, children=background) で背後を描画しながらアクティブなUI snapshotから外し、ポップアップのrectに role="dialog" を付けます。WebのCanvasでは、モーダル中のTabのブラウザ既定動作をホスト側で抑止してください。

    #キーボード・コントローラー

    UINavigationInputAdapter.update(input, elapsed_ms=dt) は矢印キー、標準マッピングの十字キー・左スティックを Move(Left / Right / Up / Down) に変換します。Enter / Space / Aは Confirm、Esc / Bは Cancel です。X / Y / LB / RB / Startは Auxiliary(2 / 3 / 4 / 5 / 9) として用途を呼び出し側に渡します。複数接続時はInputSnapshotの最初のコントローラーを使います。

    navigation_input_from_glfw(input) はnativeのGLFWで異なる十字キー・Startなどの番号を共通形式へ変換します。Web入力とヘッドレスの共通形式の入力には適用しません。

    スティックは0.55で方向を取り、0.35より小さくなるまで維持します。方向だけ350ms後から120ms間隔でリピートし、遅れたフレームでも一度に1件まで返します。決定と取消は押した瞬間だけ返します。画面遷移・演出・モーダル中にも毎フレーム更新し、受け付けない入力のエッジも消費してください。

    Scene側で公開版にも残すUI識別子は @scene.ui_key(id, node) で明示します。 key / name / subject は開発用の検査情報で、releaseでは削除されます。 ポップアップの識別やUI snapshotに依存する入力処理には ui_key を使います。

    LayoutEngine

    pub trait LayoutEngine {
    fn compute_layout(Self, root : UINodeId, constraint : LayoutConstraint) -> Array[LayoutResult] raise
    }

    UIInputAdapter

    pub trait UIInputAdapter {
    fn from_input_snapshot(Self, snapshot :
    InputSnapshot
    ) -> Array[UIEvent]
    }

    UIRenderAdapter

    pub trait UIRenderAdapter {
    fn build_draw_commands(Self, frame :
    FrameBudget
    , layouts : Array[LayoutResult], target :
    ImageHandle
    ) -> Array[
    DrawTrianglesCommand
    ] raise
    }

    JsonObjectPublisher

    pub struct JsonObjectPublisher {
    previous : Map[String,
    Json
    ]
    initialized : Bool
    }

    Incremental JSON object transport. Fields are compared structurally; only changed top-level fields are encoded. Owns a deep copy of retained values, so callers may reuse mutable input maps/arrays. Receivers apply full, set and remove atomically; null is a value, not a deletion.

    JsonObjectPublisher::encode

    fn JsonObjectPublisher::encode(self : JsonObjectPublisher, fields : Map[String,
    Json
    ]) -> String?

    First call (including an empty object) sends a full replacement; unchanged subsequent objects return None. reset starts a new receiver session.

    JsonObjectPublisher::new

    JsonObjectPublisher::reset

    fn JsonObjectPublisher::reset(self : JsonObjectPublisher) -> Unit

    LayoutConstraint

    pub struct LayoutConstraint {
    min_width : Double
    min_height : Double
    max_width : Double
    max_height : Double
    } derive(
    Debug
    )

    LayoutConstraint::output

    fn LayoutConstraint::output(self : LayoutConstraint, logger : &Logger) -> Unit

    LayoutConstraint::to_repr

    automatically derived

    LayoutConstraint::to_string

    fn LayoutConstraint::to_string(self : LayoutConstraint) -> String

    Default implementation for Show::to_string, uses a StringBuilder

    LayoutRect

    pub struct LayoutRect {
    x : Double
    y : Double
    width : Double
    height : Double
    } derive(
    Debug
    )

    impl Show for LayoutRect

    LayoutRect::new

    fn LayoutRect::new(x : Double, y : Double, width : Double, height : Double) -> LayoutRect

    LayoutRect::output

    fn LayoutRect::output(self : LayoutRect, logger : &Logger) -> Unit

    LayoutRect::to_repr

    automatically derived

    LayoutRect::to_string

    fn LayoutRect::to_string(self : LayoutRect) -> String

    Default implementation for Show::to_string, uses a StringBuilder

    LayoutResult

    pub struct LayoutResult {
    node_id : UINodeId
    rect : LayoutRect
    } derive(
    Debug
    )

    LayoutResult::output

    fn LayoutResult::output(self : LayoutResult, logger : &Logger) -> Unit

    LayoutResult::to_repr

    automatically derived

    LayoutResult::to_string

    fn LayoutResult::to_string(self : LayoutResult) -> String

    Default implementation for Show::to_string, uses a StringBuilder

    SimpleLayoutEngine

    pub struct SimpleLayoutEngine {
    tree : UITree
    }

    SimpleLayoutEngine::compute_layout

    fn SimpleLayoutEngine::compute_layout(self : SimpleLayoutEngine, root : UINodeId, constraint : LayoutConstraint) -> Array[LayoutResult] raise

    SimpleLayoutEngine::new

    SimpleUIInputAdapter

    pub struct SimpleUIInputAdapter {
    prev_pressed_mouse : Array[Int]
    prev_cursor_x : Double
    prev_cursor_y : Double
    prev_pressed_keys : Array[Int]
    }

    SimpleUIInputAdapter::from_input_snapshot

    SimpleUIInputAdapter::new

    SimpleUIRenderAdapter

    pub struct SimpleUIRenderAdapter {
    shader :
    ShaderHandle

    pipeline_id : Int
    }

    UIAlignment

    pub(all) enum UIAlignment {
    Start
    End
    FlexStart
    FlexEnd
    Center
    SpaceBetween
    SpaceAround
    SpaceEvenly
    Stretch
    Baseline
    } derive(Eq,
    Debug
    )

    impl Show for UIAlignment

    UIAlignment::equal

    fn UIAlignment::equal(UIAlignment, UIAlignment) -> Bool
    automatically derived

    UIAlignment::not_equal

    fn UIAlignment::not_equal(x : UIAlignment, y : UIAlignment) -> Bool
    automatically derived

    UIAlignment::output

    fn UIAlignment::output(self : UIAlignment, logger : &Logger) -> Unit

    UIAlignment::to_repr

    automatically derived

    UIAlignment::to_string

    fn UIAlignment::to_string(self : UIAlignment) -> String

    Default implementation for Show::to_string, uses a StringBuilder

    UIDirection

    pub(all) enum UIDirection {
    Row
    Column
    } derive(
    Debug
    )

    impl Show for UIDirection

    UIDirection::output

    fn UIDirection::output(self : UIDirection, logger : &Logger) -> Unit

    UIDirection::to_repr

    automatically derived

    UIDirection::to_string

    fn UIDirection::to_string(self : UIDirection) -> String

    Default implementation for Show::to_string, uses a StringBuilder

    UIDragCancelReason

    pub(all) enum UIDragCancelReason {
    Explicit
    InputCancelled
    Disabled
    NoTarget
    } derive(Eq,
    Debug
    )

    UIDragCancelReason::equal

    automatically derived

    UIDragCancelReason::not_equal

    automatically derived

    UIDragCancelReason::output

    fn UIDragCancelReason::output(self : UIDragCancelReason, logger : &Logger) -> Unit

    UIDragCancelReason::to_repr

    automatically derived

    UIDragCancelReason::to_string

    fn UIDragCancelReason::to_string(self : UIDragCancelReason) -> String

    Default implementation for Show::to_string, uses a StringBuilder

    UIDragController

    pub struct UIDragController {
    input : UIPointerInputAdapter
    threshold : Double
    gesture : UIDragGesture?
    }

    UIDragController::cancel

    Cancels a pending press or active drag. A started drag always ends once.

    UIDragController::handle_pointer

    fn UIDragController::handle_pointer(self : UIDragController, frame : UIPointerFrame, source_at~ : (Double, Double) -> UINodeId?, target_at~ : (UINodeId, Double, Double) -> UINodeId?, enabled? : Bool) -> Array[UIEvent]

    Recognition is independent from InputSnapshot/host acquisition.

    UIDragController::new

    fn UIDragController::new(threshold? : Double) -> UIDragController

    UIDragController::pointer

    UIDragController::snapshot

    UIDragController::update

    fn UIDragController::update(self : UIDragController, input :
    InputSnapshot
    , source_at~ : (Double, Double) -> UINodeId?, target_at~ : (UINodeId, Double, Double) -> UINodeId?, enabled? : Bool) -> Array[UIEvent]

    UI-only policy: source_at selects a draggable identity; target_at returns the topmost accepting target or None. The caller owns payloads and rules. Edges are consumed even when disabled, avoiding held-input reactivation.

    UIDragEvent

    pub struct UIDragEvent {
    phase : UIDragPhase
    source : UINodeId
    target : UINodeId?
    pointer : UIPointerId
    start_x : Double
    start_y : Double
    x : Double
    y : Double
    } derive(
    Debug
    )

    Immutable event data. Enter/Leave name the entered/left target respectively.

    UIDragEvent::to_repr

    automatically derived

    UIDragGesture

    type UIDragGesture

    UIDragPhase

    pub(all) enum UIDragPhase {
    Start
    Move
    Enter
    Leave
    Drop
    Cancel(UIDragCancelReason)
    End(Bool)
    } derive(Eq,
    Debug
    )

    impl Show for UIDragPhase

    UIDragPhase::equal

    fn UIDragPhase::equal(UIDragPhase, UIDragPhase) -> Bool
    automatically derived

    UIDragPhase::not_equal

    fn UIDragPhase::not_equal(x : UIDragPhase, y : UIDragPhase) -> Bool
    automatically derived

    UIDragPhase::output

    fn UIDragPhase::output(self : UIDragPhase, logger : &Logger) -> Unit

    UIDragPhase::to_repr

    automatically derived

    UIDragPhase::to_string

    fn UIDragPhase::to_string(self : UIDragPhase) -> String

    Default implementation for Show::to_string, uses a StringBuilder

    UIDragSnapshot

    pub struct UIDragSnapshot {
    source : UINodeId
    target : UINodeId?
    pointer : UIPointerId
    start_x : Double
    start_y : Double
    x : Double
    y : Double
    dragging : Bool
    }

    Read-only presentation state; the controller owns the mutable gesture.

    UIEvent

    pub enum UIEvent {
    PointerDown(Double, Double)
    PointerUp(Double, Double)
    PointerMove(Double, Double)
    Scroll(Double, Double)
    KeyDown(Int)
    KeyUp(Int)
    PointerCancel
    Click(UINodeId)
    Drag(UIDragEvent)
    } derive(
    Debug
    )

    impl Show for UIEvent

    UIEvent::output

    fn UIEvent::output(self : UIEvent, logger : &Logger) -> Unit

    UIEvent::to_repr

    automatically derived

    UIEvent::to_string

    fn UIEvent::to_string(self : UIEvent) -> String

    Default implementation for Show::to_string, uses a StringBuilder

    UIFlexWrap

    pub(all) enum UIFlexWrap {
    NoWrap
    Wrap
    } derive(
    Debug
    )

    impl Show for UIFlexWrap

    UIFlexWrap::output

    fn UIFlexWrap::output(self : UIFlexWrap, logger : &Logger) -> Unit

    UIFlexWrap::to_repr

    automatically derived

    UIFlexWrap::to_string

    fn UIFlexWrap::to_string(self : UIFlexWrap) -> String

    Default implementation for Show::to_string, uses a StringBuilder

    UIFocusEvent

    pub(all) enum UIFocusEvent {
    FocusGained(UINodeId)
    FocusLost(UINodeId)
    } derive(
    Debug
    )

    UIFocusEvent::output

    fn UIFocusEvent::output(self : UIFocusEvent, logger : &Logger) -> Unit

    UIFocusEvent::to_repr

    automatically derived

    UIFocusEvent::to_string

    fn UIFocusEvent::to_string(self : UIFocusEvent) -> String

    Default implementation for Show::to_string, uses a StringBuilder

    UIFocusManager

    pub struct UIFocusManager {
    focused : UINodeId?
    focusable_ids : Array[UINodeId]
    }

    UIFocusManager::blur

    Remove focus. Returns blur event if something was focused.

    UIFocusManager::current_focus

    fn UIFocusManager::current_focus(self : UIFocusManager) -> UINodeId?

    UIFocusManager::focus

    Focus a specific node. Returns focus/blur events.

    UIFocusManager::focus_next

    fn UIFocusManager::focus_next(self : UIFocusManager) -> Array[UIFocusEvent]

    Move focus to the next focusable node (tab order).

    UIFocusManager::focus_prev

    fn UIFocusManager::focus_prev(self : UIFocusManager) -> Array[UIFocusEvent]

    Move focus to the previous focusable node (shift-tab order).

    UIFocusManager::handle_pointer_down

    fn UIFocusManager::handle_pointer_down(self : UIFocusManager, layouts : Array[LayoutResult], x : Double, y : Double) -> Array[UIFocusEvent]

    Handle a pointer down event: focus the hit node, or blur if no hit.

    UIFocusManager::new

    UIFocusManager::set_focusable

    fn UIFocusManager::set_focusable(self : UIFocusManager, ids : Array[UINodeId]) -> Unit

    UIInteractionState

    pub struct UIInteractionState {
    available : Bool
    selected : Bool
    drop_target : Bool
    disabled_reason : String?
    } derive(Eq,
    Debug
    )

    Application-owned availability, shared by presentation, input and snapshots. Selected / drop-target styling cannot make an unavailable action operable.

    UIInteractionState::equal

    automatically derived

    UIInteractionState::new

    fn UIInteractionState::new(available? : Bool, selected? : Bool, drop_target? : Bool, disabled_reason? : String?) -> UIInteractionState

    UIInteractionState::not_equal

    automatically derived

    UIInteractionState::to_repr

    automatically derived

    UIModalCloseReason

    pub(all) enum UIModalCloseReason {
    Explicit
    Cancel
    Backdrop
    } derive(Eq,
    Debug
    )

    Rendering and payloads belong to the caller. This controller owns the modal stack, input scope, focus trap and the focus to restore on dismissal.

    UIModalCloseReason::equal

    automatically derived

    UIModalCloseReason::not_equal

    automatically derived

    UIModalCloseReason::to_repr

    automatically derived

    UIModalClosed

    pub struct UIModalClosed {
    id : UINodeId
    reason : UIModalCloseReason
    restore_focus : UINodeId?
    }

    UIModalController

    pub struct UIModalController {
    // private fields
    }

    UIModalController::accepts

    fn UIModalController::accepts(self : UIModalController, id : UINodeId) -> Bool

    Only the top modal may receive input; background and parent dialogs are inert.

    UIModalController::close

    UIModalController::current

    UIModalController::cycle

    fn UIModalController::cycle(self : UIModalController, direction : Int) -> Unit

    UIModalController::focus

    fn UIModalController::focus(self : UIModalController, id : UINodeId) -> Bool

    UIModalController::new

    UIModalController::open

    fn UIModalController::open(self : UIModalController, id : UINodeId, opener? : UINodeId?, focusable? : Array[UINodeId]) -> Bool

    Duplicate modal identities are rejected. Empty dialogs focus their root.

    UIModalLayer

    pub struct UIModalLayer {
    // private fields
    }

    Modal input and focus integration, independent of any renderer or game clock.

    UIModalLayer::accepts

    fn UIModalLayer::accepts(self : UIModalLayer, id : UINodeId) -> Bool

    UIModalLayer::close

    UIModalLayer::current

    fn UIModalLayer::current(self : UIModalLayer) -> UIModalSnapshot?

    UIModalLayer::current_focus

    fn UIModalLayer::current_focus(self : UIModalLayer) -> UINodeId?

    UIModalLayer::cycle

    fn UIModalLayer::cycle(self : UIModalLayer, direction : Int) -> Unit

    UIModalLayer::drain_events

    fn UIModalLayer::drain_events(self : UIModalLayer) -> Array[UIEvent]

    Opening / closing a modal defers drag cancellation events to the next input update, or callers can consume them immediately. Each event is returned once.

    UIModalLayer::focus

    fn UIModalLayer::focus(self : UIModalLayer, id : UINodeId) -> Bool

    UIModalLayer::handle_pointer

    fn UIModalLayer::handle_pointer(self : UIModalLayer, frame : UIPointerFrame, source_at~ : (Double, Double) -> UINodeId?, target_at~ : (UINodeId, Double, Double) -> UINodeId?) -> Array[UIEvent]

    UIModalLayer::interaction

    fn UIModalLayer::interaction(self : UIModalLayer, id : UINodeId, state : UIInteractionState) -> UIInteractionState

    UIModalLayer::new

    UIModalLayer::open

    fn UIModalLayer::open(self : UIModalLayer, id : UINodeId, opener? : UINodeId?, focusable? : Array[UINodeId], backdrop? : UINodeId?) -> Bool

    UIModalLayer::update

    fn UIModalLayer::update(self : UIModalLayer, input :
    InputSnapshot
    , source_at~ : (Double, Double) -> UINodeId?, target_at~ : (UINodeId, Double, Double) -> UINodeId?) -> Array[UIEvent]

    UIModalSnapshot

    pub struct UIModalSnapshot {
    id : UINodeId
    focused : UINodeId
    focusable : Array[UINodeId]
    }

    UINavigationDirection

    pub(all) enum UINavigationDirection {
    Left
    Right
    Up
    Down
    } derive(Eq,
    Debug
    )

    UINavigationDirection::equal

    automatically derived

    UINavigationDirection::not_equal

    automatically derived

    UINavigationDirection::to_repr

    automatically derived

    UINavigationEvent

    pub(all) enum UINavigationEvent {
    Move(UINavigationDirection)
    Confirm
    Cancel
    Auxiliary(Int)
    } derive(Eq,
    Debug
    )

    Standard gamepad mapping: A confirms, B cancels; X/Y/LB/RB/Start remain application-owned auxiliary actions. Arrow keys use the same contract.

    UINavigationEvent::equal

    automatically derived

    UINavigationEvent::not_equal

    fn UINavigationEvent::not_equal(x : UINavigationEvent, y : UINavigationEvent) -> Bool
    automatically derived

    UINavigationEvent::to_repr

    automatically derived

    UINavigationInputAdapter

    pub struct UINavigationInputAdapter {
    // private fields
    }

    UINavigationInputAdapter::new

    UINavigationInputAdapter::update

    Held directions repeat after 350 ms, then every 120 ms. At most one repeat per update prevents delayed/background frames from skipping many controls.

    UINode

    pub struct UINode {
    id : UINodeId
    style : UINodeStyle
    children : Array[UINodeId]
    } derive(
    Debug
    )

    impl Show for UINode

    UINode::output

    fn UINode::output(self : UINode, logger : &Logger) -> Unit

    UINode::to_repr

    automatically derived

    UINode::to_string

    fn UINode::to_string(self : UINode) -> String

    Default implementation for Show::to_string, uses a StringBuilder

    UINodeId

    pub struct UINodeId {
    value : Int
    } derive(Eq,
    Debug
    )

    impl Show for UINodeId

    UINodeId::equal

    fn UINodeId::equal(UINodeId, UINodeId) -> Bool
    automatically derived

    UINodeId::new

    fn UINodeId::new(value : Int) -> UINodeId

    Construct an application-owned identity when a UI is not backed by UITree.

    UINodeId::not_equal

    fn UINodeId::not_equal(x : UINodeId, y : UINodeId) -> Bool
    automatically derived

    UINodeId::output

    fn UINodeId::output(self : UINodeId, logger : &Logger) -> Unit

    UINodeId::to_repr

    automatically derived

    UINodeId::to_string

    fn UINodeId::to_string(self : UINodeId) -> String

    Default implementation for Show::to_string, uses a StringBuilder

    UINodeStyle

    pub(all) struct UINodeStyle {
    direction : UIDirection
    width : UISizing
    height : UISizing
    padding_left : Double
    padding_right : Double
    padding_top : Double
    padding_bottom : Double
    gap : Double
    align : UIAlignment
    justify_content : UIAlignment
    flex_wrap : UIFlexWrap
    } derive(
    Debug
    )

    impl Show for UINodeStyle

    UINodeStyle::output

    fn UINodeStyle::output(self : UINodeStyle, logger : &Logger) -> Unit

    UINodeStyle::to_repr

    automatically derived

    UINodeStyle::to_string

    fn UINodeStyle::to_string(self : UINodeStyle) -> String

    Default implementation for Show::to_string, uses a StringBuilder

    UIPointerFrame

    pub struct UIPointerFrame {
    pointer : UIPointerId
    x : Double
    y : Double
    pressed : Bool
    released : Bool
    down : Bool
    cancelled : Bool
    }

    One normalized primary pointer, in the caller's logical coordinate space. Touch release retains the owned finger's final sampled position.

    UIPointerFrame::new

    fn UIPointerFrame::new(pointer : UIPointerId, x : Double, y : Double, pressed? : Bool, released? : Bool, down? : Bool, cancelled? : Bool) -> UIPointerFrame

    Host adapters may supply normalized pointer frames directly.

    UIPointerId

    pub(all) enum UIPointerId {
    Mouse
    Touch(Int)
    } derive(Eq,
    Debug
    )

    impl Show for UIPointerId

    UIPointerId::equal

    fn UIPointerId::equal(UIPointerId, UIPointerId) -> Bool
    automatically derived

    UIPointerId::not_equal

    fn UIPointerId::not_equal(x : UIPointerId, y : UIPointerId) -> Bool
    automatically derived

    UIPointerId::output

    fn UIPointerId::output(self : UIPointerId, logger : &Logger) -> Unit

    UIPointerId::to_repr

    automatically derived

    UIPointerId::to_string

    fn UIPointerId::to_string(self : UIPointerId) -> String

    Default implementation for Show::to_string, uses a StringBuilder

    UIPointerInputAdapter

    Normalize mouse and touch once; retain one finger until its release. Does not query a DOM, scale coordinates, or depend on a game input helper.

    UIPointerInputAdapter::from_input_snapshot

    UIPointerInputAdapter::new

    UIPointerInputAdapter::pointer

    UISafeArea

    pub(all) struct UISafeArea {
    top : Double
    right : Double
    bottom : Double
    left : Double
    } derive(
    Debug
    )

    impl Show for UISafeArea

    UISafeArea::output

    fn UISafeArea::output(self : UISafeArea, logger : &Logger) -> Unit

    UISafeArea::to_repr

    automatically derived

    UISafeArea::to_string

    fn UISafeArea::to_string(self : UISafeArea) -> String

    Default implementation for Show::to_string, uses a StringBuilder

    UISizing

    pub(all) enum UISizing {
    Fixed(Double)
    Percent(Double)
    Auto
    } derive(
    Debug
    )

    impl Show for UISizing

    UISizing::output

    fn UISizing::output(self : UISizing, logger : &Logger) -> Unit

    UISizing::to_repr

    automatically derived

    UISizing::to_string

    fn UISizing::to_string(self : UISizing) -> String

    Default implementation for Show::to_string, uses a StringBuilder

    UISnapshot

    pub(all) struct UISnapshot {
    screen_width : Double
    screen_height : Double
    dpr : Double
    safe_area : UISafeArea
    frame : Int
    state : String
    nodes : Array[UISnapshotNode]
    focus_order : Array[String]
    } derive(
    Debug
    )

    impl Show for UISnapshot

    UISnapshot::hit_test

    fn UISnapshot::hit_test(self : UISnapshot, x : Double, y : Double, drop_only? : Bool) -> UISnapshotNode?

    Read only explicitly annotated actions, in paint order. Unavailable actions occlude actions behind them; decorative labels do not intercept input.

    UISnapshot::output

    fn UISnapshot::output(self : UISnapshot, logger : &Logger) -> Unit

    UISnapshot::to_json

    fn UISnapshot::to_json(self : UISnapshot) -> String

    Serialize the snapshot to the introspection JSON.

    Each node carries both role and a tag alias holding the same value, so the document is directly consumable as a vlmkit --elements-json payload (which requires tag) without a conversion step.

    UISnapshot::to_repr

    automatically derived

    UISnapshot::to_string

    fn UISnapshot::to_string(self : UISnapshot) -> String

    Default implementation for Show::to_string, uses a StringBuilder

    UISnapshotNode

    pub(all) struct UISnapshotNode {
    path : String
    id : String
    role : String
    classes : String
    left : Double
    top : Double
    width : Double
    height : Double
    z : Int
    visible : Bool
    clip : UISnapshotRect?
    text : String?
    text_measured : UITextMetrics?
    focusable : Bool
    focus_index : Int
    focused : Bool
    hit : UISnapshotRect?
    interaction : UIInteractionState?
    } derive(
    Debug
    )

    One node of a UI snapshot.

    path is a stable structural address (hud[0]>bar[1]); id and classes are the author-supplied names the tooling reports defects against. clip is the effective scissor rect at draw time, hit the rect the pointer is actually tested against (they diverge when a widget's hit box drifts from what is drawn).

    UISnapshotNode::output

    fn UISnapshotNode::output(self : UISnapshotNode, logger : &Logger) -> Unit

    UISnapshotNode::to_repr

    automatically derived

    UISnapshotNode::to_string

    fn UISnapshotNode::to_string(self : UISnapshotNode) -> String

    Default implementation for Show::to_string, uses a StringBuilder

    UISnapshotRect

    pub(all) struct UISnapshotRect {
    left : Double
    top : Double
    width : Double
    height : Double
    } derive(
    Debug
    )

    UISnapshotRect::output

    fn UISnapshotRect::output(self : UISnapshotRect, logger : &Logger) -> Unit

    UISnapshotRect::to_repr

    automatically derived

    UISnapshotRect::to_string

    fn UISnapshotRect::to_string(self : UISnapshotRect) -> String

    Default implementation for Show::to_string, uses a StringBuilder

    UITextMetrics

    pub(all) struct UITextMetrics {
    width : Double
    height : Double
    } derive(
    Debug
    )

    Measured extent of a node's text, as reported by @text.TextRenderer::measure. Compared against the node rect to detect overflow the renderer will clip.

    UITextMetrics::output

    fn UITextMetrics::output(self : UITextMetrics, logger : &Logger) -> Unit

    UITextMetrics::to_repr

    automatically derived

    UITextMetrics::to_string

    fn UITextMetrics::to_string(self : UITextMetrics) -> String

    Default implementation for Show::to_string, uses a StringBuilder

    UITree

    pub struct UITree {
    nodes : Map[Int, UINode]
    next_id : Int
    }

    UITree::add_node

    fn UITree::add_node(self : UITree, style : UINodeStyle, children : Array[UINodeId]) -> UINodeId

    UITree::get_node

    fn UITree::get_node(self : UITree, id : UINodeId) -> UINode?

    UITree::new

    fn UITree::new() -> UITree

    UITree::node_count

    fn UITree::node_count(self : UITree) -> Int

    default_layout_constraint

    fn default_layout_constraint(width : Double, height : Double) -> LayoutConstraint

    default_node_style

    fn default_node_style() -> UINodeStyle

    default_ui_snapshot

    fn default_ui_snapshot(screen_width~ : Double, screen_height~ : Double) -> UISnapshot

    default_ui_snapshot_node

    fn default_ui_snapshot_node() -> UISnapshotNode

    A node with every optional field cleared. Fill in with struct update syntax: { ..default_ui_snapshot_node(), path: "hud[0]", id: "hud", width: 640.0 }

    hit_test

    fn hit_test(layouts : Array[LayoutResult], x : Double, y : Double) -> UINodeId?

    Find the topmost node that contains the given point.

    LayoutResult carries no z, so the array order is the only ordering there is, and compute_layout emits post-order: every child before the container that holds it, the root last. The innermost node containing the point is therefore the first match, and the last match is always the outermost container -- for a full-screen root, every on-screen point.

    This used to take the last match, which meant that feeding compute_layout's own output straight into hit_test returned the root background for every point on screen. The regression test at the bottom of contracts_wbtest.mbt pins the two halves together.

    hit_test_all

    fn hit_test_all(layouts : Array[LayoutResult], x : Double, y : Double) -> Array[UINodeId]

    Every node containing the point, innermost first -- the same order hit_test picks its answer from. A caller looking for "the deepest node that is focusable" takes the first match it likes.

    hit_test_interactive

    fn hit_test_interactive(layouts : Array[LayoutResult], x : Double, y : Double, state_for : (UINodeId) -> UIInteractionState, drop_only? : Bool) -> UINodeId?

    A disabled child consumes its hit area instead of clicking through to a parent.

    GLFW uses different indices for Back, Start, Guide, thumb and D-pad buttons. Convert at the host boundary; update() takes standard UI indices. Axes 0/1 are the left stick in both contracts.

    point_in_rect

    fn point_in_rect(rect : LayoutRect, x : Double, y : Double) -> Bool

    ui_events_from_input_edge

    fn ui_events_from_input_edge(key_state :
    KeyInputState
    , mouse_state :
    MouseButtonInputState
    , cursor_x : Double, cursor_y : Double) -> Array[UIEvent]

    Convert inpututil edge state to UIEvents for the current frame. Uses just-pressed/just-released from the edge detection to generate PointerDown/Up and KeyDown/Up events.

    ui_snapshot_nodes_from_layouts

    fn ui_snapshot_nodes_from_layouts(layouts : Array[LayoutResult]) -> Array[UISnapshotNode]

    Derive snapshot nodes straight from layout results.

    This is the zero-effort path: it carries geometry only, which is enough for offscreen / zero-size / overlap detection and for --elements-json attribution. Text and focus metadata have to come from the caller, which is the only place that knows a node's role.