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-07-11 19:34:43 -04:00
|
|
|
USING: accessors kernel sequences models ui.gadgets math.geometry.rect ;
|
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
|
|
|
|
|
|
|
|
: hide-all ( book -- ) gadget-children [ hide-gadget ] each ;
|
|
|
|
|
|
|
|
|
|
: current-page ( book -- gadget )
|
|
|
|
|
[ control-value ] keep nth-gadget ;
|
|
|
|
|
|
2007-11-16 03:01:45 -05:00
|
|
|
M: book model-changed
|
|
|
|
|
nip
|
2007-09-20 18:09:08 -04:00
|
|
|
dup hide-all
|
|
|
|
|
dup current-page show-gadget
|
|
|
|
|
relayout ;
|
|
|
|
|
|
2008-07-10 21:32:17 -04:00
|
|
|
: new-book ( pages model class -- book )
|
|
|
|
|
new-gadget
|
|
|
|
|
swap >>model
|
2008-07-13 02:25:44 -04:00
|
|
|
[ swap add-gadgets drop ] keep ; inline
|
2008-07-10 21:32:17 -04:00
|
|
|
|
2007-09-20 18:09:08 -04:00
|
|
|
: <book> ( pages model -- book )
|
2008-07-10 21:32:17 -04:00
|
|
|
book new-book ;
|
2007-09-20 18:09:08 -04:00
|
|
|
|
|
|
|
|
M: book pref-dim* gadget-children pref-dims max-dim ;
|
|
|
|
|
|
|
|
|
|
M: book layout*
|
|
|
|
|
dup rect-dim swap gadget-children
|
2008-01-09 17:36:30 -05:00
|
|
|
[ set-layout-dim ] with each ;
|
2007-09-20 18:09:08 -04:00
|
|
|
|
|
|
|
|
M: book focusable-child* current-page ;
|