world
Factor documentation > Factor handbook > UI framework > Building user interfaces > Top-level windows
Prev:ungraft* ( gadget -- )
Next:MAIN-WINDOW:


Vocabulary
ui.gadgets.worlds

Class description
A gadget which appears at the top of the gadget hieararchy, and in turn may be displayed in a native window. Worlds have the following slots:
active? - if set to f, the world will not be drawn. This slot is set to f if an error is thrown while drawing the world; this prevents multiple debugger windows from being shown.
layers - a sequence of glass panes in front of the primary gadget, used to implement behaviors such as popup menus which are hidden when the mouse is clicked outside the menu. See Glass layers.
title - a string to be displayed in the title bar of the native window containing the world.
status - a model holding a string to be displayed in the world's status bar.
status-owner - the gadget that displayed the most recent status message.
focus - the current owner of the keyboard focus in the world.
focused? - a boolean indicating if the native window containing the world has keyboard focus.
fonts - a hashtable used by the font-renderer.
grab-input? - if set to t, the world will hide the mouse cursor and disable normal mouse input while focused. Use grab-input and ungrab-input to change this setting.
handle - a backend-specific native handle representing the native window containing the world, or f if the world is not grafted.
window-loc - the on-screen location of the native window containing the world. The co-ordinate system here is backend-specific.
window-controls - the set of Window controls with which the world window was created.


Variable value
Current value in global namespace:
f


Definition
USING: ui.gadgets.tracks ;

IN: ui.gadgets.worlds

TUPLE: world < track
active? focused? grab-input? fullscreen? saved-position
layers title status status-owner text-handle handle images
window-loc pixel-format-attributes background-color promise
window-controls window-resources ;


Methods
USING: accessors combinators kernel sequences ui.gadgets.tracks
ui.gadgets.worlds ;

M: world apply-world-attributes
{
[ title>> >>title ]
[ status>> >>status ]
[ pixel-format-attributes>> >>pixel-format-attributes ]
[ window-controls>> >>window-controls ]
[ initial-background-color >>background-color ]
[ grab-input?>> >>grab-input? ]
[
gadgets>> dup sequence?
[ [ 1 track-add ] each ] [ 1 track-add ] if
]
[ pref-dim>> >>pref-dim ]
} cleave ;


USING: kernel ui.gadgets.worlds ;

M: world begin-world drop ;


USING: kernel ui.gadgets.worlds ui.pixel-formats ;

M: world check-world-pixel-format 2drop ;


USING: accessors kernel ui.gadgets ui.gadgets.worlds ;

M: world children-on nip children>> ;


USING: accessors cache combinators kernel opengl.textures
ui.gadgets.worlds ui.render ;

M: world draw-world*
check-extensions {
[ init-gl ]
[ draw-gadget ]
[ text-handle>> [ purge-cache ] when* ]
[ images>> [ purge-cache ] when* ]
} cleave ;


USING: kernel ui.gadgets.worlds ;

M: world end-world drop ;


USING: accessors sequences ui.gadgets ui.gadgets.worlds ;

M: world focusable-child* children>> [ t ] [ first ] if-empty ;


USING: continuations kernel ui.backend ui.gadgets
ui.gadgets.worlds ui.private ;

M: world graft*
[ (open-window) ] [
[ set-up-window ]
[ [ clean-up-broken-window ] [ ui-error ] bi* ] recover
] bi ;


USING: combinators generic kernel ui.gadgets.worlds ui.gestures
;

M: world handle-gesture
2dup M\ world handle-gesture (call-next-method) [
{
{
[ over specific-button-up? ]
[ drop generalize-gesture f ]
}
{
[ over specific-button-down? ]
[ drop generalize-gesture f ]
}
{
[ over specific-drag? ]
[ drop generalize-gesture f ]
}
[ 2drop t ]
} cond
] [ 2drop f ] if ;


USING: accessors generic kernel sequences ui.gadgets
ui.gadgets.worlds ;

M: world layout*
[ M\ world layout* (call-next-method) ]
[ dup layers>> [ as-big-as-possible ] with each ] bi ;


USING: accessors generic kernel sequences ui.gadgets
ui.gadgets.worlds ;

M: world remove-gadget
2dup layers>> member-eq?
[ layers>> remove-eq! drop ]
[ M\ world remove-gadget (call-next-method) ] if ;


USING: accessors kernel ui.gadgets ui.gadgets.worlds ;

M: world request-focus-on
2dup eq? [ 2drop ] [ dup focused?>> (request-focus) ] if ;


USING: kernel ui.gadgets.worlds ;

M: world resize-world drop ;


USING: accessors combinators concurrency.promises destructors
kernel ui.backend ui.gadgets ui.gadgets.worlds ui.gestures
ui.private ;

M: world ungraft*
{
[ set-gl-context ]
[ text-handle>> [ dispose ] when* ]
[ images>> [ dispose ] when* ]
[ hand-clicked close-global ]
[ hand-gadget close-global ]
[ end-world ]
[ dispose-window-resources ]
[ unfocus-world ]
[ [ (close-window) f ] change-handle drop ]
[ promise>> t swap fulfill ]
} cleave ;


USING: accessors ui.gadgets.worlds ui.pixel-formats ;

M: world world-pixel-format-attributes
pixel-format-attributes>> ;