]> gitweb.factorcode.org Git - factor.git/blob - unmaintained/drills/deployed/deployed.factor
20cdcb641d623c44f7af15dc0f2ea7914d0169da
[factor.git] / unmaintained / drills / deployed / deployed.factor
1 USING: arrays cocoa.dialogs combinators continuations
2 fry grouping io.encodings.utf8 io.files io.styles kernel math
3 math.parser models models.arrow models.history namespaces random
4 sequences splitting ui ui.gadgets.alerts ui.gadgets.book-extras
5 ui.gadgets.books ui.gadgets.buttons ui.gadgets.frames
6 ui.gadgets.grids ui.gadgets.labels ui.gadgets.tracks fonts
7 wrap.strings system ;
8 EXCLUDE: accessors => change-model ;
9 IN: drills.deployed
10 SYMBOLS: it startLength ;
11 : big ( gadget -- gadget ) T{ font { name "sans-serif" } { size 30 } } >>font ;
12 : card ( model quot -- button ) <arrow> <label-control> big [ next ] <book-btn> ;
13 : op ( quot str -- gadget ) <label> big swap <book-bevel-btn> ;
14
15 : show ( model -- gadget ) dup it set-global [ random ] <arrow>
16    { [ [ first ] card ]
17      [ [ second ] card ]
18      [ '[ |<< it get _ model-changed ] "No" op ]
19           [ '[ |<< [ it get [
20         _ value>> swap remove
21         [ [ it get go-back ] "Drill Complete" alert return ] when-empty
22      ] change-model ] with-return ] "Yes" op ]
23    } cleave
24 2array { 1 0 } <track> swap [ 0.5 track-add ] each
25 3array <book*> 3 3 <frame> { 1 1 } >>filled-cell { 450 175 } >>pref-dim swap { 1 1 } grid-add
26 it get [ length startLength get swap - number>string "/" startLength get number>string 3append ] <arrow> <label-control> { 1 2 } grid-add ;
27
28 : drill ( -- ) [
29    open-panel [
30          [ utf8 file-lines [ "\t" split [ 25 wrap-string ] map ] map dup [ first2 swap 2array ] map append ] map concat
31             [ length startLength set-global ] keep <history> [ add-history ] [ show ] bi
32          "Got it?" open-window
33    ] [ 0 exit ] if*
34 ] with-ui ;
35
36 MAIN: drill