2005-02-02 19:50:13 -05:00
|
|
|
! Copyright (C) 2005 Slava Pestov.
|
|
|
|
! See http://factor.sf.net/license.txt for BSD license.
|
|
|
|
IN: gadgets
|
|
|
|
USING: generic hashtables kernel lists math namespaces ;
|
|
|
|
|
2005-02-03 18:18:47 -05:00
|
|
|
GENERIC: layout* ( gadget -- )
|
|
|
|
M: gadget layout* drop ;
|
|
|
|
|
2005-02-02 19:50:13 -05:00
|
|
|
! A pile is a box that lays out its contents vertically.
|
|
|
|
TUPLE: pile delegate ;
|
|
|
|
|
2005-02-03 18:18:47 -05:00
|
|
|
C: pile ( shape -- pile )
|
|
|
|
[ >r <gadget> r> set-pile-delegate ] keep ;
|
2005-02-02 19:50:13 -05:00
|
|
|
|
|
|
|
M: pile layout* ( pile -- )
|
|
|
|
dup gadget-children run-heights >r >r
|
|
|
|
dup gadget-children max-width r> pick resize-gadget
|
|
|
|
gadget-children r> zip [
|
|
|
|
uncons 0 swap rot move-gadget
|
|
|
|
] each ;
|
2005-02-02 22:00:46 -05:00
|
|
|
|
|
|
|
! A shelf is a box that lays out its contents horizontally.
|
|
|
|
TUPLE: shelf delegate ;
|
|
|
|
|
2005-02-03 18:18:47 -05:00
|
|
|
C: shelf ( shape -- pile )
|
|
|
|
[ >r <gadget> r> set-shelf-delegate ] keep ;
|
2005-02-02 22:00:46 -05:00
|
|
|
|
|
|
|
M: shelf layout* ( pile -- )
|
|
|
|
dup gadget-children run-widths >r >r
|
|
|
|
dup gadget-children max-height r> swap pick resize-gadget
|
|
|
|
gadget-children r> zip [
|
|
|
|
uncons 0 rot move-gadget
|
|
|
|
] each ;
|
2005-02-03 18:18:47 -05:00
|
|
|
|
|
|
|
: relayout ( gadget -- )
|
|
|
|
#! Relayout a gadget before the next iteration of the event
|
|
|
|
#! loop. Since relayout also implies the visual
|
|
|
|
#! representation changed, we redraw the gadget too.
|
|
|
|
t over set-gadget-redraw?
|
|
|
|
t over set-gadget-relayout?
|
|
|
|
gadget-parent [ relayout ] when* ;
|
|
|
|
|
|
|
|
: layout ( gadget -- )
|
|
|
|
#! Set the gadget's width and height to its preferred width
|
|
|
|
#! and height. The gadget's children are laid out first.
|
|
|
|
#! Note that nothing is done if the gadget does not need to
|
|
|
|
#! be laid out.
|
|
|
|
dup gadget-relayout? [
|
|
|
|
f over set-gadget-relayout?
|
|
|
|
dup gadget-children [ layout ] each
|
|
|
|
layout*
|
|
|
|
] [
|
|
|
|
drop
|
|
|
|
] ifte ;
|