2009-02-05 04:31:18 -05:00
|
|
|
! Copyright (C) 2005, 2009 Slava Pestov.
|
2007-09-20 18:09:08 -04:00
|
|
|
! See http://factorcode.org/license.txt for BSD license.
|
2008-11-25 20:20:25 -05:00
|
|
|
USING: accessors arrays generic kernel math namespaces sequences
|
|
|
|
words splitting grouping math.vectors ui.gadgets.grids
|
2009-02-15 04:59:02 -05:00
|
|
|
ui.gadgets.grids.private ui.gadgets math.order math.rectangles
|
|
|
|
fry ;
|
2007-09-20 18:09:08 -04:00
|
|
|
IN: ui.gadgets.frames
|
|
|
|
|
2009-02-15 04:59:02 -05:00
|
|
|
TUPLE: frame < grid filled-cell ;
|
2009-02-05 04:31:18 -05:00
|
|
|
|
|
|
|
<PRIVATE
|
|
|
|
|
2008-11-25 20:20:25 -05:00
|
|
|
TUPLE: glue < gadget ;
|
|
|
|
|
|
|
|
M: glue pref-dim* drop { 0 0 } ;
|
|
|
|
|
2009-02-16 05:04:32 -05:00
|
|
|
: <glue> ( -- glue ) glue new ;
|
2007-09-20 18:09:08 -04:00
|
|
|
|
2009-02-15 04:59:02 -05:00
|
|
|
: <frame-grid> ( cols rows -- grid )
|
|
|
|
swap '[ _ [ <glue> ] replicate ] replicate ;
|
|
|
|
|
|
|
|
: (fill- ( frame grid-layout quot1 quot2 -- pref-dim gap filled-cell dims )
|
|
|
|
[ '[ [ dim>> ] [ gap>> ] [ filled-cell>> ] tri _ tri@ ] dip ] dip call ; inline
|
|
|
|
|
2009-02-24 02:32:46 -05:00
|
|
|
: available-space ( pref-dim gap dims -- avail )
|
2009-08-13 20:21:44 -04:00
|
|
|
length 1 + * [-] ; inline
|
2009-02-24 02:32:46 -05:00
|
|
|
|
2009-02-15 04:59:02 -05:00
|
|
|
: -center) ( pref-dim gap filled-cell dims -- )
|
2009-10-04 18:50:34 -04:00
|
|
|
[ nip available-space ]
|
|
|
|
[ [ remove-nth sum [-] ] [ set-nth ] 2bi ] 2bi ; inline
|
2009-02-15 04:59:02 -05:00
|
|
|
|
|
|
|
: (fill-center) ( frame grid-layout quot1 quot2 -- ) (fill- -center) ; inline
|
2007-09-20 18:09:08 -04:00
|
|
|
|
2009-02-15 04:59:02 -05:00
|
|
|
: fill-center ( frame grid-layout -- )
|
|
|
|
[ [ first ] [ column-widths>> ] (fill-center) ]
|
|
|
|
[ [ second ] [ row-heights>> ] (fill-center) ] 2bi ;
|
2007-09-20 18:09:08 -04:00
|
|
|
|
2009-02-15 04:59:02 -05:00
|
|
|
: <frame-layout> ( frame -- grid-layout )
|
2009-10-04 18:50:34 -04:00
|
|
|
dup <grid-layout> [ fill-center ] [ ] bi ;
|
2007-09-20 18:09:08 -04:00
|
|
|
|
2009-02-05 04:31:18 -05:00
|
|
|
PRIVATE>
|
|
|
|
|
|
|
|
M: frame layout*
|
2009-02-15 04:59:02 -05:00
|
|
|
[ grid>> ] [ <frame-layout> ] bi grid-layout ;
|
2008-11-25 20:20:25 -05:00
|
|
|
|
2009-02-15 04:59:02 -05:00
|
|
|
: new-frame ( cols rows class -- frame )
|
|
|
|
[ <frame-grid> ] dip new-grid ; inline
|
2008-07-10 21:32:17 -04:00
|
|
|
|
2009-02-15 04:59:02 -05:00
|
|
|
: <frame> ( cols rows -- frame )
|
2009-08-13 20:21:44 -04:00
|
|
|
frame new-frame ;
|