factor/extra/ui/gadgets/incremental/incremental.factor

61 lines
1.8 KiB
Factor
Raw Normal View History

2007-09-20 18:09:08 -04:00
! Copyright (C) 2005, 2007 Slava Pestov.
! See http://factorcode.org/license.txt for BSD license.
2007-11-21 04:19:50 -05:00
USING: io kernel math namespaces math.vectors ui.gadgets ;
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
2007-11-21 04:19:50 -05:00
TUPLE: incremental cursor ;
2007-09-20 18:09:08 -04:00
: <incremental> ( pack -- incremental )
2007-11-21 04:19:50 -05:00
dup pref-dim
{ set-gadget-delegate set-incremental-cursor }
incremental construct ;
2007-09-20 18:09:08 -04:00
M: incremental pref-dim*
2007-11-16 01:54:13 -05:00
dup gadget-layout-state [
2007-09-20 18:09:08 -04:00
dup delegate pref-dim over set-incremental-cursor
] when incremental-cursor ;
: next-cursor ( gadget incremental -- cursor )
[
swap rect-dim swap incremental-cursor
2dup v+ >r vmax r>
] keep gadget-orientation set-axis ;
: update-cursor ( gadget incremental -- )
[ next-cursor ] keep set-incremental-cursor ;
: incremental-loc ( gadget incremental -- )
dup incremental-cursor swap gadget-orientation v*
swap set-rect-loc ;
: prefer-incremental ( gadget -- )
2007-11-24 23:57:37 -05:00
dup forget-pref-dim dup pref-dim swap set-rect-dim ;
2007-09-20 18:09:08 -04:00
: add-incremental ( gadget incremental -- )
2007-11-16 01:19:13 -05:00
not-in-layout
2007-11-21 04:19:50 -05:00
2dup (add-gadget)
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
gadget-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
2007-09-20 18:09:08 -04:00
{ 0 0 } over set-incremental-cursor
gadget-parent [ relayout ] when* ;