2008-07-10 21:32:17 -04:00
|
|
|
! Copyright (C) 2005, 2008 Slava Pestov.
|
2007-09-20 18:09:08 -04:00
|
|
|
! See http://factorcode.org/license.txt for BSD license.
|
2008-07-10 21:32:17 -04:00
|
|
|
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.
|
2007-11-16 03:01:45 -05:00
|
|
|
! New gadgets are added at
|
|
|
|
! incremental-cursor gadget-orientation v*
|
2007-09-20 18:09:08 -04:00
|
|
|
|
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 )
|
|
|
|
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>> [
|
2008-08-30 22:58:13 -04:00
|
|
|
dup call-next-method over (>>cursor)
|
|
|
|
] when cursor>> ;
|
2007-09-20 18:09:08 -04:00
|
|
|
|
|
|
|
: next-cursor ( gadget incremental -- cursor )
|
|
|
|
[
|
2008-08-30 22:58:13 -04:00
|
|
|
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 -- )
|
2008-08-30 22:58:13 -04:00
|
|
|
[ next-cursor ] keep (>>cursor) ;
|
2007-09-20 18:09:08 -04:00
|
|
|
|
|
|
|
: incremental-loc ( gadget incremental -- )
|
2008-08-30 22:58:13 -04:00
|
|
|
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
|
2007-11-16 03:01:45 -05:00
|
|
|
dup (clear-gadget)
|
|
|
|
dup forget-pref-dim
|
2008-08-30 22:58:13 -04:00
|
|
|
{ 0 0 } over (>>cursor)
|
2008-08-29 19:44:19 -04:00
|
|
|
parent>> [ relayout ] when* ;
|