2009-01-25 18:55:27 -05:00
|
|
|
! Copyright (C) 2005, 2009 Slava Pestov.
|
2007-09-20 18:09:08 -04:00
|
|
|
! See http://factorcode.org/license.txt for BSD license.
|
2015-10-18 11:35:26 -04:00
|
|
|
USING: accessors combinators grouping kernel math math.vectors
|
|
|
|
namespaces sequences threads ui.gadgets ui.gadgets.packs
|
|
|
|
ui.gadgets.private ;
|
2007-09-20 18:09:08 -04:00
|
|
|
IN: ui.gadgets.incremental
|
|
|
|
|
2008-07-10 21:32:17 -04:00
|
|
|
TUPLE: incremental < pack cursor ;
|
2007-09-20 18:09:08 -04:00
|
|
|
|
2008-07-10 21:32:17 -04:00
|
|
|
: <incremental> ( -- incremental )
|
2009-02-16 05:04:32 -05:00
|
|
|
incremental new
|
2009-02-02 01:02:55 -05:00
|
|
|
vertical >>orientation
|
2008-07-10 21:32:17 -04:00
|
|
|
{ 0 0 } >>cursor ;
|
2007-09-20 18:09:08 -04:00
|
|
|
|
|
|
|
M: incremental pref-dim*
|
2008-08-29 19:44:19 -04:00
|
|
|
dup layout-state>> [
|
2008-09-27 15:36:04 -04:00
|
|
|
dup call-next-method >>cursor
|
2008-08-30 22:58:13 -04:00
|
|
|
] when cursor>> ;
|
2007-09-20 18:09:08 -04:00
|
|
|
|
|
|
|
: next-cursor ( gadget incremental -- cursor )
|
|
|
|
[
|
2009-02-01 21:31:42 -05:00
|
|
|
[ dim>> ] [ cursor>> ] bi*
|
2008-09-27 18:54:51 -04:00
|
|
|
[ vmax ] [ v+ ] 2bi
|
2008-08-29 19:44:19 -04:00
|
|
|
] keep orientation>> set-axis ;
|
2007-09-20 18:09:08 -04:00
|
|
|
|
|
|
|
: update-cursor ( gadget incremental -- )
|
2009-01-23 19:20:47 -05:00
|
|
|
[ nip ] [ next-cursor ] 2bi >>cursor drop ;
|
2007-09-20 18:09:08 -04:00
|
|
|
|
|
|
|
: incremental-loc ( gadget incremental -- )
|
2008-09-01 23:43:56 -04:00
|
|
|
[ cursor>> ] [ orientation>> ] bi v*
|
|
|
|
>>loc drop ;
|
2007-09-20 18:09:08 -04:00
|
|
|
|
2009-01-25 18:55:27 -05:00
|
|
|
: prefer-incremental ( gadget -- )
|
2011-10-16 22:33:16 -04:00
|
|
|
dup forget-pref-dim prefer ;
|
2007-09-20 18:09:08 -04:00
|
|
|
|
2008-09-27 18:54:51 -04:00
|
|
|
M: incremental dim-changed drop ;
|
|
|
|
|
2015-10-16 04:55:48 -04:00
|
|
|
: scroll-children ( incremental -- )
|
|
|
|
dup children>> length 200,000 > [
|
|
|
|
! We let the length oscillate between 100k-200k, so we don't
|
2015-10-18 11:35:26 -04:00
|
|
|
! have to relayout the container every time a gadget is added.
|
|
|
|
[ 100,000 short cut* ] change-children relayout yield
|
|
|
|
|
|
|
|
! Then we ungraft the scrolled of gadgets. Yield every 10k
|
|
|
|
! gadget so to not overflow the ungraft queue.
|
|
|
|
10 <groups> [ [ ungraft ] each yield ] each
|
2015-10-16 04:55:48 -04:00
|
|
|
] [ drop ] if ;
|
|
|
|
|
2007-09-20 18:09:08 -04:00
|
|
|
: add-incremental ( gadget incremental -- )
|
2007-11-16 01:19:13 -05:00
|
|
|
not-in-layout
|
2015-10-16 04:55:48 -04:00
|
|
|
dup scroll-children
|
2009-02-02 14:43:54 -05:00
|
|
|
2dup (add-gadget)
|
2008-09-27 18:54:51 -04:00
|
|
|
t in-layout? [
|
2009-01-25 18:55:27 -05:00
|
|
|
{
|
|
|
|
[ drop prefer-incremental ]
|
|
|
|
[ drop layout-later ]
|
|
|
|
[ incremental-loc ]
|
|
|
|
[ update-cursor ]
|
|
|
|
[ nip prefer-incremental ]
|
|
|
|
[ nip parent>> [ invalidate* ] when* ]
|
|
|
|
} 2cleave
|
2008-09-27 18:54:51 -04:00
|
|
|
] with-variable ;
|
2007-09-20 18:09:08 -04:00
|
|
|
|
|
|
|
: clear-incremental ( incremental -- )
|
2007-11-16 01:19:13 -05:00
|
|
|
not-in-layout
|
2009-01-25 18:55:27 -05:00
|
|
|
[ (clear-gadget) ]
|
|
|
|
[ forget-pref-dim ]
|
|
|
|
[ { 0 0 } >>cursor parent>> [ relayout ] when* ]
|
|
|
|
tri ;
|