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

40 lines
1.0 KiB
Factor
Raw Normal View History

2007-09-20 18:09:08 -04:00
! Copyright (C) 2005, 2007 Slava Pestov.
! See http://factorcode.org/license.txt for BSD license.
USING: arrays generic kernel math namespaces sequences words
2008-07-11 19:34:43 -04:00
splitting grouping math.vectors ui.gadgets.grids ui.gadgets
math.geometry.rect ;
2007-09-20 18:09:08 -04:00
IN: ui.gadgets.frames
! A frame arranges gadgets in a 3x3 grid, where the center
! gadgets gets left-over space.
TUPLE: frame < grid ;
2007-09-20 18:09:08 -04:00
: <frame-grid> ( -- grid ) 9 [ <gadget> ] 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
: 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-19 22:13:50 -05:00
: (fill-center) ( n vec -- )
[ [ 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-19 22:13:50 -05:00
[ [ rect-dim ] 2dip fill-center ] [ grid-layout ] 3bi ;