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

62 lines
1.8 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
! Incremental layout allows adding lines to panes to be O(1).
! Note that incremental packs are distinct from ordinary packs
! defined in layouts.factor, since you don't want all packs to
! be incremental. In particular, incremental packs do not
! support non-default values for pack-align, pack-fill and
! pack-gap.
! The cursor is the current size of the incremental pack.
! New gadgets are added at
! incremental-cursor gadget-orientation v*
2007-09-20 18:09:08 -04:00
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 over (>>cursor)
] when cursor>> ;
2007-09-20 18:09:08 -04:00
: next-cursor ( gadget incremental -- cursor )
[
swap rect-dim swap cursor>>
2007-09-20 18:09:08 -04:00
2dup v+ >r vmax r>
2008-08-29 19:44:19 -04:00
] keep orientation>> set-axis ;
2007-09-20 18:09:08 -04:00
: update-cursor ( gadget incremental -- )
[ next-cursor ] keep (>>cursor) ;
2007-09-20 18:09:08 -04:00
: incremental-loc ( gadget incremental -- )
dup cursor>> swap orientation>> v*
2007-09-20 18:09:08 -04:00
swap set-rect-loc ;
: prefer-incremental ( gadget -- )
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
: 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
2007-11-21 04:19:50 -05:00
over prefer-incremental
2007-11-24 23:57:37 -05:00
over layout-later
2007-09-20 18:09:08 -04:00
2dup incremental-loc
tuck update-cursor
2007-11-21 04:19:50 -05:00
dup prefer-incremental
2008-08-29 19:44:19 -04:00
parent>> [ invalidate* ] when* ;
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 } over (>>cursor)
2008-08-29 19:44:19 -04:00
parent>> [ relayout ] when* ;