factor/extra/ui/frp/layout/layout.factor

43 lines
1.7 KiB
Factor
Raw Normal View History

2009-06-04 22:22:30 -04:00
USING: accessors assocs arrays fry kernel lexer make math math.parser
models models.product namespaces parser sequences
ui.frp.gadgets ui.gadgets ui.gadgets.books ui.gadgets.tracks
words tools.continuations ;
2009-05-24 10:36:24 -04:00
IN: ui.frp.layout
2009-06-04 22:22:30 -04:00
: <layout> ( gadget width -- gadget ) over set ;
2009-05-24 10:36:24 -04:00
2009-06-04 22:22:30 -04:00
SYNTAX: ,% scan string>number [ <layout> , ] curry over push-all ;
SYNTAX: ->% scan string>number '[ [ _ <layout> , ] [ output-model ] bi ] over push-all ;
2009-05-24 10:36:24 -04:00
GENERIC: -> ( uiitem -- model )
M: gadget -> dup , output-model ;
M: model -> dup , ;
2009-06-04 22:22:30 -04:00
: <spacer> ( -- ) <gadget> 1 <layout> , ;
SYMBOL: wordnames
2009-05-24 10:36:24 -04:00
: <box> ( gadgets type -- track )
2009-06-04 22:22:30 -04:00
[ { } make [ [ model? ] filter ] [ [ word? ] filter ] [ [ gadget? ] filter ] tri ] dip <track>
swap [ dup get track-add ] each
tuck [ [ swap 2array ] curry wordnames get swap change-at ] curry each
swap [ <product> >>model ] unless-empty ; inline
2009-05-24 10:36:24 -04:00
: <hbox> ( gadgets -- track ) horizontal <box> ; inline
: <vbox> ( gadgets -- track ) vertical <box> ; inline
2009-05-30 11:58:32 -04:00
2009-06-04 22:22:30 -04:00
: <frp-book> ( gadgets -- book ) { } make [ gadget>> ] map f <book> ; inline
SYNTAX: $ CREATE-WORD dup [ , ] curry (( -- )) define-declared "$" expect
word [ [ building get length swap wordnames get set-at ] [ , ] bi ] curry over push-all ;
GENERIC# insert-item 1 ( item location -- )
M: gadget insert-item first2 spin [ dup get track-add ] keep
-rot [ but-last insert-nth ] change-children drop ;
M: model insert-item first model>> swap add-connection ;
: insert-items ( makelist -- ) f swap [ dup word?
[ wordnames get at nip ] [ over insert-item ] if
] each drop ;
: with-interface ( quot: ( -- gadget ) -- gadget ) H{ } clone wordnames
[ { } make insert-items ] with-variable ; inline