factor/library/ui/incremental.factor

54 lines
1.7 KiB
Factor
Raw Normal View History

2006-01-26 23:44:08 -05:00
! Copyright (C) 2005, 2006 Slava Pestov.
! See http://factorcode.org/license.txt for BSD license.
IN: gadgets-layouts
2005-09-25 20:41:49 -04:00
USING: gadgets generic io kernel math namespaces ;
2005-07-06 01:57:58 -04:00
! 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
2006-01-26 23:44:08 -05:00
! be incremental. In particular, incremental packs do not
! support non-default values for pack-align, pack-fill and
! pack-gap.
2005-07-06 01:57:58 -04:00
! The cursor is the current size of the incremental pack.
! New gadgets are added at cursor-cursor*gadget-orientation.
2005-07-06 01:57:58 -04:00
TUPLE: incremental cursor ;
C: incremental ( pack -- incremental )
2005-10-09 21:27:14 -04:00
[ set-gadget-delegate ] keep
dup delegate pref-dim over set-incremental-cursor ;
2005-07-06 01:57:58 -04:00
M: incremental pref-dim* ( incremental -- dim )
2005-09-25 21:27:29 -04:00
dup gadget-relayout? [
dup delegate pref-dim over set-incremental-cursor
] when incremental-cursor ;
2005-07-09 16:08:50 -04:00
2005-07-06 01:57:58 -04:00
: next-cursor ( gadget incremental -- cursor )
[
swap rect-dim swap incremental-cursor
2005-07-06 01:57:58 -04:00
2dup v+ >r vmax r>
] keep gadget-orientation set-axis ;
2005-07-06 01:57:58 -04:00
: 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 ;
2005-07-06 01:57:58 -04:00
2005-07-09 16:08:50 -04:00
: prefer-incremental ( gadget -- )
2006-01-26 23:44:08 -05:00
dup forget-pref-dim dup pref-dim over set-rect-dim layout ;
2005-07-09 16:08:50 -04:00
2005-07-06 01:57:58 -04:00
: add-incremental ( gadget incremental -- )
2005-07-09 16:08:50 -04:00
2dup (add-gadget)
over prefer-incremental
2dup incremental-loc
tuck update-cursor
prefer-incremental ;
: clear-incremental ( incremental -- )
2006-01-26 23:44:53 -05:00
dup (clear-gadget) dup forget-pref-dim
{ 0 0 0 } over set-incremental-cursor
gadget-parent [ relayout ] when* ;