You can search for identifiers within the package.
in-package search v0.2.0
Source file focus_container.ml
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188(******************************************************************************)(* *)(* SPDX-License-Identifier: MIT *)(* Copyright (c) 2026 Nomadic Labs <contact@nomadic-labs.com> *)(* *)(******************************************************************************)[@@@warning"-32-34-37-69"](** Widget operations for Focus_container.
New API uses [on_key] with [Key_event.result].
Legacy [handle_key] is still supported via adapters. *)type'awidget_ops={render:'a->focus:bool->string;on_key:'a->key:string->'a*Miaou_interfaces.Key_event.result;}(** @deprecated Legacy widget ops with polymorphic variant result. *)type'awidget_ops_legacy={render:'a->focus:bool->string;handle_key:'a->key:string->'a*[`Handled|`Bubble];}(* Type equality witness via extensible GADT — no Obj.magic needed.
Same approach as Hmap / Univ_map. *)type(_,_)teq=Teq:('a,'a)teqtype_witness_key=..type'awitness={key:'awitness_key;cast:'b.'bwitness_key->('a,'b)teqoption;}letwitness(typea)():awitness=letmoduleM=structtype_witness_key+=K:awitness_keyendin{key=M.K;cast=(fun(typeb)(k:bwitness_key):(a,b)teqoption->matchkwithM.K->SomeTeq|_->None);}typepacked_slot=|Slot:{id:string;ops:'awidget_ops;mutablestate:'a;wkey:'awitness_keyoption;}->packed_slotletslotidopsstate=Slot{id;ops;state;wkey=None}letslot_widopsstate(w:_witness)=Slot{id;ops;state;wkey=Somew.key}typet={ring:Focus_ring.t;slots:packed_slotlist}letcreateslots=letids=List.map(fun(Slots)->s.id)slotsinletring=Focus_ring.createidsin{ring;slots}letcountt=List.lengtht.slotsletfocused_idt=Focus_ring.currentt.ringletringt=t.ringletset_ringtr={twithring=r}letfocustid={twithring=Focus_ring.focust.ringid}letrender_allt=letfocused=Focus_ring.currentt.ringinList.map(fun(Slots)->letis_focused=matchfocusedwithSomefid->String.equals.idfid|None->falsein(s.id,is_focused,s.ops.renders.state~focus:is_focused))t.slotsletrender_focusedt=matchFocus_ring.currentt.ringwith|None->None|Somefid->(matchList.find_opt(fun(Slots)->String.equals.idfid)t.slotswith|None->None|Some(Slots)->Some(s.id,s.ops.renders.state~focus:true))(** New unified key handler returning Key_event.result *)leton_keyt~key=letopenMiaou_interfaces.Key_eventinletring',ring_result=Focus_ring.on_keyt.ring~keyinmatchring_resultwith|Handled->({twithring=ring'},Handled)|Bubble->(matchFocus_ring.currentt.ringwith|None->(t,Bubble)|Somefid->letstatus=refBubbleinList.iter(fun(Slots)->ifString.equals.idfidthenbeginletstate',st=s.ops.on_keys.state~keyins.state<-state';status:=stend)t.slots;(t,!status))(** @deprecated Use [on_key] instead. Returns polymorphic variant for compat. *)lethandle_keyt~key=lett',result=on_keyt~keyinletstatus=matchresultwith|Miaou_interfaces.Key_event.Handled->`Handled|Miaou_interfaces.Key_event.Bubble->`Bubblein(t',status)(* Type-safe extraction via extensible GADT witness *)letget:typea.t->string->awitness->aoption=funtidw->matchList.find_opt(fun(Slots)->String.equals.idid)t.slotswith|None->None|Some(Slots)->(matchs.wkeywith|None->None|Somek->(matchw.castkwithSomeTeq->Somes.state|None->None))letset:typea.t->string->awitness->a->t=funtidwv->List.iter(fun(Slots)->ifString.equals.ididthenmatchs.wkeywith|None->()|Somek->(matchw.castkwithSomeTeq->s.state<-v|None->()))t.slots;t(** Create widget_ops from render and on_key functions. *)letops~render~on_key={render;on_key}(** @deprecated Adapter: wrap simple handle_key that returns just state (bubbles). *)letops_simple~render~handle_key={render;on_key=(funst~key->(handle_keyst~key,Miaou_interfaces.Key_event.Bubble));}(** @deprecated Adapter: wrap handle_key that returns (state, bool). *)letops_bool~render~handle_key={render;on_key=(funst~key->letst',fired=handle_keyst~keyin(st',iffiredthenMiaou_interfaces.Key_event.HandledelseMiaou_interfaces.Key_event.Bubble));}(** Adapter: wrap legacy handle_key returning polymorphic variant. *)letops_of_legacy(legacy:'awidget_ops_legacy):'awidget_ops={render=legacy.render;on_key=(funst~key->letst',status=legacy.handle_keyst~keyinletresult=matchstatuswith|`Handled->Miaou_interfaces.Key_event.Handled|`Bubble->Miaou_interfaces.Key_event.Bubblein(st',result));}