]> gitweb.factorcode.org Git - factor.git/blob - basis/ui/gadgets/incremental/incremental.factor
Fix conflict in images vocab
[factor.git] / basis / ui / gadgets / incremental / incremental.factor
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.private ui.gadgets.packs accessors
5 math.rectangles combinators ;
6 IN: ui.gadgets.incremental
7
8 TUPLE: incremental < pack cursor ;
9
10 : <incremental> ( -- incremental )
11     incremental new
12         vertical >>orientation
13         { 0 0 } >>cursor ;
14
15 M: incremental pref-dim*
16     dup layout-state>> [
17         dup call-next-method >>cursor
18     ] when cursor>> ;
19
20 : next-cursor ( gadget incremental -- cursor )
21     [
22         [ dim>> ] [ cursor>> ] bi*
23         [ vmax ] [ v+ ] 2bi
24     ] keep orientation>> set-axis ;
25
26 : update-cursor ( gadget incremental -- )
27     [ nip ] [ next-cursor ] 2bi >>cursor drop ;
28
29 : incremental-loc ( gadget incremental -- )
30     [ cursor>> ] [ orientation>> ] bi v*
31     >>loc drop ;
32
33 : prefer-incremental ( gadget -- )
34     dup forget-pref-dim dup pref-dim >>dim drop ;
35
36 M: incremental dim-changed drop ;
37
38 : add-incremental ( gadget incremental -- )
39     not-in-layout
40     2dup (add-gadget)
41     t in-layout? [
42         {
43             [ drop prefer-incremental ]
44             [ drop layout-later ]
45             [ incremental-loc ]
46             [ update-cursor ]
47             [ nip prefer-incremental ]
48             [ nip parent>> [ invalidate* ] when* ]
49         } 2cleave
50     ] with-variable ;
51
52 : clear-incremental ( incremental -- )
53     not-in-layout
54     [ (clear-gadget) ]
55     [ forget-pref-dim ]
56     [ { 0 0 } >>cursor parent>> [ relayout ] when* ]
57     tri ;