factor/basis/ui/gadgets/books/books.factor

35 lines
882 B
Factor
Raw Normal View History

! Copyright (C) 2006, 2008 Slava Pestov.
2007-09-20 18:09:08 -04:00
! See http://factorcode.org/license.txt for BSD license.
USING: accessors kernel sequences models ui.gadgets
math.geometry.rect fry ;
2007-09-20 18:09:08 -04:00
IN: ui.gadgets.books
TUPLE: book < gadget ;
2007-09-20 18:09:08 -04:00
2008-08-29 19:44:19 -04:00
: hide-all ( book -- ) children>> [ hide-gadget ] each ;
2007-09-20 18:09:08 -04:00
2008-07-15 14:50:42 -04:00
: current-page ( book -- gadget ) [ control-value ] keep nth-gadget ;
2007-09-20 18:09:08 -04:00
2008-07-15 14:50:42 -04:00
M: book model-changed ( model book -- )
nip
2007-09-20 18:09:08 -04:00
dup hide-all
dup current-page show-gadget
relayout ;
: new-book ( model class -- book )
new-gadget
swap >>model ; inline
: <book> ( pages model -- book )
book new-book swap add-gadgets ;
: <empty-book> ( model -- book )
book new-book ;
2007-09-20 18:09:08 -04:00
2008-07-15 14:50:42 -04:00
M: book pref-dim* ( book -- dim ) children>> pref-dims max-dim ;
2007-09-20 18:09:08 -04:00
2008-07-15 14:50:42 -04:00
M: book layout* ( book -- )
[ children>> ] [ dim>> ] bi '[ _ >>dim drop ] each ;
2007-09-20 18:09:08 -04:00
2008-07-15 14:50:42 -04:00
M: book focusable-child* ( book -- child/t ) current-page ;