pry off some ui app boilerplate with a MAIN-WINDOW: syntax

db4
Joe Groff 2010-01-15 16:55:43 -08:00
parent 9dc5d18b1c
commit 4beb8192c9
17 changed files with 71 additions and 90 deletions

View File

@ -133,7 +133,7 @@ M: world request-focus-on ( child gadget -- )
[ window-controls>> >>window-controls ] [ window-controls>> >>window-controls ]
[ initial-background-color >>background-color ] [ initial-background-color >>background-color ]
[ grab-input?>> >>grab-input? ] [ grab-input?>> >>grab-input? ]
[ gadgets>> [ 1 track-add ] each ] [ gadgets>> dup sequence? [ [ 1 track-add ] each ] [ 1 track-add ] if ]
[ pref-dim>> >>pref-dim ] [ pref-dim>> >>pref-dim ]
} cleave ; } cleave ;

View File

@ -5,7 +5,7 @@ deques sequences threads words continuations init
combinators combinators.short-circuit hashtables concurrency.flags combinators combinators.short-circuit hashtables concurrency.flags
sets accessors calendar fry destructors ui.gadgets ui.gadgets.private sets accessors calendar fry destructors ui.gadgets ui.gadgets.private
ui.gadgets.worlds ui.gadgets.tracks ui.gestures ui.backend ui.render ui.gadgets.worlds ui.gadgets.tracks ui.gestures ui.backend ui.render
strings ; strings classes.tuple classes.tuple.parser lexer vocabs.parser parser ;
IN: ui IN: ui
<PRIVATE <PRIVATE
@ -242,3 +242,15 @@ M: object close-window
ui-running? [ call( -- ) ] [ '[ init-ui @ ] (with-ui) ] if ; ui-running? [ call( -- ) ] [ '[ init-ui @ ] (with-ui) ] if ;
HOOK: beep ui-backend ( -- ) HOOK: beep ui-backend ( -- )
: parse-main-window ( class -- attributes quot )
"{" expect dup all-slots parse-tuple-literal-slots
parse-definition ;
: define-main-window ( word attributes quot -- )
[
'[ [ f _ @ open-window ] with-ui ] (( -- )) define-declared
] [ 2drop current-vocab (>>main) ] 3bi ;
SYNTAX: MAIN-WINDOW:
CREATE world-attributes parse-main-window define-main-window ;

View File

@ -44,16 +44,12 @@ M: bunny-world draw-world*
[ geom>> ] [ get-draw ] bi draw-bunny [ geom>> ] [ get-draw ] bi draw-bunny
] if ; ] if ;
M: bunny-world pref-dim* ( gadget -- dim )
drop { 640 480 } ;
bunny-world H{ bunny-world H{
{ T{ key-down f f "TAB" } [ next-draw ] } { T{ key-down f f "TAB" } [ next-draw ] }
} set-gestures } set-gestures
: bunny-window ( -- ) MAIN-WINDOW: bunny-window
[ {
f T{ world-attributes
{ world-class bunny-world } { world-class bunny-world }
{ title "Bunny" } { title "Bunny" }
{ pixel-format-attributes { { pixel-format-attributes {
@ -61,7 +57,5 @@ bunny-world H{
double-buffered double-buffered
T{ depth-bits { value 16 } } T{ depth-bits { value 16 } }
} } } }
} open-window { pref-dim { 640 480 } }
] with-ui ; } ;
MAIN: bunny-window

View File

@ -1,6 +1,6 @@
! Copyright (C) 2006, 2009 Slava Pestov. ! Copyright (C) 2006, 2009 Slava Pestov.
! See http://factorcode.org/license.txt for BSD license. ! See http://factorcode.org/license.txt for BSD license.
USING: kernel math math.functions math.parser models USING: arrays kernel math math.functions math.parser models
models.arrow models.range models.product sequences ui models.arrow models.range models.product sequences ui
ui.gadgets ui.gadgets.tracks ui.gadgets.labels ui.gadgets.packs ui.gadgets ui.gadgets.tracks ui.gadgets.labels ui.gadgets.packs
ui.gadgets.sliders ui.pens.solid ui.render math.rectangles accessors ui.gadgets.sliders ui.pens.solid ui.render math.rectangles accessors
@ -45,7 +45,5 @@ M: color-preview model-changed
] bi ] bi
] bi* ; ] bi* ;
: color-picker-window ( -- ) MAIN-WINDOW: color-picker-window { { title "Color Picker" } }
[ <color-picker> "Color Picker" open-window ] with-ui ; <color-picker> >>gadgets ;
MAIN: color-picker-window

