Canvas GUI API

From FlightGear wiki
Revision as of 14:20, 14 January 2017 by Jsb (talk | contribs)
Jump to navigation Jump to search


gui.nas implements the classes gui, WindowButton and Window. It loads nasal files from $FGROOT/Nasal/canvas/gui for widgets and styles.

See inside the current (Git) API here.

gui

Container class. Stores widgets and the focused window (if any).

style

canvas.style is initialized in gui.nas as

var style = DefaultStyle.new("AmbianceClassic", "Humanity");

WindowButton

This class manages a button implemented as canvas.image element.

new(parent, name)

parent:

name: string, used to identify the WindowButton and load decoration image files from $FGROOT/gui/style/<StyleName>/decoration/

e.g. for a button named "close", you should have files close_focused_normal.png, close_focused_prelight.png, close_focused_pressed.png, close_unfocused_normal.png, close_unfocused_prelight.png, close_unfocused_pressed.png

protected _onStateChange()

Different images are sourced e.g. for hover, focus etc. according to the active style.

Window

new: func(size, type = nil, id = nil)

size: vector [x,y], initial size of the window

type: ? set property "type"

id: ? used in var ghost = _newWindowGhost(id);

Constructor to create a new instance of canvas.Window

returns: Window object

del: func

Destructor to clean up. Canvas will not be deleted if it has other "placements"

setTitle: func(title)

title: string

Set property "title" (e.g. text on the titlebar)

returns: Window object (me)

createCanvas: func()

Create the canvas to be used for this Window, add placement and mousedown listener.

returns: The new canvas

setCanvas: func(canvas_)

canvas_: canvas object

Replace canvas of this window with canvas_ and remove onRezize method so window cannot be resized anymore.

getCanvas: func(create = 0)

create: bool, create canvas for this window if it does not exist

returns: canvas object of this window

getCanvasDecoration: func()

returns: canvas object of the window decoration (?)

setLayout: func(l)

l (?)

Call me._ghost.setLayout(l);

returns: Window object (me)

setFocus: func

Set this window focused and tell gui class about it.

returns: Window object (me)

clearFocus: func

Clear focus from this window and tell gui class about it.

returns: Window object (me)

setPosition: func (arg...)

arg: either a vector [x, y] or two parameters x,y

Set window position to (x,y) where (0,0) is (left, top)

returns: Window object (me)

setSize: func(arg...)

arg: either a vector [width, height] or two parameters width, height

Set content-size to width, height and call me.onResize if exists.

returns: Window object (me)

move: func

arg: either a vector [x, y] or two parameters x,y

Moves window by x to the right and y down.

returns: Window object (me)

raise: func()

Update z-index and call setFocus()

returns: Window object (me)

onResize: func()

Update canvas size and view to Window.content-size

returns: Window object (me) or nil if window has no canvas.

Private methods The following methods should NOT be called directly, they shall be used ONLY by the methods above.

_onStateChange: func

Used in setFocus(), clearFocus() and _updateDecoration().

_propCallback: func(child, mode)

Used in Window.new (m is the window object under creation):

arg is a vector [child, listener_node, mode, is_child_event]

setlistener(m._node, func m._propCallback(arg[0], arg[2]), 0, 2);

_handlePositionAbsolute: func(child, mode, name, index)

used only in _propCallback

_updatePos: func(index, name)

used only in _handlePositionAbsolute

_handleResize: func(child, name)

used only in _propCallback

_updateDecoration: func()

used only in _propCallback

_resizeDecoration: func()

used by _propCallback and _updateDecoration


Dialog (depricated)

canvas.Dialog is deprectated! Use canvas.Window instead.