1 ! Copyright (C) 2021 Kevin Cope.
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: accessors arrays assocs classes kernel math.rectangles
4 models models.arrow namespaces sequences ui ui.gadgets
5 ui.gadgets.buttons ui.gadgets.glass ui.gadgets.labeled
6 ui.gadgets.presentations ui.gadgets.search-tables
7 ui.gadgets.labels ui.gadgets.tables ui.gadgets.wrappers ui.gestures
8 ui.theme ui.tools.browser.popups ui.tools.common ;
9 FROM: ui.gadgets.wrappers => wrapper ;
10 IN: ui.tools.button-list
12 TUPLE: button-list-popup < wrapper ;
15 INSTANCE: button clickable
17 SYMBOL: active-buttons
18 active-buttons [ H{ } ] initialize
20 : label-from-button ( button -- str/f )
21 children>> [ label? ] find swap [ text>> ] [ drop f ] if ;
23 : store-labelled-button ( button -- str/f )
24 dup label-from-button [ [ active-buttons get set-at ] keep ] [ drop f ] if* ;
26 : remove-labelled-button ( button -- str/f )
27 label-from-button [ dup active-buttons get delete-at ] [ f ] if* ;
29 M: clickable graft* [ store-labelled-button drop ] [ call-next-method ] bi ;
30 M: clickable ungraft* [ remove-labelled-button drop ] [ call-next-method ] bi ;
32 : <active-buttons-table> ( model -- table )
33 [ keys [ ">" swap 2array ] map ] <arrow> trivial-renderer [ second ] <search-table>
35 [ second active-buttons get at invoke-primary ] >>action
37 t >>selection-required?
45 : <active-buttons-popup> ( model title -- gadget )
46 [ <active-buttons-table> white-interior ] dip
47 popup-color <framed-labeled-gadget> button-list-popup new-wrapper ;
50 { T{ key-down f f "ESC" } [ hide-glass ] }
53 : show-active-buttons-popup ( tool -- )
54 active-buttons get <model> "Active Buttons" <active-buttons-popup>
55 [ hand-loc get-global point>rect show-glass ] [ request-focus ] bi ; inline