1 ! Copyright (C) 2005, 2009 Slava Pestov.
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: io kernel math namespaces math.vectors ui.gadgets
4 ui.gadgets.packs accessors math.geometry.rect combinators ;
5 IN: ui.gadgets.incremental
7 TUPLE: incremental < pack cursor ;
9 : <incremental> ( -- incremental )
10 incremental new-gadget
14 M: incremental pref-dim*
16 dup call-next-method >>cursor
19 : next-cursor ( gadget incremental -- cursor )
21 [ rect-dim ] [ cursor>> ] bi*
23 ] keep orientation>> set-axis ;
25 : update-cursor ( gadget incremental -- )
26 [ nip ] [ next-cursor ] 2bi >>cursor drop ;
28 : incremental-loc ( gadget incremental -- )
29 [ cursor>> ] [ orientation>> ] bi v*
32 : prefer-incremental ( gadget -- )
33 dup forget-pref-dim dup pref-dim >>dim drop ;
35 M: incremental dim-changed drop ;
37 : add-incremental ( gadget incremental -- )
39 2dup swap (add-gadget) drop
42 [ drop prefer-incremental ]
46 [ nip prefer-incremental ]
47 [ nip parent>> [ invalidate* ] when* ]
51 : clear-incremental ( incremental -- )
55 [ { 0 0 } >>cursor parent>> [ relayout ] when* ]