Canvas snippets

From FlightGear wiki
Revision as of 20:15, 14 September 2014 by Philosopher (talk | contribs) (→‎Canvas Input Dialog: great idea!)
Jump to navigation Jump to search
This article is a stub. You can help the wiki by expanding it.
WIP.png Work in progress
This article or section will be worked on in the upcoming hours or days.
See history for the latest developments.


Creating a Canvas GUI Window

Note  This example uses so called method chaining, if you're not familiar with the concept, please see: Method Chaining.
This is what the Nasal/Canvas snippet will look like once you pasted it into the Nasal Console and click "Execute".
# create a new window, dimensions are 320 x 160, using the dialog decoration (i.e. titlebar)
var window = canvas.Window.new([320,160],"dialog");

# adding a canvas to the new window and setting up background colors/transparency
var myCanvas = window.createCanvas().setColorBackground(1,1,1,1);

# creating the top-level/root group which will contain all other elements/group
var root = myCanvas.createGroup();

Canvas Input Dialog

# create a new InputDialog with a title, label, and a callback
canvas.InputDialog.getText("Input Dialog Title", "Please enter some text", func(btn,value) {
    if (value) gui.popupTip("You entered: "~value);
});