2009-04-28 21:37:25 -04:00
|
|
|
USING: accessors arrays colors fonts fry kernel models
|
|
|
|
|
models.product monads sequences ui.gadgets ui.gadgets.buttons
|
|
|
|
|
ui.gadgets.editors ui.gadgets.line-support ui.gadgets.tables
|
|
|
|
|
ui.gadgets.tracks ui.render ;
|
2009-04-25 00:25:16 -04:00
|
|
|
QUALIFIED: make
|
|
|
|
|
IN: ui.frp
|
|
|
|
|
|
2009-04-28 21:37:25 -04:00
|
|
|
! Gadgets
|
|
|
|
|
: <frp-button> ( text -- button ) [ t swap set-control-value ] <border-button> f <model> >>model ;
|
|
|
|
|
TUPLE: frp-table < table quot val-quot color-quot column-titles column-alignment ;
|
|
|
|
|
M: frp-table column-titles column-titles>> ;
|
|
|
|
|
M: frp-table column-alignment column-alignment>> ;
|
2009-04-28 23:00:21 -04:00
|
|
|
M: frp-table row-columns quot>> [ call( a -- b ) ] [ drop f ] if* ;
|
|
|
|
|
M: frp-table row-value val-quot>> [ call( a -- b ) ] [ drop f ] if* ;
|
|
|
|
|
M: frp-table row-color color-quot>> [ call( a -- b ) ] [ drop f ] if* ;
|
2009-04-28 21:37:25 -04:00
|
|
|
|
2009-05-01 12:06:48 -04:00
|
|
|
: <frp-table> ( model -- table )
|
|
|
|
|
frp-table new-line-gadget dup >>renderer [ ] >>quot swap >>model
|
2009-04-28 21:37:25 -04:00
|
|
|
f <model> >>selected-value sans-serif-font >>font
|
|
|
|
|
focus-border-color >>focus-border-color
|
|
|
|
|
transparent >>column-line-color ;
|
2009-05-01 12:06:48 -04:00
|
|
|
: <frp-list> ( model -- table ) <frp-table> [ 1array ] >>quot ;
|
2009-04-28 21:37:25 -04:00
|
|
|
: <frp-field> ( -- field ) f <model> <model-field> ;
|
|
|
|
|
|
2009-04-25 00:25:16 -04:00
|
|
|
! Layout utilities
|
|
|
|
|
|
2009-04-26 20:01:05 -04:00
|
|
|
GENERIC: output-model ( gadget -- model )
|
|
|
|
|
M: gadget output-model model>> ;
|
|
|
|
|
M: frp-table output-model selected-value>> ;
|
|
|
|
|
|
2009-05-01 12:06:48 -04:00
|
|
|
GENERIC: , ( uiitem -- )
|
2009-04-25 00:25:16 -04:00
|
|
|
M: gadget , make:, ;
|
|
|
|
|
M: model , activate-model ;
|
|
|
|
|
|
2009-05-01 12:06:48 -04:00
|
|
|
GENERIC: -> ( uiitem -- model )
|
2009-04-26 20:01:05 -04:00
|
|
|
M: gadget -> dup make:, output-model ;
|
2009-04-25 00:25:16 -04:00
|
|
|
M: model -> dup , ;
|
2009-04-28 21:37:25 -04:00
|
|
|
M: table -> dup , selected-value>> ;
|
2009-04-25 00:25:16 -04:00
|
|
|
|
2009-04-29 15:19:30 -04:00
|
|
|
: <box> ( gadgets type -- track )
|
|
|
|
|
[ { } make:make ] dip <track> swap [ f track-add ] each ; inline
|
|
|
|
|
: <box*> ( gadgets type -- track ) [ <box> ] [ [ model>> ] map <product> ] bi >>model ; inline
|
|
|
|
|
: <hbox> ( gadgets -- track ) horizontal <box> ; inline
|
|
|
|
|
: <vbox> ( gadgets -- track ) vertical <box> ; inline
|
2009-04-25 00:25:16 -04:00
|
|
|
|
|
|
|
|
! Model utilities
|
|
|
|
|
TUPLE: multi-model < model ;
|
|
|
|
|
! M: multi-model model-activated dup model-changed ;
|
|
|
|
|
: <multi-model> ( models kind -- model ) f swap new-model [ [ add-dependency ] curry each ] keep ;
|
|
|
|
|
|
|
|
|
|
TUPLE: merge-model < multi-model ;
|
|
|
|
|
M: merge-model model-changed [ value>> ] dip set-model ;
|
|
|
|
|
: <merge> ( models -- model ) merge-model <multi-model> ;
|
|
|
|
|
|
|
|
|
|
TUPLE: filter-model < multi-model quot ;
|
|
|
|
|
M: filter-model model-changed [ value>> ] dip [ quot>> call( val -- bool ) ] 2keep
|
|
|
|
|
[ set-model ] [ 2drop ] if ;
|
|
|
|
|
: <filter> ( model quot -- filter-model ) [ 1array filter-model <multi-model> ] dip >>quot ;
|
|
|
|
|
|
|
|
|
|
TUPLE: fold-model < multi-model oldval quot ;
|
|
|
|
|
M: fold-model model-changed [ [ value>> ] [ [ oldval>> ] [ quot>> ] bi ] bi*
|
|
|
|
|
call( val oldval -- newval ) ] keep set-model ;
|
|
|
|
|
: <fold> ( oldval quot model -- model' ) 1array fold-model <multi-model> swap >>quot swap >>oldval ;
|
|
|
|
|
|
|
|
|
|
TUPLE: switch-model < multi-model switcher on ;
|
|
|
|
|
M: switch-model model-changed tuck [ switcher>> = ] 2keep
|
|
|
|
|
'[ on>> [ _ value>> _ set-model ] when ] [ t swap (>>on) ] if ;
|
|
|
|
|
: switch ( signal1 signal2 -- signal' ) [ 2array switch-model <multi-model> ] keep >>switcher ;
|
|
|
|
|
|
|
|
|
|
TUPLE: mapped < model model quot ;
|
|
|
|
|
|
|
|
|
|
: <mapped> ( model quot -- arrow )
|
|
|
|
|
f mapped new-model
|
|
|
|
|
swap >>quot
|
|
|
|
|
over >>model
|
|
|
|
|
[ add-dependency ] keep ;
|
|
|
|
|
|
|
|
|
|
M: mapped model-changed
|
|
|
|
|
[ [ value>> ] [ quot>> ] bi* call( old -- new ) ] [ nip ] 2bi
|
|
|
|
|
set-model ;
|
|
|
|
|
|
|
|
|
|
! Instances
|
|
|
|
|
M: model fmap <mapped> ;
|
|
|
|
|
|
|
|
|
|
SINGLETON: gadget-monad
|
|
|
|
|
INSTANCE: gadget-monad monad
|
|
|
|
|
INSTANCE: gadget monad
|
|
|
|
|
M: gadget monad-of drop gadget-monad ;
|
|
|
|
|
M: gadget-monad return drop <gadget> swap >>model ;
|
2009-04-28 21:37:25 -04:00
|
|
|
M: gadget >>= model>> '[ _ swap call( x -- y ) ] ;
|