factor/unmaintained/drills/drills.factor

37 lines
1.6 KiB
Factor
Raw Normal View History

USING: arrays cocoa.dialogs combinators continuations
2009-03-09 21:39:48 -04:00
fry grouping io.encodings.utf8 io.files io.styles kernel math
math.parser models models.arrow models.history namespaces random
2009-03-09 21:39:48 -04:00
sequences splitting ui ui.gadgets.alerts ui.gadgets.book-extras
ui.gadgets.books ui.gadgets.buttons ui.gadgets.frames
2009-04-25 00:24:23 -04:00
ui.gadgets.grids ui.gadgets.labels ui.gadgets.tracks fonts
wrap.strings ;
EXCLUDE: accessors => change-model ;
2009-03-09 21:39:48 -04:00
IN: drills
SYMBOLS: it startLength ;
2009-04-25 00:24:23 -04:00
: big ( gadget -- gadget ) T{ font { name "sans-serif" } { size 30 } } >>font ;
: card ( model quot -- button ) <arrow> <label-control> big [ next ] <book-btn> ;
2009-05-30 11:58:32 -04:00
: op ( quot str -- gadget ) <label> big swap <book-border-btn> ;
2009-03-09 21:39:48 -04:00
: show ( model -- gadget ) dup it set-global [ random ] <arrow>
2009-03-09 21:39:48 -04:00
{ [ [ first ] card ]
2009-04-25 00:24:23 -04:00
[ [ second ] card ]
[ '[ |<< it get _ model-changed ] "No" op ]
[ '[ |<< [ it get [
_ value>> swap remove
[ [ it get go-back ] "Drill Complete" alert return ] when-empty
] change-model ] with-return ] "Yes" op ]
} cleave
2009-03-09 21:39:48 -04:00
2array { 1 0 } <track> swap [ 0.5 track-add ] each
2009-04-25 00:24:23 -04:00
3array <book*> 3 3 <frame> { 1 1 } >>filled-cell { 450 175 } >>pref-dim swap { 1 1 } grid-add
it get [ length startLength get swap - number>string "/" startLength get number>string 3append ] <arrow> <label-control> { 1 2 } grid-add ;
2009-03-09 21:39:48 -04:00
2009-04-25 00:24:23 -04:00
: drill ( -- ) [
2009-03-09 21:39:48 -04:00
open-panel [
2009-04-25 00:24:23 -04:00
[ utf8 file-lines [ "\t" split [ 25 wrap-string ] map ] map dup [ first2 swap 2array ] map append ] map concat
[ length startLength set-global ] keep <history> [ add-history ] [ show ] bi
"Got it?" open-window
2009-03-09 21:39:48 -04:00
] when*
] with-ui ;
2009-04-25 00:24:23 -04:00
MAIN: drill