factor/extra/slides/slides.factor

112 lines
3.1 KiB
Factor
Raw Normal View History

2010-01-14 10:10:13 -05:00
! Copyright (C) 2007, 2010 Slava Pestov.
! See http://factorcode.org/license.txt for BSD license.
USING: accessors arrays colors fonts fry help.markup help.stylesheet
io.styles kernel literals math math.ranges models namespaces parser
sequences system ui ui.gadgets ui.gadgets.books ui.gadgets.panes
ui.gestures ui.pens.gradient ui.pens.solid ;
2007-09-20 18:09:08 -04:00
IN: slides
CONSTANT: stylesheet
2007-09-20 18:09:08 -04:00
H{
{ default-style
2007-09-20 18:09:08 -04:00
H{
{ font-name $ default-sans-serif-font-name }
{ font-size $[ default-font-size 3 * ] }
{ wrap-margin $[ default-font-size 92 * ] }
2007-09-20 18:09:08 -04:00
}
}
{ code-style
2007-09-20 18:09:08 -04:00
H{
{ font-name $ default-monospace-font-name }
{ font-size $[ default-font-size 3 * ] }
{ 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-name $ default-monospace-font-name }
{ font-size $[ default-font-size 3 * ] }
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
H{ { wrap-margin $[ default-font-size 83 * ] } }
2007-09-20 18:09:08 -04:00
}
{ list-style
H{
{ table-gap ${ default-font-size 5/6 *
default-font-size 10/6 * }
}
}
2007-09-20 18:09:08 -04:00
}
}
2007-09-20 18:09:08 -04:00
: $title ( string -- )
2015-08-05 00:05:31 -04:00
[
H{
{ font-name $ default-sans-serif-font-name }
{ font-size $[ default-font-size 4 * ] }
2015-08-05 00:05:31 -04:00
} format
] ($block) ;
2007-09-20 18:09:08 -04:00
: $divider ( -- )
[
<gadget>
{
T{ rgba f 0.25 0.25 0.25 1.0 }
T{ rgba f 1.0 1.0 1.0 0.0 }
} <gradient> >>interior
${ default-font-size 67 * default-font-size 5/6 * } >>dim
2015-08-05 00:05:31 -04:00
{ 1 0 } >>orientation
2007-09-20 18:09:08 -04:00
gadget.
] ($block) ;
2015-08-05 00:05:31 -04:00
: page-theme ( gadget -- gadget )
{
T{ rgba f 0.8 0.8 1.0 1.0 }
T{ rgba f 0.8 1.0 1.0 1.0 }
} <gradient> >>interior ;
2007-09-20 18:09:08 -04:00
: <page> ( list -- gadget )
[
stylesheet clone [
[ print-element ] with-default-style
] with-variables
2015-08-05 00:05:31 -04:00
] make-pane page-theme ;
2007-09-20 18:09:08 -04:00
: $slide ( element -- )
2015-08-05 00:05:31 -04:00
unclip $title $divider $list ;
2007-09-20 18:09:08 -04:00
TUPLE: slides < book ;
2007-09-20 18:09:08 -04:00
: <slides> ( slides -- gadget )
0 <model> slides new-book [ <page> add-gadget ] reduce ;
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 set-control-value ;
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 -- seq )
2015-08-05 00:05:31 -04:00
first3 2 over length [a,b] [ head 3array ] with with with map ;
2008-01-10 15:45:54 -05:00
SYNTAX: STRIP-TEASE:
2015-08-05 00:05:31 -04:00
parse-definition strip-tease append! ;
2008-01-10 15:45:54 -05:00
2007-09-20 18:09:08 -04:00
\ slides H{
{ T{ button-down } [ request-focus ] }
2015-10-25 11:33:53 -04:00
{ T{ key-down f f " " } [ next-page ] }
2007-09-20 18:09:08 -04:00
{ T{ key-down f f "DOWN" } [ next-page ] }
{ T{ key-down f f "b" } [ prev-page ] }
2007-09-20 18:09:08 -04:00
{ T{ key-down f f "UP" } [ prev-page ] }
2015-10-25 11:33:53 -04:00
{ T{ key-down f f "q" } [ close-window ] }
{ T{ key-down f f "ESC" } [ close-window ] }
2015-08-05 00:09:04 -04:00
{ T{ key-down f f "f" } [ toggle-fullscreen ] }
2007-09-20 18:09:08 -04:00
} set-gestures
: slides-window ( slides title -- )
'[ _ <slides> _ open-window ] with-ui ;