diff --git a/library/ui/editors.factor b/library/ui/editors.factor index dd5762609f..f114215629 100644 --- a/library/ui/editors.factor +++ b/library/ui/editors.factor @@ -50,9 +50,7 @@ TUPLE: editor line caret ; [ line-text get x>offset caret set ] with-editor ; : click-editor ( editor -- ) - hand - 2dup relative shape-x pick set-caret-x - request-focus ; + dup hand relative shape-x over set-caret-x request-focus ; : editor-actions ( editor -- ) [ diff --git a/library/ui/gadgets.factor b/library/ui/gadgets.factor index 146b97ce8e..b48ba5553d 100644 --- a/library/ui/gadgets.factor +++ b/library/ui/gadgets.factor @@ -90,3 +90,11 @@ M: gadget layout* GENERIC: user-input* ( ch gadget -- ? ) M: gadget user-input* 2drop t ; + +GENERIC: focusable-child* ( gadget -- gadget/t ) + +M: gadget focusable-child* drop t ; + +: focusable-child ( gadget -- gadget ) + dup focusable-child* + dup t = [ drop ] [ nip focusable-child ] ifte ; diff --git a/library/ui/hand.factor b/library/ui/hand.factor index 957e8b5900..073fcc1bc0 100644 --- a/library/ui/hand.factor +++ b/library/ui/hand.factor @@ -104,8 +104,9 @@ C: hand ( world -- hand ) #! Called when a gadget is removed or added. [ dup shape-x swap shape-y ] keep move-hand ; -: request-focus ( gadget hand -- ) - dup >r hand-focus +: request-focus ( gadget -- ) + focusable-child + hand hand-focus 2dup lose-focus - swap dup r> set-hand-focus + swap dup hand set-hand-focus gain-focus ; diff --git a/library/ui/init-world.factor b/library/ui/init-world.factor index 8474ff434f..10791ef1eb 100644 --- a/library/ui/init-world.factor +++ b/library/ui/init-world.factor @@ -22,6 +22,9 @@ global [ add-layer - "Stack display goes here"