View File

@ -37,7 +37,5 @@ M: color-renderer row-value
10 >>min-rows 10 >>min-rows
10 >>max-rows ; 10 >>max-rows ;
: color-table-demo ( -- ) MAIN-WINDOW: color-table-demo { { title "Colors" } }
[ <color-table> <scroller> "Colors" open-window ] with-ui ; <color-table> <scroller> >>gadgets ;
MAIN: color-table-demo

View File

@ -11,6 +11,5 @@ IN: demos
: <demo-runner> ( -- gadget ) : <demo-runner> ( -- gadget )
<pile> 1 >>fill { 2 2 } >>gap demo-vocabs [ <run-vocab-button> add-gadget ] each ; <pile> 1 >>fill { 2 2 } >>gap demo-vocabs [ <run-vocab-button> add-gadget ] each ;
: demos ( -- ) [ <demo-runner> { 2 2 } <border> <scroller> "Demos" open-window ] with-ui ; MAIN-WINDOW: demos { { title "Demos" } }
<demo-runner> { 2 2 } <border> <scroller> >>gadgets ;
MAIN: demos

View File

@ -1,7 +1,5 @@
USING: ui ui.gadgets.labels ; USING: accessors ui ui.gadgets.labels ;
IN: hello-ui IN: hello-ui
: hello ( -- ) MAIN-WINDOW: hello { { title "Hi" } }
[ "Hello world" <label> "Hi" open-window ] with-ui ; "Hello world" <label> >>gadgets ;
MAIN: hello

View File

@ -1,6 +1,6 @@
! Copyright (C) 2009 Slava Pestov. ! Copyright (C) 2009 Slava Pestov.
! See http://factorcode.org/license.txt for BSD license. ! See http://factorcode.org/license.txt for BSD license.
USING: ui.gadgets.panes ui.gadgets.borders ui io io.styles ; USING: accessors ui.gadgets.panes ui.gadgets.borders ui io io.styles ;
IN: hello-unicode IN: hello-unicode
: <hello-gadget> ( -- gadget ) : <hello-gadget> ( -- gadget )
@ -15,6 +15,5 @@ IN: hello-unicode
] with-style ] with-style
] make-pane { 10 10 } <border> ; ] make-pane { 10 10 } <border> ;
: hello-unicode ( -- ) [ <hello-gadget> "გამარჯობა" open-window ] with-ui ; MAIN-WINDOW: hello-unicode { { title "გამარჯობა" } }
<hello-gadget> >>gadgets ;
MAIN: hello-unicode

View File

@ -79,7 +79,5 @@ jamshred-gadget H{
{ mouse-scroll [ handle-mouse-scroll ] } { mouse-scroll [ handle-mouse-scroll ] }
} set-gestures } set-gestures
: jamshred-window ( -- ) MAIN-WINDOW: jamshred-window { { title "Jamshred" } }
[ <jamshred> <jamshred-gadget> "Jamshred" open-window ] with-ui ; <jamshred> <jamshred-gadget> >>gadgets ;
MAIN: jamshred-window

View File

@ -24,7 +24,5 @@ IN: lcd
"99:99:99" lcd >>string "99:99:99" lcd >>string
monospace-font >>font ; monospace-font >>font ;
: time-window ( -- ) MAIN-WINDOW: time-window { { title "Time" } }
[ time get <time-display> "Time" open-window ] with-ui ; time get <time-display> >>gadgets ;
MAIN: time-window

View File

@ -61,7 +61,7 @@ M: maze draw-gadget* [ n draw-maze ] draw-canvas ;
M: maze pref-dim* drop { 400 400 } ; M: maze pref-dim* drop { 400 400 } ;
: maze-window ( -- ) MAIN-WINDOW: maze-window { { title "Maze" } }
[ <maze> "Maze" open-window ] with-ui ; <maze> >>gadgets ;
MAIN: maze-window MAIN: maze-window

View File

