factor/extra/slides/slides.factor

108 lines
2.5 KiB
Factor
Raw Normal View History

! Copyright (C) 2007, 2008 Slava Pestov.
! See http://factorcode.org/license.txt for BSD license.
2007-09-20 18:09:08 -04:00
USING: arrays hashtables help.markup help.stylesheet io
io.styles kernel math models namespaces sequences ui ui.gadgets
2008-01-10 15:48:30 -05:00
ui.gadgets.books ui.gadgets.panes ui.gestures ui.render
2008-07-29 20:09:00 -04:00
parser accessors colors ;
2007-09-20 18:09:08 -04:00
IN: slides
: stylesheet
H{
{ default-span-style
2007-09-20 18:09:08 -04:00
H{
{ font "sans-serif" }
{ font-size 36 }
}
}
{ default-block-style
H{
2008-10-28 19:18:47 -04:00
{ wrap-margin 1100 }
2007-09-20 18:09:08 -04:00
}
}
{ code-style
H{
{ font "monospace" }
{ font-size 36 }
2008-07-28 18:01:08 -04:00
{ page-color T{ rgba f 0.4 0.4 0.4 0.3 } }
2007-09-20 18:09:08 -04:00
}
}
{ snippet-style
H{
{ font "monospace" }
{ font-size 36 }
2008-07-28 18:01:08 -04:00
{ foreground T{ rgba f 0.1 0.1 0.4 1 } }
2007-09-20 18:09:08 -04:00
}
}
{ table-content-style
2008-10-28 19:18:47 -04:00
H{ { wrap-margin 1000 } }
2007-09-20 18:09:08 -04:00
}
{ list-style
H{ { table-gap { 10 20 } } }
}
{ bullet "\u0000b7" }
2007-09-20 18:09:08 -04:00
} ;
: $title ( string -- )
[ H{ { font "sans-serif" } { font-size 48 } } format ] ($block) ;
: $divider ( -- )
[
<gadget>
2008-11-17 22:45:23 -05:00
{
T{ rgba f 0.25 0.25 0.25 1.0 }
T{ rgba f 1.0 1.0 1.0 0.0 }
} <gradient> >>interior
2008-07-22 22:26:28 -04:00
{ 800 10 } >>dim
{ 1 0 } >>orientation
2007-09-20 18:09:08 -04:00
gadget.
] ($block) ;
: page-theme ( gadget -- )
2008-11-17 22:45:23 -05:00
{ T{ rgba f 0.8 0.8 1.0 1.0 } T{ rgba f 0.8 1.0 1.0 1.0 } } <gradient>
2008-09-02 13:35:42 -04:00
>>interior drop ;
2007-09-20 18:09:08 -04:00
: <page> ( list -- gadget )
[
stylesheet clone [
[ print-element ] with-default-style
] bind
] make-pane
dup page-theme ;
: $slide ( element -- )
unclip $title
$divider
$list ;
TUPLE: slides < book ;
2007-09-20 18:09:08 -04:00
: <slides> ( slides -- gadget )
[ <page> ] map 0 <model> slides new-book ;
2007-09-20 18:09:08 -04:00
: change-page ( book n -- )
2008-09-02 13:35:42 -04:00
over control-value + over children>> length rem
swap model>> set-model ;
2007-09-20 18:09:08 -04:00
: next-page ( book -- ) 1 change-page ;
: prev-page ( book -- ) -1 change-page ;
2008-01-10 15:45:54 -05:00
: (strip-tease) ( data n -- data )
>r first3 r> head 3array ;
: strip-tease ( data -- seq )
2008-01-12 17:23:34 -05:00
dup third length 1- [
2008-01-10 15:45:54 -05:00
2 + (strip-tease)
] with map ;
: STRIP-TEASE:
parse-definition strip-tease [ parsed ] each ; parsing
2007-09-20 18:09:08 -04:00
\ slides H{
{ T{ key-down f f "DOWN" } [ next-page ] }
{ T{ key-down f f "UP" } [ prev-page ] }
} set-gestures
: slides-window ( slides -- )
[ <slides> "Slides" open-window ] with-ui ;