From b74b8478f3ad86365c59078d03621551ac81d64f Mon Sep 17 00:00:00 2001 From: Sam Anklesaria Date: Thu, 4 Jun 2009 21:22:30 -0500 Subject: [PATCH] ui.frp templates separate model, view --- extra/ui/frp/layout/layout.factor | 45 +++++++++++++++++++++---------- 1 file changed, 31 insertions(+), 14 deletions(-) diff --git a/extra/ui/frp/layout/layout.factor b/extra/ui/frp/layout/layout.factor index b2d888470d..ce2f8ed098 100644 --- a/extra/ui/frp/layout/layout.factor +++ b/extra/ui/frp/layout/layout.factor @@ -1,26 +1,43 @@ -USING: accessors fry kernel lexer math.parser models -sequences ui.gadgets.tracks ui.gadgets models.product -ui.frp.gadgets ui.gadgets.books ; -QUALIFIED: make +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 ; IN: ui.frp.layout -TUPLE: layout gadget width ; C: layout -GENERIC: , ( uiitem -- ) -M: gadget , f make:, ; -M: model , make:, ; +: ( gadget width -- gadget ) over set ; -SYNTAX: ,% scan string>number [ make:, ] curry over push-all ; -SYNTAX: ->% scan string>number '[ [ _ make:, ] [ output-model ] bi ] over push-all ; +SYNTAX: ,% scan string>number [ , ] curry over push-all ; +SYNTAX: ->% scan string>number '[ [ _ , ] [ output-model ] bi ] over push-all ; GENERIC: -> ( uiitem -- model ) M: gadget -> dup , output-model ; M: model -> dup , ; -: ( -- ) 1 make:, ; +: ( -- ) 1 , ; + +SYMBOL: wordnames + : ( gadgets type -- track ) - [ { } make:make dup [ layout? ] filter ] dip swap [ [ gadget>> ] [ width>> ] bi track-add ] each - swap [ model? ] filter [ >>model ] unless-empty ; inline + [ { } make [ [ model? ] filter ] [ [ word? ] filter ] [ [ gadget? ] filter ] tri ] dip + swap [ dup get track-add ] each + tuck [ [ swap 2array ] curry wordnames get swap change-at ] curry each + swap [ >>model ] unless-empty ; inline : ( gadgets -- track ) horizontal ; inline : ( gadgets -- track ) vertical ; inline -: ( gadgets -- book ) { } make:make [ gadget>> ] map f ; inline \ No newline at end of file +: ( gadgets -- book ) { } make [ gadget>> ] map f ; 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 \ No newline at end of file