From 4beb8192c9fba1e279e56c26618655b0cacd8cd6 Mon Sep 17 00:00:00 2001 From: Joe Groff Date: Fri, 15 Jan 2010 16:55:43 -0800 Subject: [PATCH] pry off some ui app boilerplate with a MAIN-WINDOW: syntax --- basis/ui/gadgets/worlds/worlds.factor | 2 +- basis/ui/ui.factor | 14 +++++++++++- extra/bunny/bunny.factor | 28 ++++++++++-------------- extra/color-picker/color-picker.factor | 8 +++---- extra/color-table/color-table.factor | 6 ++--- extra/demos/demos.factor | 5 ++--- extra/hello-ui/hello-ui.factor | 8 +++---- extra/hello-unicode/hello-unicode.factor | 7 +++--- extra/jamshred/jamshred.factor | 6 ++--- extra/lcd/lcd.factor | 6 ++--- extra/maze/maze.factor | 4 ++-- extra/merger/merger.factor | 12 +++++----- extra/nehe/2/2.factor | 9 +++----- extra/nehe/3/3.factor | 9 +++----- extra/nehe/4/4.factor | 9 +++----- extra/nehe/5/5.factor | 10 +++------ extra/nehe/nehe.factor | 18 +++++++-------- 17 files changed, 71 insertions(+), 90 deletions(-) diff --git a/basis/ui/gadgets/worlds/worlds.factor b/basis/ui/gadgets/worlds/worlds.factor index 8378310253..8a22107f3a 100644 --- a/basis/ui/gadgets/worlds/worlds.factor +++ b/basis/ui/gadgets/worlds/worlds.factor @@ -133,7 +133,7 @@ M: world request-focus-on ( child gadget -- ) [ window-controls>> >>window-controls ] [ initial-background-color >>background-color ] [ grab-input?>> >>grab-input? ] - [ gadgets>> [ 1 track-add ] each ] + [ gadgets>> dup sequence? [ [ 1 track-add ] each ] [ 1 track-add ] if ] [ pref-dim>> >>pref-dim ] } cleave ; diff --git a/basis/ui/ui.factor b/basis/ui/ui.factor index 8260608cd4..1bf7617bc9 100644 --- a/basis/ui/ui.factor +++ b/basis/ui/ui.factor @@ -5,7 +5,7 @@ deques sequences threads words continuations init combinators combinators.short-circuit hashtables concurrency.flags sets accessors calendar fry destructors ui.gadgets ui.gadgets.private 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 >main) ] 3bi ; + +SYNTAX: MAIN-WINDOW: + CREATE world-attributes parse-main-window define-main-window ; diff --git a/extra/bunny/bunny.factor b/extra/bunny/bunny.factor index b7400c4acb..97a90af342 100644 --- a/extra/bunny/bunny.factor +++ b/extra/bunny/bunny.factor @@ -44,24 +44,18 @@ M: bunny-world draw-world* [ geom>> ] [ get-draw ] bi draw-bunny ] if ; -M: bunny-world pref-dim* ( gadget -- dim ) - drop { 640 480 } ; - bunny-world H{ { T{ key-down f f "TAB" } [ next-draw ] } } set-gestures -: bunny-window ( -- ) - [ - f T{ world-attributes - { world-class bunny-world } - { title "Bunny" } - { pixel-format-attributes { - windowed - double-buffered - T{ depth-bits { value 16 } } - } } - } open-window - ] with-ui ; - -MAIN: bunny-window +MAIN-WINDOW: bunny-window + { + { world-class bunny-world } + { title "Bunny" } + { pixel-format-attributes { + windowed + double-buffered + T{ depth-bits { value 16 } } + } } + { pref-dim { 640 480 } } + } ; diff --git a/extra/color-picker/color-picker.factor b/extra/color-picker/color-picker.factor index 56a60d6fc8..a76f07c0fe 100644 --- a/extra/color-picker/color-picker.factor +++ b/extra/color-picker/color-picker.factor @@ -1,6 +1,6 @@ ! Copyright (C) 2006, 2009 Slava Pestov. ! 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 ui.gadgets ui.gadgets.tracks ui.gadgets.labels ui.gadgets.packs ui.gadgets.sliders ui.pens.solid ui.render math.rectangles accessors @@ -45,7 +45,5 @@ M: color-preview model-changed ] bi ] bi* ; -: color-picker-window ( -- ) - [ "Color Picker" open-window ] with-ui ; - -MAIN: color-picker-window +MAIN-WINDOW: color-picker-window { { title "Color Picker" } } + >>gadgets ; diff --git a/extra/color-table/color-table.factor b/extra/color-table/color-table.factor index 0865dabcf7..a154ff82d0 100644 --- a/extra/color-table/color-table.factor +++ b/extra/color-table/color-table.factor @@ -37,7 +37,5 @@ M: color-renderer row-value 10 >>min-rows 10 >>max-rows ; -: color-table-demo ( -- ) - [ "Colors" open-window ] with-ui ; - -MAIN: color-table-demo +MAIN-WINDOW: color-table-demo { { title "Colors" } } + >>gadgets ; diff --git a/extra/demos/demos.factor b/extra/demos/demos.factor index dfd73f1236..9c60d8ad1a 100644 --- a/extra/demos/demos.factor +++ b/extra/demos/demos.factor @@ -11,6 +11,5 @@ IN: demos : ( -- gadget ) 1 >>fill { 2 2 } >>gap demo-vocabs [ add-gadget ] each ; -: demos ( -- ) [ { 2 2 } "Demos" open-window ] with-ui ; - -MAIN: demos \ No newline at end of file +MAIN-WINDOW: demos { { title "Demos" } } + { 2 2 } >>gadgets ; diff --git a/extra/hello-ui/hello-ui.factor b/extra/hello-ui/hello-ui.factor index 3843eec091..9ed9457d5a 100644 --- a/extra/hello-ui/hello-ui.factor +++ b/extra/hello-ui/hello-ui.factor @@ -1,7 +1,5 @@ -USING: ui ui.gadgets.labels ; +USING: accessors ui ui.gadgets.labels ; IN: hello-ui -: hello ( -- ) - [ "Hello world"