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

44 lines
1.0 KiB
Factor
Raw Normal View History

2008-11-20 19:11:25 -05:00
! Copyright (C) 2005, 2008 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 math.geometry.rect ;
2007-09-20 18:09:08 -04:00
IN: ui.gadgets.frames
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
2008-11-19 22:13:50 -05:00
: @center 1 1 ; inline
: @left 0 1 ; inline
: @right 2 1 ; inline
: @top 1 0 ; inline
: @bottom 1 2 ; inline
2007-09-20 18:09:08 -04:00
2008-11-19 22:13:50 -05:00
: @top-left 0 0 ; inline
: @top-right 2 0 ; inline
: @bottom-left 0 2 ; inline
: @bottom-right 2 2 ; inline
2007-09-20 18:09:08 -04:00
2008-11-25 20:20:25 -05:00
TUPLE: frame < grid ;
: new-frame ( class -- frame )
<frame-grid> swap new-grid ; inline
2007-09-20 18:09:08 -04:00
: <frame> ( -- frame )
frame new-frame ;
2007-09-20 18:09:08 -04:00
2008-11-25 20:20:25 -05:00
: (fill-center) ( dim vec -- )
2008-11-19 22:13:50 -05:00
[ [ first ] [ third ] bi v+ [v-] ] keep set-second ;
2007-09-20 18:09:08 -04:00
2008-11-19 22:13:50 -05:00
: fill-center ( dim horiz vert -- )
[ over ] dip [ (fill-center) ] 2bi@ ;
2007-09-20 18:09:08 -04:00
M: frame layout*
dup compute-grid
2008-11-25 20:20:25 -05:00
[ [ dim>> ] 2dip fill-center ] [ grid-layout ] 3bi ;