@ -4,7 +4,11 @@ ui.gadgets ui.gadgets.buttons ui.gadgets.labeled
ui.gadgets.tracks ui.gadgets.labels ui.gadgets.glass ui.gadgets.tracks ui.gadgets.labels ui.gadgets.glass
math.rectangles cocoa.dialogs ; math.rectangles cocoa.dialogs ;
IN: merger IN: merger
: main ( -- ) [
MAIN-WINDOW: merger-window {
{ title "Merging" }
{ pref-dim { 300 220 } }
}
vertical <track> vertical <track>
{ "From:" "To:" } f <model> f <model> 2array { "From:" "To:" } f <model> f <model> 2array
[ [
@ -25,7 +29,5 @@ IN: merger
] with-directory ] with-directory
] keep hide-glass ] keep hide-glass
] [ drop ] if ] ] [ drop ] if ]
"merge" swap <border-button> 0.4 track-add { 300 220 } >>pref-dim "Merging" open-window "merge" swap <border-button> 0.4 track-add
] with-ui ; >>gadgets ;
MAIN: main

View File

@ -1,5 +1,5 @@
USING: arrays kernel math opengl opengl.gl opengl.glu USING: arrays kernel math opengl opengl.gl opengl.glu
opengl.demo-support ui ui.gadgets ui.render ; opengl.demo-support ui ui.gadgets ui.render literals accessors ;
IN: nehe.2 IN: nehe.2
TUPLE: nehe2-gadget < gadget ; TUPLE: nehe2-gadget < gadget ;
@ -10,9 +10,6 @@ CONSTANT: height 256
: <nehe2-gadget> ( -- gadget ) : <nehe2-gadget> ( -- gadget )
nehe2-gadget new ; nehe2-gadget new ;
M: nehe2-gadget pref-dim* ( gadget -- dim )
drop width height 2array ;
M: nehe2-gadget draw-gadget* ( gadget -- ) M: nehe2-gadget draw-gadget* ( gadget -- )
drop drop
GL_PROJECTION glMatrixMode GL_PROJECTION glMatrixMode
@ -42,5 +39,5 @@ M: nehe2-gadget draw-gadget* ( gadget -- )
-1.0 -1.0 0.0 glVertex3f -1.0 -1.0 0.0 glVertex3f
] do-state ; ] do-state ;
: run2 ( -- ) MAIN-WINDOW: run2 { { title "NeHe Tutorial 2" } { pref-dim { $ width $ height } } }
<nehe2-gadget> "NeHe Tutorial 2" open-window ; <nehe2-gadget> >>gadgets ;

View File

@ -1,5 +1,5 @@
USING: arrays kernel math opengl opengl.gl opengl.glu USING: arrays kernel math opengl opengl.gl opengl.glu
opengl.demo-support ui ui.gadgets ui.render ; opengl.demo-support ui ui.gadgets ui.render literals accessors ;
IN: nehe.3 IN: nehe.3
TUPLE: nehe3-gadget < gadget ; TUPLE: nehe3-gadget < gadget ;
@ -10,9 +10,6 @@ CONSTANT: height 256
: <nehe3-gadget> ( -- gadget ) : <nehe3-gadget> ( -- gadget )
nehe3-gadget new ; nehe3-gadget new ;
M: nehe3-gadget pref-dim* ( gadget -- dim )
drop width height 2array ;
M: nehe3-gadget draw-gadget* ( gadget -- ) M: nehe3-gadget draw-gadget* ( gadget -- )
drop drop
GL_PROJECTION glMatrixMode GL_PROJECTION glMatrixMode
@ -46,5 +43,5 @@ M: nehe3-gadget draw-gadget* ( gadget -- )
-1.0 -1.0 0.0 glVertex3f -1.0 -1.0 0.0 glVertex3f
] do-state ; ] do-state ;
: run3 ( -- ) MAIN-WINDOW: run3 { { title "NeHe Tutorial 3" } { pref-dim { $ width $ height } } }
<nehe3-gadget> "NeHe Tutorial 3" open-window ; <nehe3-gadget> >>gadgets ;

View File

