2008-07-10 21:32:17 -04:00
|
|
|
! Copyright (C) 2006, 2008 Slava Pestov.
|
2007-09-20 18:09:08 -04:00
|
|
|
! See http://factorcode.org/license.txt for BSD license.
|
2008-11-28 01:02:02 -05:00
|
|
|
USING: accessors kernel sequences models ui.gadgets
|
|
|
|
math.geometry.rect fry ;
|
2007-09-20 18:09:08 -04:00
|
|
|
IN: ui.gadgets.books
|
|
|
|
|
2008-07-10 21:32:17 -04:00
|
|
|
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 -- )
|
2007-11-16 03:01:45 -05:00
|
|
|
nip
|
2007-09-20 18:09:08 -04:00
|
|
|
dup hide-all
|
|
|
|
dup current-page show-gadget
|
|
|
|
relayout ;
|
|
|
|
|
2008-12-22 06:40:38 -05:00
|
|
|
: new-book ( model class -- book )
|
2008-09-27 15:36:04 -04:00
|
|
|
new-gadget
|
2008-12-22 06:40:38 -05:00
|
|
|
swap >>model ; inline
|
2008-07-10 21:32:17 -04:00
|
|
|
|
2008-12-22 06:40:38 -05:00
|
|
|
: <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 -- )
|
2008-11-28 01:02:02 -05:00
|
|
|
[ 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 ;
|