USING: accessors arrays fry kernel lexer make math.parser models models.product namespaces parser sequences ui.frp.gadgets ui.gadgets ui.gadgets.books ui.gadgets.tracks vectors words combinators ; QUALIFIED: make IN: ui.frp.layout PREDICATE: true < word t = ; SYMBOL: inserting TUPLE: layout gadget size ; C: layout TUPLE: placeholder < gadget ; ERROR: no-models-in-books models ; DEFER: insert-item HOOK: , inserting ( uiitem -- ) M: f , make:, ; M: placeholder , [ inserting get insert-item ] keep relayout ; M: true , dup placeholder? [ inserting set ] [ "No location to add UI item" throw ] if ; SYNTAX: UI[ parse-quotation '[ [ t inserting _ with-variable ] ] 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 , ; : ,? ( uiitem -- ) inserting get parent>> children>> over [ [ unique ] bi@ = ] curry find drop [ drop ] [ , ] if ; : ->? ( uiitem -- model ) dup ,? output-model ; : ( -- ) 1 , ; : add-layout ( track layout -- track ) [ gadget>> ] [ size>> ] bi track-add ; inline : layouts ( sized? gadgets -- layouts ) [ [ gadget? ] [ layout? ] bi or ] filter swap [ [ dup layout? [ f ] unless ] map ] [ [ dup gadget? [ gadget>> ] unless ] map ] if ; : make-layout ( building sized? -- models layouts ) [ swap layouts ] curry [ { } make [ [ model? ] filter ] ] dip bi ; inline : ( gadgets type -- track ) [ t make-layout ] dip swap [ add-layout ] each swap [ >>model ] unless-empty ; inline : ( gadgets -- track ) horizontal ; inline : ( gadgets -- track ) vertical ; inline : make-book ( models gadgets model -- book ) swap [ no-models-in-books ] unless-empty ; : ( quot: ( -- model ) -- book ) f make-layout rot 0 >>value make-book ; inline : ( quot -- book ) f make-layout f make-book ; inline SYNTAX: $ CREATE-WORD placeholder new [ [ , ] curry (( -- )) define-declared "$" expect ] [ [ , ] curry ] bi over push-all ; : insert-gadget ( number parent gadget -- ) -rot [ but-last insert-nth ] change-children drop ; : insert-size ( number parent size -- ) -rot [ but-last insert-nth ] change-sizes drop ; : insertion-point ( gadget placeholder -- number parent gadget ) dup parent>> [ children>> index ] keep rot ; GENERIC# insert-item 1 ( item location -- ) M: gadget insert-item dup parent>> track? [ [ f ] dip insert-item ] [ insertion-point [ add-gadget ] keep insert-gadget ] if ; M: layout insert-item insertion-point [ add-layout ] keep [ gadget>> insert-gadget ] [ size>> insert-size ] 3bi ; M: model insert-item parent>> dup book? [ no-models-in-books ] [ dup model>> dup product? [ nip swap add-connection ] [ drop [ 1array ] dip (>>model) ] if ] if ; : insert-items ( makelist -- ) f swap [ dup placeholder? [ nip ] [ over insert-item ] if ] each drop ; : with-interface ( quot: ( -- gadget ) -- gadget ) { } make insert-items ; inline