@ -1,6 +1,6 @@
USING: arrays kernel math opengl opengl.gl opengl.glu USING: arrays kernel math opengl opengl.gl opengl.glu
opengl.demo-support ui ui.gadgets ui.render threads accessors opengl.demo-support ui ui.gadgets ui.render threads accessors
calendar ; calendar literals ;
IN: nehe.4 IN: nehe.4
TUPLE: nehe4-gadget < gadget rtri rquad thread quit? ; TUPLE: nehe4-gadget < gadget rtri rquad thread quit? ;
@ -14,9 +14,6 @@ CONSTANT: height 256
0.0 >>rtri 0.0 >>rtri
0.0 >>rquad ; 0.0 >>rquad ;
M: nehe4-gadget pref-dim* ( gadget -- dim )
drop width height 2array ;
M: nehe4-gadget draw-gadget* ( gadget -- ) M: nehe4-gadget draw-gadget* ( gadget -- )
GL_PROJECTION glMatrixMode GL_PROJECTION glMatrixMode
glLoadIdentity glLoadIdentity
@ -71,5 +68,5 @@ M: nehe4-gadget graft* ( gadget -- )
M: nehe4-gadget ungraft* ( gadget -- ) M: nehe4-gadget ungraft* ( gadget -- )
t >>quit? drop ; t >>quit? drop ;
: run4 ( -- ) MAIN-WINDOW: run4 { { title "NeHe Tutorial 4" } { pref-dim { $ width $ height } } }
<nehe4-gadget> "NeHe Tutorial 4" open-window ; <nehe4-gadget> >>gadgets ;

View File

@ -1,6 +1,6 @@
USING: arrays kernel math opengl opengl.gl opengl.glu USING: arrays kernel math opengl opengl.gl opengl.glu
opengl.demo-support ui ui.gadgets ui.render threads accessors opengl.demo-support ui ui.gadgets ui.render threads accessors
calendar ; calendar literals ;
IN: nehe.5 IN: nehe.5
TUPLE: nehe5-gadget < gadget rtri rquad thread quit? ; TUPLE: nehe5-gadget < gadget rtri rquad thread quit? ;
@ -13,9 +13,6 @@ CONSTANT: height 256
0.0 >>rtri 0.0 >>rtri
0.0 >>rquad ; 0.0 >>rquad ;
M: nehe5-gadget pref-dim* ( gadget -- dim )
drop width height 2array ;
M: nehe5-gadget draw-gadget* ( gadget -- ) M: nehe5-gadget draw-gadget* ( gadget -- )
GL_PROJECTION glMatrixMode GL_PROJECTION glMatrixMode
glLoadIdentity glLoadIdentity
@ -123,6 +120,5 @@ M: nehe5-gadget graft* ( gadget -- )
M: nehe5-gadget ungraft* ( gadget -- ) M: nehe5-gadget ungraft* ( gadget -- )
t >>quit? drop ; t >>quit? drop ;
MAIN-WINDOW: run5 { { title "NeHe Tutorial 5" } { pref-dim { $ width $ height } } }
: run5 ( -- ) <nehe5-gadget> >>gadgets ;
<nehe5-gadget> "NeHe Tutorial 5" open-window ;

View File

@ -1,15 +1,13 @@
USING: ui.gadgets.buttons ui.gadgets.packs ui.gadgets ui USING: ui.gadgets.buttons ui.gadgets.packs ui.gadgets ui
nehe.2 nehe.3 nehe.4 nehe.5 kernel ; nehe.2 nehe.3 nehe.4 nehe.5 kernel accessors ;
IN: nehe IN: nehe
: nehe-window ( -- ) MAIN-WINDOW: nehe-window { { title "Nehe Examples" } }
[
<filled-pile> <filled-pile>
"Nehe 2" [ drop run2 ] <border-button> add-gadget "Nehe 2" [ drop run2 ] <border-button> add-gadget
"Nehe 3" [ drop run3 ] <border-button> add-gadget "Nehe 3" [ drop run3 ] <border-button> add-gadget
"Nehe 4" [ drop run4 ] <border-button> add-gadget "Nehe 4" [ drop run4 ] <border-button> add-gadget
"Nehe 5" [ drop run5 ] <border-button> add-gadget "Nehe 5" [ drop run5 ] <border-button> add-gadget
"Nehe examples" open-window >>gadgets ;
] with-ui ;
MAIN: nehe-window MAIN: nehe-window