factor/basis/ui/gadgets/incremental/incremental.factor

55 lines
1.4 KiB
Factor
Raw Normal View History

! Copyright (C) 2005, 2008 Slava Pestov.
2007-09-20 18:09:08 -04:00
! See http://factorcode.org/license.txt for BSD license.
USING: io kernel math namespaces math.vectors ui.gadgets
2008-07-11 19:34:43 -04:00
ui.gadgets.packs accessors math.geometry.rect ;
2007-09-20 18:09:08 -04:00
IN: ui.gadgets.incremental
TUPLE: incremental < pack cursor ;
2007-09-20 18:09:08 -04:00
: <incremental> ( -- incremental )
incremental new-gadget
{ 0 1 } >>orientation
{ 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>> [
dup call-next-method >>cursor
] when cursor>> ;
2007-09-20 18:09:08 -04:00
: next-cursor ( gadget incremental -- cursor )
[
2008-09-27 18:54:51 -04:00
[ rect-dim ] [ cursor>> ] bi*
[ 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 -- )
2008-09-27 18:54:51 -04:00
tuck next-cursor >>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
2008-09-27 18:54:51 -04:00
: prefer-incremental ( gadget -- ) USE: slots.private
2008-08-31 17:22:25 -04:00
dup forget-pref-dim dup pref-dim >>dim drop ;
2007-09-20 18:09:08 -04:00
2008-09-27 18:54:51 -04:00
M: incremental dim-changed drop ;
2007-09-20 18:09:08 -04:00
: add-incremental ( gadget incremental -- )
2007-11-16 01:19:13 -05:00
not-in-layout
2008-07-13 02:25:44 -04:00
2dup swap (add-gadget) drop
2008-09-27 18:54:51 -04:00
t in-layout? [
over prefer-incremental
over layout-later
2dup incremental-loc
tuck update-cursor
dup prefer-incremental
parent>> [ invalidate* ] when*
] with-variable ;
2007-09-20 18:09:08 -04:00
: clear-incremental ( incremental -- )
2007-11-16 01:19:13 -05:00
not-in-layout
dup (clear-gadget)
dup forget-pref-dim
{ 0 0 } >>cursor
2008-08-29 19:44:19 -04:00
parent>> [ relayout ] when* ;