1 ! Copyright (C) 2005, 2009 Slava Pestov.
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: accessors combinators grouping kernel math math.vectors
4 namespaces sequences threads ui.gadgets ui.gadgets.packs
6 IN: ui.gadgets.incremental
8 TUPLE: incremental < pack cursor ;
10 : <incremental> ( -- incremental )
12 vertical >>orientation
15 M: incremental pref-dim*
17 dup call-next-method >>cursor
20 : next-cursor ( gadget incremental -- cursor )
22 [ dim>> ] [ cursor>> ] bi*
24 ] keep orientation>> set-axis ;
26 : update-cursor ( gadget incremental -- )
27 [ nip ] [ next-cursor ] 2bi >>cursor drop ;
29 : incremental-loc ( gadget incremental -- )
30 [ cursor>> ] [ orientation>> ] bi v*
33 : prefer-incremental ( gadget -- )
34 dup forget-pref-dim prefer ;
36 M: incremental dim-changed drop ;
38 : scroll-children ( incremental -- )
39 dup children>> length 200,000 > [
40 ! We let the length oscillate between 100k-200k, so we don't
41 ! have to relayout the container every time a gadget is added.
42 [ 100,000 bound cut* ] change-children
44 ! Unfocus if any focused gadgets were removed and relayout
45 dup focus>> pick member-eq? [ f >>focus ] when relayout yield
47 ! Then we finish unparenting the scrolled of gadgets. Yield
48 ! every 10k gadget so to not overflow the ungraft queue.
49 10 <groups> [ [ (unparent) ] each yield ] each
52 : add-incremental ( gadget incremental -- )
58 [ drop prefer-incremental ]
62 [ nip prefer-incremental ]
63 [ nip parent>> [ invalidate* ] when* ]
67 : clear-incremental ( incremental -- )
71 [ { 0 0 } >>cursor parent>> [ relayout ] when* ]