package miaou-core

  1. Overview
  2. Docs
On This Page
  1. Nested scopes
Legend:
Page
Library
Module
Module type
Parameter
Class
Class type
Source

Module Miaou_internals.Focus_ringSource

Named-slot focus ring with nested scope support.

A Focus_ring.t manages a flat ring of named slots with Tab/Shift+Tab cycling, named lookup, and per-slot enable/disable.

A Focus_ring.scope adds parent/child nesting: Tab stays within the active scope, Enter drills into a child scope, and Esc exits back to the parent.

(* Flat ring *)
let ring = Focus_ring.create ["search"; "filter"; "tree"] in
let focused = Focus_ring.is_focused ring "search" in
let ring, _ = Focus_ring.on_key ring ~key:"Tab" in
...

(* Nested scopes *)
let parent = Focus_ring.create ["sidebar"; "main"] in
let sidebar = Focus_ring.create ["search"; "filter"] in
let main = Focus_ring.create ["editor"; "preview"] in
let sc = Focus_ring.scope ~parent
  ~children:[("sidebar", sidebar); ("main", main)] in
let sc, _ = Focus_ring.on_scope_key sc ~key:"Enter" in
(* Now inside the sidebar child ring *)
Sourcetype t
Sourcetype slot = {
  1. id : string;
    (*

    Unique name within the ring.

    *)
  2. focusable : bool;
    (*

    Whether this slot participates in Tab cycling.

    *)
}

A single focusable slot.

Sourceval create : string list -> t

Create a focus ring from a list of slot IDs (all focusable by default).

Sourceval create_slots : slot list -> t

Create from explicit slot definitions.

Sourceval current : t -> string option

Current focused slot ID (None if empty or all disabled).

Sourceval current_index : t -> int option

Current focused index (None if empty or all disabled).

Sourceval is_focused : t -> string -> bool

Is the given slot ID currently focused? Useful in view functions.

Sourceval move : t -> [ `Next | `Prev ] -> t

Move focus forward or backward among focusable slots. Wraps around.

Sourceval on_key : t -> key:string -> t * Miaou_interfaces.Key_event.result

Handle Tab/Shift+Tab. Returns Key_event.Handled if consumed, Key_event.Bubble if the key should propagate.

Sourceval handle_key : t -> key:string -> t * [ `Handled | `Bubble ]
  • deprecated

    Use on_key instead. Returns polymorphic variant for compat.

Sourceval focus : t -> string -> t

Focus a specific slot by ID. No-op if ID not found.

Sourceval set_focusable : t -> string -> bool -> t

Enable or disable a slot for Tab cycling. When disabling the currently focused slot, focus moves to the next available slot.

Sourceval total : t -> int

Total number of slots.

Sourceval focusable_count : t -> int

Number of currently focusable slots.

Nested scopes

A scope tracks a parent ring and a map of child rings. Enter a child scope with enter, exit back with exit. Tab cycles within the active scope; Esc exits the child scope.

Sourcetype scope
Sourceval scope : parent:t -> children:(string * t) list -> scope

Create a scope from a parent ring and named child rings. Each child ring is associated with a parent slot by ID.

Sourceval active : scope -> t

The ring currently active in the scope (parent or child).

Sourceval in_child : scope -> bool

Is the scope currently inside a child ring?

Sourceval active_child_id : scope -> string option

Name of the active child ring, if in a child scope.

Sourceval enter : scope -> scope

Enter the child ring associated with the currently focused parent slot. No-op if the focused slot has no child ring.

Sourceval exit : scope -> scope

Exit the child ring, returning focus to the parent. No-op if already at the parent level.

Sourceval update_child : scope -> string -> t -> scope

Update a child ring inside a scope. No-op if the child ID is not found.

Sourceval on_scope_key : scope -> key:string -> scope * Miaou_interfaces.Key_event.result

Handle keys within the scope:

  • Tab/Shift+Tab cycle within the active ring
  • Enter enters a child scope (if available)
  • Esc exits a child scope back to the parent
  • Other keys bubble.
Sourceval handle_scope_key : scope -> key:string -> scope * [ `Handled | `Bubble ]
  • deprecated

    Use on_scope_key instead. Returns polymorphic variant for compat.