factor/basis/ui/gadgets/frames/frames.factor

49 lines
1.2 KiB
Factor
Raw Normal View History

! 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
ui.gadgets.grids.private ui.gadgets math.order math.rectangles ;
2007-09-20 18:09:08 -04:00
IN: ui.gadgets.frames
CONSTANT: @center { 1 1 }
CONSTANT: @left { 0 1 }
CONSTANT: @right { 2 1 }
CONSTANT: @top { 1 0 }
CONSTANT: @bottom { 1 2 }
CONSTANT: @top-left { 0 0 }
CONSTANT: @top-right { 2 0 }
CONSTANT: @bottom-left { 0 2 }
CONSTANT: @bottom-right { 2 2 }
TUPLE: frame < grid ;
<PRIVATE
2008-11-25 20:20:25 -05:00
TUPLE: glue < gadget ;
M: glue pref-dim* drop { 0 0 } ;
: <glue> ( -- glue ) glue new-gadget ;
2007-09-20 18:09:08 -04:00
2008-11-25 20:20:25 -05:00
: <frame-grid> ( -- grid ) 9 [ <glue> ] replicate 3 group ;
2007-09-20 18:09:08 -04:00
: (fill-center) ( n seq -- )
[ [ first ] [ third ] bi + [-] ] keep set-second ;
2007-09-20 18:09:08 -04:00
: fill-center ( dim grid-layout -- )
[ [ first ] [ column-widths>> ] bi* ]
[ [ second ] [ row-heights>> ] bi* ] 2bi
[ (fill-center) ] 2bi@ ;
2007-09-20 18:09:08 -04:00
PRIVATE>
M: frame layout*
[ grid>> ] [ dim>> ] [ <grid-layout> ] tri
[ fill-center ] keep grid-layout ;
2008-11-25 20:20:25 -05:00
: new-frame ( class -- frame )
<frame-grid> swap new-grid ; inline
2007-09-20 18:09:08 -04:00
: <frame> ( -- frame )
frame new-frame ;