From 47edda1f6618805c6b9538b655e77d292158e005 Mon Sep 17 00:00:00 2001 From: Sam Anklesaria Date: Sun, 31 May 2009 11:57:05 -0500 Subject: [PATCH] frp model activation changes --- extra/file-trees/file-trees.factor | 2 +- extra/ui/frp/gadgets/gadgets.factor | 21 +++++++++++++++++++-- extra/ui/frp/layout/layout.factor | 10 ++++------ extra/ui/frp/signals/signals-docs.factor | 2 +- extra/ui/frp/signals/signals.factor | 8 ++++---- 5 files changed, 29 insertions(+), 14 deletions(-) diff --git a/extra/file-trees/file-trees.factor b/extra/file-trees/file-trees.factor index fa9411cfbf..0329021f57 100644 --- a/extra/file-trees/file-trees.factor +++ b/extra/file-trees/file-trees.factor @@ -44,5 +44,5 @@ DEFER: (tree-insert) : ( tree-model -- table ) [ node>> 1array ] >>quot - [ selected-value>> [ file? not ] ] + [ selected-value>> [ file? not ] swap ] [ swap >>model ] bi ; \ No newline at end of file diff --git a/extra/ui/frp/gadgets/gadgets.factor b/extra/ui/frp/gadgets/gadgets.factor index 3568d4036d..7df9a4e8c9 100644 --- a/extra/ui/frp/gadgets/gadgets.factor +++ b/extra/ui/frp/gadgets/gadgets.factor @@ -33,12 +33,29 @@ M: table output-model dup multiple-selection?>> M: model-field output-model field-model>> ; M: scroller output-model viewport>> children>> first output-model ; +TUPLE: frp-field < field frp-model ; + +M: model-field graft* + [ [ field-model>> value>> ] [ editor>> ] bi set-editor-string ] + [ dup editor>> model>> add-connection ] + bi ; + +! frp-fields observe the underlying editor, relaying the string to the +! frp-model. Also, however, they relay the frp-model to the document and +! relayout + +! Frp boxes should unactivate all models attatched to them + +! Table gadgets should have slots for their illusions, not requireing manual activation +! and allowing deactivation an superior memory management + : ( -- field ) "" ; -: ( model -- field ) "" swap ; +: ( model -- field ) "" ; : ( model -- gadget ) model-field [ ] dip new-border dup gadget-child >>editor field-theme swap >>field-model { 1 0 } >>align ; -: ( model -- editor ) "" swap ; +: ( model -- editor ) "" ; +: after-empty ( model quot -- model' ) fmap "" ; inline IN: accessors M: frp-button text>> children>> first text>> ; \ No newline at end of file diff --git a/extra/ui/frp/layout/layout.factor b/extra/ui/frp/layout/layout.factor index 6e6689dce3..b2d888470d 100644 --- a/extra/ui/frp/layout/layout.factor +++ b/extra/ui/frp/layout/layout.factor @@ -1,5 +1,5 @@ USING: accessors fry kernel lexer math.parser models -sequences ui.frp.signals ui.gadgets.tracks ui.gadgets +sequences ui.gadgets.tracks ui.gadgets models.product ui.frp.gadgets ui.gadgets.books ; QUALIFIED: make IN: ui.frp.layout @@ -7,7 +7,7 @@ TUPLE: layout gadget width ; C: layout GENERIC: , ( uiitem -- ) M: gadget , f make:, ; -M: model , activate-model ; +M: model , make:, ; SYNTAX: ,% scan string>number [ make:, ] curry over push-all ; SYNTAX: ->% scan string>number '[ [ _ make:, ] [ output-model ] bi ] over push-all ; @@ -18,11 +18,9 @@ M: model -> dup , ; : ( -- ) 1 make:, ; : ( gadgets type -- track ) - [ { } make:make ] dip swap [ [ gadget>> ] [ width>> ] bi track-add ] each ; inline -: ( gadgets type -- track ) [ ] [ [ model>> ] map <|> ] bi >>model ; inline + [ { } make:make dup [ layout? ] filter ] dip swap [ [ gadget>> ] [ width>> ] bi track-add ] each + swap [ model? ] filter [ >>model ] unless-empty ; inline : ( gadgets -- track ) horizontal ; inline -: ( gadgets -- track ) horizontal ; inline : ( gadgets -- track ) vertical ; inline -: ( gadgets -- track ) vertical ; inline : ( gadgets -- book ) { } make:make [ gadget>> ] map f ; inline \ No newline at end of file diff --git a/extra/ui/frp/signals/signals-docs.factor b/extra/ui/frp/signals/signals-docs.factor index 2cc455c7ff..e2b14234e1 100644 --- a/extra/ui/frp/signals/signals-docs.factor +++ b/extra/ui/frp/signals/signals-docs.factor @@ -15,7 +15,7 @@ HELP: HELP: { $values { "signal1" model } { "signal2" model } { "signal'" model } } -{ $description "Creates a signal that starts with the behavior of signal1 and switches to the behavior of signal2 on its update" } ; +{ $description "Creates a signal that starts with the behavior of signal2 and switches to the behavior of signal1 on its update" } ; HELP: { $values { "model" model } { "quot" "applied to model's value on updates" } { "signal" model } } diff --git a/extra/ui/frp/signals/signals.factor b/extra/ui/frp/signals/signals.factor index 650acb37c8..145c25c0d6 100644 --- a/extra/ui/frp/signals/signals.factor +++ b/extra/ui/frp/signals/signals.factor @@ -35,10 +35,10 @@ TUPLE: switch-model < multi-model original switcher on ; M: switch-model (model-changed) 2dup switcher>> = [ [ value>> ] [ t >>on ] bi* set-model ] [ dup on>> [ 2drop ] [ [ value>> ] dip set-model ] if ] if ; -: ( signal1 signal2 -- signal' ) [ 2array switch-model ] 2keep +: ( signal1 signal2 -- signal' ) swap [ 2array switch-model ] 2keep [ >>original ] [ >>switcher ] bi* ; M: switch-model model-activated [ original>> ] keep model-changed ; -: >behavior ( event -- behavior ) t swap ; +: >behavior ( event -- behavior ) t ; TUPLE: mapped-model < multi-model model quot ; : new-mapped-model ( model quot class -- mapped-model ) [ over 1array ] dip @@ -64,7 +64,7 @@ TUPLE: action < multi-model quot ; M: action (model-changed) [ [ value>> ] [ quot>> ] bi* call( a -- b ) ] keep value>> [ swap add-connection ] 2keep model-changed ; : ( model quot -- action-signal ) [ 1array action ] dip >>quot dup f >>value value>> ; - + ( models -- product ) | ; GENERIC: models-changed ( product -- ) @@ -82,5 +82,5 @@ M: | model-activated dup model-changed ; TUPLE: & < | ; : <&> ( models -- product ) & ; M: & models-changed dependencies>> [ f swap (>>value) ] each ; - +PRIVATE> FMAPS: $> <$ fmap FOR & | ; \ No newline at end of file