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
|
2005-06-28 16:25:27 -04:00
|
|
|
USING: errors generic hashtables kernel lists math matrices
|
|
|
|
namespaces sdl sequences ;
|
2005-02-02 19:50:13 -05:00
|
|
|
|
2005-02-03 19:11:06 -05:00
|
|
|
: 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? [
|
2005-04-30 17:17:10 -04:00
|
|
|
f over set-gadget-relayout?
|
2005-02-03 22:21:51 -05:00
|
|
|
dup gadget-paint [
|
2005-03-07 23:15:00 -05:00
|
|
|
dup layout*
|
|
|
|
gadget-children [ layout ] each
|
2005-02-03 22:21:51 -05:00
|
|
|
] bind
|
2005-02-03 19:11:06 -05:00
|
|
|
] [
|
|
|
|
drop
|
|
|
|
] ifte ;
|
|
|
|
|
2005-03-08 22:54:59 -05:00
|
|
|
: with-pref-size ( quot -- )
|
|
|
|
[
|
|
|
|
0 width set 0 height set call width get height get
|
|
|
|
] with-scope ; inline
|
|
|
|
|
|
|
|
: with-layout ( quot -- )
|
|
|
|
[ 0 x set 0 y set call ] with-scope ; inline
|
|
|
|
|
2005-06-29 00:33:07 -04:00
|
|
|
: pref-dims ( gadget -- list )
|
|
|
|
gadget-children [ pref-dim ] map ;
|
|
|
|
|
|
|
|
: packed-pref-dim ( gadget gap axis -- dim )
|
2005-06-28 16:25:27 -04:00
|
|
|
#! The preferred size of the gadget, if all children are
|
|
|
|
#! packed in the direction of the given axis.
|
|
|
|
>r
|
2005-06-29 00:33:07 -04:00
|
|
|
over length 0 max v*n >r pref-dims r>
|
2005-06-28 16:25:27 -04:00
|
|
|
2dup [ v+ ] reduce >r [ vmax ] reduce r>
|
|
|
|
r> set-axis ;
|