factor/core/ui/gadgets/controls.factor

37 lines
925 B
Factor
Raw Normal View History

! Copyright (C) 2006 Slava Pestov.
! See http://factorcode.org/license.txt for BSD license.
2006-10-03 18:17:21 -04:00
USING: kernel models ;
IN: gadgets
2006-09-16 17:11:55 -04:00
TUPLE: control self model quot ;
: (delegate>control) ( tuple gadget -- )
over set-gadget-delegate dup set-control-self ;
C: control ( model gadget quot -- gadget )
[ set-control-quot ] keep
[ swap (delegate>control) ] keep
[ set-control-model ] keep ;
: control-value ( control -- value )
control-model model-value ;
: set-control-value ( value control -- )
control-model set-model ;
2006-10-03 18:17:21 -04:00
M: control graft*
2006-10-03 18:17:21 -04:00
control-self dup dup control-model add-connection
model-changed ;
M: control ungraft*
2006-10-03 18:17:21 -04:00
control-self dup control-model remove-connection ;
M: control model-changed
2006-10-03 18:17:21 -04:00
control-self
[ control-value ] keep
[ dup control-quot call ] keep
relayout ;
: delegate>control ( tuple model underlying -- )
[ 2drop ] <control> (delegate>control) ;