ui.text.private ;
IN: ui
+<PRIVATE
+
! Assoc mapping aliens to gadgets
SYMBOL: windows
[ handle>> (close-window) ]
[ reset-world ] tri ;
-: find-window ( quot -- world )
- windows get values
- [ gadget-child swap call ] with find-last nip ; inline
-
: init-ui ( -- )
<dlist> \ graft-queue set-global
<dlist> \ layout-queue set-global
children>> [ restore-gadget ] each ;
: restore-world ( world -- )
- [ reset-world ] [ init-text-rendering ] [ restore-gadget ] tri ;
+ {
+ [ reset-world ]
+ [ init-text-rendering ]
+ [ f >>images drop ]
+ [ restore-gadget ]
+ } cleave ;
: update-hand ( world -- )
dup hand-world get-global eq?
t \ ui-running set-global
[ f \ ui-running set-global ] [ ] cleanup ; inline
+PRIVATE>
+
+: find-window ( quot -- world )
+ windows get values
+ [ gadget-child swap call ] with find-last nip ; inline
+
: ui-running? ( -- ? )
\ ui-running get-global ;
+<PRIVATE
+
: update-ui-loop ( -- )
[ ui-running? ui-thread get-global self eq? and ]
[ ui-notify-flag get lower-flag update-ui ]
- [ ] while ;
+ while ;
: start-ui-thread ( -- )
[ self ui-thread set-global update-ui-loop ]
"UI update" spawn drop ;
+: start-ui ( quot -- )
+ call notify-ui-thread start-ui-thread ;
+
+: restore-windows ( -- )
+ [
+ windows get [ values ] [ delete-all ] bi
+ [ restore-world ] each
+ forget-rollover
+ ] (with-ui) ;
+
+: restore-windows? ( -- ? )
+ windows get empty? not ;
+
+PRIVATE>
+
: open-world-window ( world -- )
dup pref-dim >>dim dup relayout graft ;
M: object close-window
find-world [ ungraft ] when* ;
-: start-ui ( quot -- )
- call notify-ui-thread start-ui-thread ;
-
[
f \ ui-running set-global
<flag> ui-notify-flag set-global
] "ui" add-init-hook
-HOOK: (with-ui) ui-backend ( quot -- )
-
-: restore-windows ( -- )
- [
- windows get [ values ] [ delete-all ] bi
- [ restore-world ] each
- forget-rollover
- ] (with-ui) ;
-
-: restore-windows? ( -- ? )
- windows get empty? not ;
-
: with-ui ( quot -- )
ui-running? [ call ] [ '[ init-ui @ ] (with-ui) ] if ;